private void searchMovieBG_DoWork(object sender, DoWorkEventArgs e) { string movieFileFullName = (string)e.Argument; string movieFileName = System.IO.Path.GetFileName(movieFileFullName); byte[] movieHashByte = Hasher.ComputeMovieHash(movieFileFullName); string movieHashString = Hasher.ToHexadecimal(movieHashByte); FileInfo movieFileInfo = new FileInfo(movieFileFullName); string movieFileSize = movieFileInfo.Length.ToString(); var worker = sender as BackgroundWorker; worker.ReportProgress(20, String.Format("File: {0}\nSearching subtitle...", movieFileName)); OSAPICalls osAPI = new OSAPICalls(movieHashString, movieFileSize, "TemporaryUserAgent"); MatchResult searchResult = osAPI.searchMovie(); if (!searchResult.IsEmpty) { worker.ReportProgress(40, String.Format("Found subtitle: {0}\nDownloading...", searchResult.SubFileName)); WebClient webClient = new WebClient(); string zipSubtitle = movieFileFullName.Remove(movieFileFullName.Length - movieFileInfo.Extension.Length) + ".gz"; webClient.DownloadFile(searchResult.SubDownloadLink, zipSubtitle); worker.ReportProgress(80, String.Format("Downloaded {0}\nDecompressing...", zipSubtitle)); FileInfo gzFileInfo = new FileInfo(zipSubtitle); Decompress(gzFileInfo); File.Delete(zipSubtitle); } else { worker.ReportProgress(90, String.Format("No subtitle found for {0}.", movieFileName)); } worker.ReportProgress(100); }
static void Main(string[] args) { string assemblyFullName = Application.ExecutablePath; string currentPath; if (args.Length == 0) { currentPath = Path.GetDirectoryName(assemblyFullName); } else { currentPath = args[0]; } var movieFiles = Directory.GetFiles(currentPath, "*.*", SearchOption.AllDirectories) .Where(s => s.EndsWith(".mp4") || s.EndsWith(".mkv")); foreach (var movieFileFullName in movieFiles) { string movieFileName = Path.GetFileName(movieFileFullName); byte[] movieHashByte = Hasher.ComputeMovieHash(movieFileFullName); string movieHashString = Hasher.ToHexadecimal(movieHashByte); FileInfo movieFileInfo = new FileInfo(movieFileFullName); string movieFileSize = movieFileInfo.Length.ToString(); Console.WriteLine("File: {0}", movieFileName); Console.WriteLine("Searching subtitle..."); OSAPICalls osAPI = new OSAPICalls(movieHashString, movieFileSize, "TemporaryUserAgent"); MatchResult searchResult = osAPI.searchMovie(); if (!searchResult.IsEmpty) { Console.WriteLine("Found subtitle: {0}", searchResult.SubFileName); Console.WriteLine("Downloading..."); WebClient webClient = new WebClient(); //string zipSubtitle = Path.GetFileNameWithoutExtension(movieFileFullName) + ".gz"; string zipSubtitle = movieFileFullName.Remove(movieFileFullName.Length - movieFileInfo.Extension.Length) + ".gz"; webClient.DownloadFile(searchResult.SubDownloadLink, zipSubtitle); Console.WriteLine("Downloaded {0}", zipSubtitle); Console.WriteLine("Decompressing..."); FileInfo gzFileInfo = new FileInfo(zipSubtitle); Decompress(gzFileInfo); File.Delete(zipSubtitle); } else { Console.WriteLine("No subtitle found for {0}.", movieFileName); } Console.WriteLine("-------"); } }