public string GetFileName(TeaseMedia media) { if (media.Id.StartsWith("http://")) { return(media.Id); } if (FullMediaDirectoryPath.StartsWith("http://")) { return(FullMediaDirectoryPath + media.Id); } var matchingFiles = new DirectoryInfo(FullMediaDirectoryPath).GetFiles(media.Id); if (matchingFiles.Count() > 0) { return(matchingFiles[random.Next(matchingFiles.Length)].FullName); } return(null); }
void DownloadMedia(DownloadTask task, TeasePage page, TeaseMedia teaseMedia) { string mediaName = teaseMedia.Id; if (teaseMedia.Id.Contains("*")) { mediaName = teaseMedia.Id.Replace("*", String.Format("[{0}]", Guid.NewGuid())); } if (teaseMedia.Id.StartsWith("http://") || teaseMedia.Id.StartsWith("https://")) { mediaName = new Uri(teaseMedia.Id).Segments.Last(); } string fileName = Path.Combine(task.MediaDirectory.FullName, mediaName); if (!File.Exists(fileName)) { string url = String.Format("{0}/media/get.php?folder={1}/{2}&name={3}", MilovanaRootUrl, task.AuthorId, task.TeaseId, teaseMedia.Id); if (teaseMedia.Id.StartsWith("http://") || teaseMedia.Id.StartsWith("https://")) { url = teaseMedia.Id; } try { using (var client = new WebClient()) { backgroundWorker.ReportProgress(0, "Downloading " + url); // Be nice to the Milovana webserver and wait a bit before the next request... Thread.Sleep(800); client.DownloadFile(url, fileName); backgroundWorker.ReportProgress(0, "Ok"); } } catch (Exception err) { backgroundWorker.ReportProgress(1, String.Format("Error: [{0}] {1}", err.GetType(), err.Message)); page.Errors = String.Format("Error while downloading file '{0}'. {1}.", url, page.Errors); } } if (teaseMedia.Id.StartsWith("http://") || teaseMedia.Id.StartsWith("https://")) { teaseMedia.Id = mediaName; } }
public string GetFileName(TeaseMedia media) { if (media.Id.StartsWith("http://") || media.Id.StartsWith("https://")) { return media.Id; } if (FullMediaDirectoryPath.StartsWith("http://") || FullMediaDirectoryPath.StartsWith("https://")) { return FullMediaDirectoryPath + media.Id; } var matchingFiles = new DirectoryInfo(FullMediaDirectoryPath).GetFiles(media.Id); if (matchingFiles.Any()) { return matchingFiles[random.Next(matchingFiles.Length)].FullName; } return null; }
private TeaseMedia GetAudio(CommonTree soundNode) { if (soundNode == null) { return null; } var result = new TeaseMedia(); var idNode = soundNode.GetFirstChildWithType(FlashTeaseScriptLexer.ID) as CommonTree; if (idNode != null) { result.Id = idNode.GetChild(0).Text.Trim('\'', '"'); } var loopsNode = soundNode.GetFirstChildWithType(FlashTeaseScriptLexer.LOOPS) as CommonTree; if (loopsNode != null && loopsNode.ChildCount > 0) { result.Repeat = loopsNode.GetChild(0).Text; } return result; }
private string WriteAsxFile(string videoFile, TeaseMedia media) { TimeSpan? duration = null; if (String.IsNullOrEmpty(media.StartAt)) { media.StartAt = "00:00:00"; } if (!String.IsNullOrEmpty(media.StopAt)) { duration = ParseTime(media.StopAt).Subtract(ParseTime(media.StartAt)); } string result = videoFile + ".asx"; var contents = new StringBuilder(); contents.AppendLine("<Asx Version=\"3.0\">"); contents.AppendFormat("<Repeat count=\"{0}\">", String.IsNullOrEmpty(media.Repeat) ? "1" : media.Repeat).AppendLine(); contents.AppendLine("<Entry>"); contents.AppendFormat("<StartTime value=\"{0}\" />", media.StartAt).AppendLine(); if (duration.HasValue) { contents.AppendFormat("<Duration value=\"{0}:{1}:{2}\" />", duration.Value.Hours, duration.Value.Minutes, duration.Value.Seconds).AppendLine(); } contents.AppendFormat("<Ref href=\"{0}\" />", videoFile).AppendLine(); contents.AppendLine("</Entry>"); contents.AppendLine("</Repeat>"); contents.AppendLine("</Asx>"); File.WriteAllText(result, contents.ToString()); return result; }