Ejemplo n.º 1
0
        private void RefreshOnlineSubs()
        {
            IsSubtitleSearchInProgress = true;
            BackgroundWorker b = new BackgroundWorker();

            b.DoWork += (sender, args) =>
            {
                DateTime start = DateTime.Now;

                IMDb imdb;
                List <SubtitleMatch> otherChoices;
                try
                {
                    SubtitleUtil.FindSubtitleForFilename(SubtitleDefaultSearchText, SubtitleDefaultSearchText, Main.SubtitleLanguages.Select(l => l.Id).ToArray(), Main.SubtitleServices.Select(l => l.Id).ToArray(), out imdb, out otherChoices, MessageCallback, true, false);
                    args.Result = otherChoices;
                }
                catch (WebException)
                {
                    Main.ShowOsdMessage("Internet connection unavailable.");
                    args.Result = null;
                }
                finally
                {
                    if (DateTime.Now - start > TimeSpan.FromSeconds(15))
                    {
                        args.Cancel = true;
                    }
                }
            };
            b.RunWorkerCompleted += (sender, args) =>
            {
                try
                {
                    if (args.Cancelled || args.Error != null)
                    {
                        return;
                    }

                    SetupDownloadedSubtitleAndIMDbInfo(Source, SelectedSubtitle != null ? SelectedSubtitle.Path : "", IMDb, args.Result);
                }
                catch (Exception)
                {
                    Main.ShowOsdMessage("Querying subtitle providers failed. Please try again.");
                }
                finally
                {
                    IsSubtitleSearchInProgress = false;
                }
            };
            b.RunWorkerAsync();
        }
Ejemplo n.º 2
0
        public void LoadSelectedOnlineSubtitle()
        {
            ShowOnlineSubtitles = false;
            BackgroundWorker b = new BackgroundWorker();

            b.DoWork += (sender, args) =>
            {
                DateTime start = DateTime.Now;
                Monitor.Enter(_subtitleSearchLocker);

                try
                {
                    args.Result = SubtitleUtil.DownloadSubtitle(SelectedOnlineSubtitle, Source.LocalPath);
                }
                catch (WebException)
                {
                    Main.ShowOsdMessage("Failed to download subtitle: Internet connection unavailable");
                }
                catch (Exception)
                {
                    Main.ShowOsdMessage("Failed to download subtitle from '" + SelectedOnlineSubtitle.Service + "'");
                }
                finally
                {
                    Monitor.Exit(_subtitleSearchLocker);
                    if (DateTime.Now - start > TimeSpan.FromSeconds(15))
                    {
                        args.Cancel = true;
                    }
                }
            };
            b.RunWorkerCompleted += (sender, args) =>
            {
                if (!args.Cancelled && args.Error == null && args.Result is string && Source != null)
                {
                    FillSubs(Source);
                    string resultSub = (string)args.Result;
                    if (SubtitleStreams.Any(s => s.Path.ToLowerInvariant() == resultSub.ToLowerInvariant()) == false)
                    {
                        SubtitleStreams.Add(new SubtitleItem(SubtitleItem.SubtitleType.File, SubtitleItem.SubtitleSubType.Srt, resultSub, "Subtitle"));
                    }
                    var loadSub = (DownloadedSubtitle = SubtitleStreams.FirstOrDefault(s => s.Path.ToLowerInvariant() == (resultSub).ToLowerInvariant()));
                    ServiceLocator.GetService <IMainView>().DelayedInvoke(() => { SelectedSubtitle = loadSub; }, 200);
                }
            };
            b.RunWorkerAsync();
        }
Ejemplo n.º 3
0
        private void QueryIMDBForUri(Uri uri)
        {
            BackgroundWorker b = new BackgroundWorker();

            b.DoWork += (sender, args) =>
            {
                DateTime start = DateTime.Now;
                string   strTitle, strYear, strTitleAndYear; int season, episode;
                SubtitleDownloader.Core.Subtitle bestGuessSubtitle = null;
                try
                {
                    args.Result = SubtitleUtil.GetIMDbFromFilename(uri.LocalPath, Path.GetDirectoryName(uri.LocalPath), out strTitle, out strTitleAndYear, out strYear, out season, out episode, MessageCallback, out bestGuessSubtitle);
                }
                catch
                {
                    args.Cancel = true;
                }
                if (DateTime.Now - start > TimeSpan.FromSeconds(15))
                {
                    args.Cancel = true;
                }
            };
            b.RunWorkerCompleted += (sender, args) =>
            {
                if (args.Cancelled || args.Error != null)
                {
                    IMDb = null;
                    return;
                }
                object r = null;
                try
                {
                    r = args.Result;
                }
                catch { }
                if (r != null)
                {
                    IMDb = (IMDb)r;
                }
                else
                {
                    IMDb = null;
                }
            };
            b.RunWorkerAsync();
        }
Ejemplo n.º 4
0
        private void DownloadSubtitleForUriAndQueryIMDB(Uri uri)
        {
            // try online
            BackgroundWorker b = new BackgroundWorker();

            _subtitleIsDownloading     = true;
            IsSubtitleSearchInProgress = true;
            b.DoWork += (sender, args) =>
            {
                DateTime start = DateTime.Now;

                Monitor.Enter(_subtitleSearchLocker);

                IMDb imdb;
                List <SubtitleMatch> otherChoices;
                try
                {
                    string s = SubtitleUtil.DownloadSubtitle(uri.LocalPath, Main.SubtitleLanguages.Select(l => l.Id).ToArray(),
                                                             Main.SubtitleServices.Select(l => l.Id).ToArray(), out imdb, out otherChoices, MessageCallback);
                    if (!string.IsNullOrEmpty(s) && imdb.status)
                    {
                        args.Result = new object[] { s, imdb, otherChoices };
                    }
                    else
                    {
                        args.Result = imdb;
                    }
                }
                catch (WebException)
                {
                    Main.ShowOsdMessage("Internet connection unavailable.");
                    args.Result = null;
                }
                finally
                {
                    Monitor.Exit(_subtitleSearchLocker);
                    if (DateTime.Now - start > TimeSpan.FromSeconds(15))
                    {
                        args.Cancel = true;
                    }
                }
            };
            b.RunWorkerCompleted += (sender, args) =>
            {
                try
                {
                    if (args.Cancelled || args.Error != null || HasVideo == false)
                    {
                        return;
                    }
                    var result = (object)null;
                    try
                    {
                        result = args.Result;
                    }
                    catch { /* bad request etc */ }

                    if (result != null)
                    {
                        if (result is IMDb)
                        {
                            // we got no subtitle but have IMDb
                            IMDb = result as IMDb;
                        }
                        else
                        {
                            // both subtitle and IMDB
                            string resultSub = (string)((object[])result)[0];
                            IMDb   imdb      = (IMDb)((object[])result)[1];
                            var    param2    = ((object[])result)[2];
                            SetupDownloadedSubtitleAndIMDbInfo(uri, resultSub, imdb, param2);
                        }
                    }
                    else
                    {
                        // we got nothing
                        IMDb = null;
                    }
                }
                finally
                {
                    IsSubtitleSearchInProgress = false;
                    _subtitleIsDownloading     = false;
                }
            };
            b.RunWorkerAsync();
        }
Ejemplo n.º 5
0
 private void chkForceStream_CheckedChanged(object sender, EventArgs e)
 {
     subName.Text = SubtitleUtil.ApplyForcedStringToTrackName(chkForceStream.Checked, subName.Text);
 }