public void DownSub(string paths) { //13Oct,2013 - Added check for existing subtitles(Smart download option) by Ajay Singh of techovity.com([email protected]) if (isSmartDownload && SubtitleExists(paths)) { AppendSuccess("Skipping Download for: " + paths.Substring((paths.LastIndexOf("\\") + 1), (paths.Length - (paths.LastIndexOf("\\") + 1))) + "as video file already have Subtitle (*.srt) file available. Uncheck 'Smart Download' to stop this."); return; } WebClient Client = new WebClient(); if (IsConnectedToInternet()) { Opensubhub subhub = (Opensubhub)XmlRpcProxyGen.Create(typeof(Opensubhub)); byte[] hashsize = GetHash.Main.ComputeHash(paths); string hashcode = GetHash.Main.ToHexadecimal(hashsize); FileInfo info = new FileInfo(paths); double bytesize = info.Length; LoginRequest inrequest; LogoutRequest outrequest; FileDet[] detail = new FileDet[1]; SubReturn returndetails; try { inrequest = subhub.LogIn("", "", "en", "OS Test User Agent"); detail[0].sublanguageid = Properties.Settings.Default.langPref; detail[0].moviehash = hashcode; detail[0].moviebytesize = bytesize; AppendSuccess("Searching subtitle for: " + paths.Substring((paths.LastIndexOf("\\") + 1), (paths.Length - (paths.LastIndexOf("\\") + 1)))); returndetails = subhub.SearchSubtitles(inrequest.token, detail); string result = ""; if (returndetails.data[0].SubBad != "1") { string rating1 = returndetails.data[0].SubRating; double ch = Convert.ToDouble(rating1); result = returndetails.data[0].SubDownloadLink; for (int j = 0; j < returndetails.data.Length; j++) { string rating2 = returndetails.data[j].SubRating; double ch2 = Convert.ToDouble(rating2); if (ch2 > ch) { result = returndetails.data[j].SubDownloadLink; ch = ch2; } } } if (result != null) { AppendSuccess("Subtitle Found"); // MessageBox.Show(result[i]); int ch1 = paths.LastIndexOf("\\"); int ch2 = paths.LastIndexOf("."); string pth = paths.Substring(0, (ch1)); string ext = paths.Substring(ch1, (ch2 - ch1)) + ".gz"; string pth1 = pth + ext; string ext1 = paths.Substring(ch1, (ch2 - ch1)) + ".srt"; string pth2 = pth + ext1; Client.DownloadFile(result, pth1); TestDecompress(pth1, pth2); File.Delete(pth1); AppendSuccess("Subtitle Downloaded"); } outrequest = subhub.LogOut(inrequest.token); // MessageBox.Show("All subs downloaded"); } catch (Exception ex) { AppendSuccess("Subtitle not found for " + paths.Substring((paths.LastIndexOf("\\") + 1), (paths.Length - (paths.LastIndexOf("\\") + 1)))); // HandleException(ex); } } else { MessageBox.Show("Please check your net connection"); } }
public void DownSub(string[] paths) { WebClient Client = new WebClient(); int filelnth = paths.Length; if (IsConnectedToInternet()) { Opensubhub subhub = (Opensubhub)XmlRpcProxyGen.Create(typeof(Opensubhub)); string[] hashcode = new string[filelnth]; double[] bytesize = new double[filelnth]; for (int i = 0; i < filelnth; i++) { byte[] hashsize = GetHash.Main.ComputeHash(paths[i]); hashcode[i] = GetHash.Main.ToHexadecimal(hashsize); FileInfo info = new FileInfo(paths[i]); bytesize[i] = info.Length; } LoginRequest inrequest; LogoutRequest outrequest; FileDet[] detail = new FileDet[1]; SubReturn returndetails; try { inrequest = subhub.LogIn("", "", "en", "OS Test User Agent"); for (int k = 0; k < filelnth; k++) { AppendSuccess("Searching subtitle for: " + paths[k].Substring((paths[k].LastIndexOf("\\") + 1), (paths[k].Length - (paths[k].LastIndexOf("\\") + 1)))); detail[0].sublanguageid = "eng"; detail[0].moviehash = hashcode[k]; detail[0].moviebytesize = bytesize[k]; try { returndetails = subhub.SearchSubtitles(inrequest.token, detail); string result = ""; if (returndetails.data[0].SubBad != "1") { AppendSuccess("Sutitle Found"); string rating1 = returndetails.data[0].SubRating; double ch = Convert.ToDouble(rating1); result = returndetails.data[0].SubDownloadLink; for (int j = 1; j < returndetails.data.Length; j++) { string rating2 = returndetails.data[j].SubRating; double ch2 = Convert.ToDouble(rating2); if (ch2 > ch) { result = returndetails.data[j].SubDownloadLink; ch = ch2; } } } if (result != null) { int ch1 = paths[k].LastIndexOf("\\"); int ch2 = paths[k].LastIndexOf("."); string pth = paths[k].Substring(0, (ch1)); string ext = paths[k].Substring(ch1, (ch2 - ch1)) + ".gz"; string pth1 = pth + ext; string ext1 = paths[k].Substring(ch1, (ch2 - ch1)) + ".srt"; string pth2 = pth + ext1; Client.DownloadFile(result, pth1); TestDecompress(pth1, pth2); File.Delete(pth1); AppendSuccess("Subtitle saved"); } } catch (Exception) { AppendSuccess("Subtitle not found for " + paths[k].Substring((paths[k].LastIndexOf("\\") + 1), (paths[k].Length - (paths[k].LastIndexOf("\\") + 1)))); } } /* sb = subhub.DownloadSubtitles(inrequest.token, result); * for (int i = 0; i < sb.data.Length; i++) * { * string s=base64Decode(sb.data[i].data); * System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); * Byte[] bytes = encoding.GetBytes(s); * // string str = UnZipStr(s); * int ch1=paths[i].LastIndexOf("\\"); * int ch2=paths[i].LastIndexOf("."); * string pth=paths[i].Substring(0,(ch1)); * string ext = paths[i].Substring(ch1,(ch2-ch1 ))+".srt"; * pth=pth+ext; * using (System.IO.FileStream fs = System.IO.File.Create(pth)) * { * } * StreamWriter sw = new StreamWriter(pth); * sw.Write(sb.data[i].data); * }*/ outrequest = subhub.LogOut(inrequest.token); MessageBox.Show("All Subtitles downloaded"); } catch (Exception ex) { // HandleException(ex); } } else { MessageBox.Show("Please check your internect connection"); } }