コード例 #1
0
ファイル: EasySubtitles.cs プロジェクト: jpsfs/tv-organizer
        public void Download(Episode ep)
        {
            if (!ep.DownloadSub || ep.AvailableLanguages == null || ep.AvailableLanguages.Length == 0) return;

            string fileName = Path.GetFileNameWithoutExtension(ep.FilePath);
            string hash = "";

            try
            {
                hash = tv_organizer.SubtitlesAPI.HashGenerator.Get(ep.FilePath);
            }
            catch
            {
                //Error generating the hash file... just continue
                ep.ErrorHash = true;
                return;
            }

            //Handle HTTP Request
            string url = String.Format((EasySubtitles.Url + "?action=download&language={0}&hash={1}&name={2}"), EasySubtitles.Language, hash, fileName);

            WebClient webClient = new WebClient();
            webClient.Headers.Add(HttpRequestHeader.UserAgent, _userAgent);
            webClient.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(webClient_DownloadFileCompleted);
            webClient.DownloadFileAsync(new Uri(url), Path.GetDirectoryName(ep.FilePath) + Path.DirectorySeparatorChar + fileName + ".srt", ep);
        }
コード例 #2
0
ファイル: EasySubtitles.cs プロジェクト: jpsfs/tv-organizer
        public void Search(Episode ep)
        {
            string fileName = Path.GetFileNameWithoutExtension(ep.FilePath);

            string hash = "";
            try
            {
                hash = tv_organizer.SubtitlesAPI.HashGenerator.Get(ep.FilePath);
            }
            catch
            {
                //Error generating the hash file... just continue
                ep.ErrorHash = true;
                return;
            }
            //Handle HTTP Request
            string url = String.Format((EasySubtitles.Url + "?action=search&hash={0}"), hash);

            WebClient webClient = new WebClient();
            webClient.Headers.Add(HttpRequestHeader.UserAgent, _userAgent);

            webClient.OpenReadCompleted += webClient_OpenReadCompleted;
            webClient.OpenReadAsync(new Uri(url), ep);
        }