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();
        }
        private void findSubtitles(string file)
        {
            try
            {
                OSDotNetSession session  = OSDotNetSession.LogIn("", "", "fr", "iPhoneVideoHelper");
                FileInfo        fileInfo = new FileInfo(file);
                List <string>   codes    = new List <string>();
                if (rdbBalkan.Checked)
                {
                    codes.Add("scc");
                    codes.Add("hrv");
                    codes.Add("bos");
                }
                else
                {
                    codes.Add("eng");
                }
                foreach (string code in codes)
                {
                    List <SearchSubtitleResult> List = session.SearchByFile(fileInfo,
                                                                            OSLanguageHelper.GetOSLanguageById(code));

                    foreach (SearchSubtitleResult res in List)
                    {
                        foundSubtitles.Add(res);
                    }
                }

                string imdbId = foundSubtitles[0].IDMovieImdb;
                foundSubtitles.Clear();

                if (rdbBalkan.Checked)
                {
                    codes.Add("scc");
                    codes.Add("hrv");
                    codes.Add("bos");
                }
                else
                {
                    codes.Add("eng");
                }
                foreach (string code in codes)
                {
                    List <SearchSubtitleResult> List = session.SearchByImdbId(imdbId,
                                                                              OSLanguageHelper.GetOSLanguageById(code));

                    foreach (SearchSubtitleResult res in List)
                    {
                        foundSubtitles.Add(res);
                    }
                }
                session.LogOut();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
示例#3
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();
                    }
                }
            }
        }