public bool Start() { AnimeDownload dl = new AnimeDownload(); BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += delegate { dl = GetDownload(Episode); }; bw.RunWorkerCompleted += delegate { if (dl.downloadLink == null) { Trace.TraceError("Failed to fetch download link for {0}.", Title); Status = DownloadStatus.Failed; return; } DownloadLink = dl.DownloadLink; Resolution = dl.Resolution; // This is a really shitty solution, but so far it has worked as all files I have encountered so far has been mp4. // There is probably a way better solution to this, but I have time issues as it is :( // I tried to get the file extension by usual means, but sometimes the URL contained a '.' and no file extension, // which resulted in 25+ character long, invalid, file extensions. // TODO: Find the real extension through hex signatures. string extension = ".mp4"; FileName = DownloadManager.GenerateFilePath(this) + extension; downloadingClient = new WebClient(); downloadingClient.Headers.Add("Referer", "http://www.animebam.net/"); downloadingClient.DownloadProgressChanged += DownloadProgressChanged; downloadingClient.DownloadFileCompleted += DownloadFileCompleted; downloadingClient.DownloadFileAsync(new Uri(dl.DownloadLink), Path.Combine(DownloadManager.DownloadFolder, FileName)); Trace.TraceInformation("Started downloading {0} ({1})", FileName, Title); }; bw.RunWorkerAsync(); Status = DownloadStatus.Downloading; return(true); }
private AnimeDownload GetDownload(Episode ep) { List <AnimeDownload> dlList = API.GetDownloads(ep.EpisodeUrl, ep.EpisodeName); AnimeDownload maxDl = new AnimeDownload(); int maxResolution = 0; foreach (AnimeDownload dl in dlList) { int res = dl.Resolution; if (res > maxResolution) { maxResolution = res; maxDl = dl; } } return(maxDl); }