private void btnDownload_Click(object sender, EventArgs e)
        {
            int index = lvwTitles.SelectedIndices[0];

            string location = Path.GetDirectoryName(txtMovieLocation.Text);

            SearchSubtitleResult item = foundSubtitles[index];
            string subtitle           = location + "\\" + item.SubFileName;

            OSDotNetSession session = OSDotNetSession.LogIn("", "", "fr", "iPhoneVideoHelper");

            using (MemoryStream st = session.DownloadSubtitle(item))
            {
                using (FileStream fs = new FileStream(subtitle, FileMode.OpenOrCreate))
                {
                    st.WriteTo(fs);

                    st.Flush();
                    st.Close();
                    session.LogOut();
                }
            }

            findExistingSubtitles();
        }
Пример #2
0
        private void DownloadSubtitles(string videoFilePath, string TitleText)
        {
            if (SubtitlesSession == null)
            {
                //subtitlesSession = OSDotNetSession.LogIn("shayfichman", "opensubtitles", "en", "moviematch v1.2");
                SubtitlesSession = OSDotNetSession.LogIn(Settings.OpensubtitlesUsername, Settings.OpensubtitlesPassword, "en", "moviematch v1.2");
                if (SubtitlesSession == null)
                {
                    return;
                }
            }

            List <SearchSubtitleResult> subtitleList = SubtitlesSession.SearchByFile(new FileInfo(videoFilePath), SubtitlesLang);

            if (subtitleList.Count == 0)
            {
                if (!IsEpisode)
                {
                    subtitleList = SubtitlesSession.SearchOnlyByImdbId(ImdbId, SubtitlesLang);
                    if (subtitleList.Count == 0)
                    {
                        subtitleList = SubtitlesSession.SearchOnlyByTag(Path.GetFileName(videoFilePath), SubtitlesLang);
                    }
                    if (subtitleList.Count == 0)
                    {
                        subtitleList = SubtitlesSession.SearchOnlyByQuery(TitleText, SubtitlesLang);
                    }
                }
                else
                {
                    subtitleList = SubtitlesSession.SearchOnlyByTag(Path.GetFileName(videoFilePath), SubtitlesLang);
                    if (subtitleList.Count == 0)
                    {
                        subtitleList = SubtitlesSession.SearchByEpisode(TitleText, SeasonNumber, EpisodeNumber, SubtitlesLang);
                    }
                }
            }

            if (subtitleList.Count > 0)
            {
                string subtitlesPath = Path.Combine(Path.GetDirectoryName(videoFilePath), Path.GetFileNameWithoutExtension(videoFilePath) + "." + subtitleList[0].SubFormat);
                if (!File.Exists(subtitlesPath))
                {
                    MemoryStream st = SubtitlesSession.DownloadSubtitle(subtitleList[0]);
                    using (FileStream fs = new FileStream(subtitlesPath, FileMode.OpenOrCreate))
                    {
                        st.WriteTo(fs);
                        st.Flush();
                        st.Close();
                    }
                }
            }
        }