Beispiel #1
0
        private void GetThread([NotNull] object codeIn)
        {
            System.Diagnostics.Debug.Assert(workerSemaphore != null);

            SeriesSpecifier series;

            switch (codeIn)
            {
            case SeriesSpecifier ss:
                series = ss;
                break;

            default:
                throw new ArgumentException("GetThread started with invalid parameter");
            }

            try
            {
                workerSemaphore.WaitOne(); // don't start until we're allowed to

                bool bannersToo = TVSettings.Instance.NeedToDownloadBannerFile();

                Threadslogger.Trace("  Downloading " + series.Name);
                if (TVDoc.GetMediaCache(series.Provider).EnsureUpdated(series, bannersToo, true))
                {
                    return;
                }
            }
            catch (MediaNotFoundException snfe)
            {
                Problems.Add(snfe);
                //We don't want this to stop all other threads
                return;
            }
            catch (SourceConsistencyException sce)
            {
                Logger.Error(sce.Message);
            }
            catch (Exception e)
            {
                Logger.Fatal(e, $"Unhandled Exception in GetThread for {series}");
            }
            finally
            {
                Threadslogger.Trace("  Finished " + series);
                workerSemaphore.Release(1);
            }

            //If we get to here the download failed
            downloadOk = false;
            if (downloadStopOnError)
            {
                DownloadDone = true;
            }
        }
Beispiel #2
0
        private bool OkToClose()
        {
            if (!TVDoc.GetMediaCache(GetProviderTypeInUse()).HasMovie(codeFinderForm.SelectedCode()))
            {
                DialogResult dr = MessageBox.Show($"{GetProviderType().PrettyPrint()} code unknown, close anyway?", "TVRename Add/Edit Movie",
                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (dr == DialogResult.No)
                {
                    return(false);
                }
            }
            if (chkCustomLanguage.Checked && string.IsNullOrWhiteSpace(cbLanguage.SelectedItem?.ToString()))
            {
                MessageBox.Show("Please enter language for the show or accept the default preferred language", "TVRename Add/Edit Movie",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);

                return(false);
            }
            if (chkAutoFolders.Checked && string.IsNullOrWhiteSpace(cbDirectory.SelectedItem?.ToString()))
            {
                MessageBox.Show("Please enter base folder for this show or turn off automatic folders", "TVRename Add/Edit Movie",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);

                Folders.SelectedTab = tabPage5;
                cbDirectory.Focus();

                return(false);
            }
            if (chkAutoFolders.Checked && !TVSettings.OKPath(cbDirectory.SelectedItem?.ToString(), false))
            {
                MessageBox.Show("Please check the base folder is a valid one and has no invalid characters"
                                , "TVRename Add/Edit Movie",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);

                Folders.SelectedTab = tabPage5;
                cbDirectory.Focus();

                return(false);
            }

            if (chkAutoFolders.Checked && rdoFolderCustom.Checked && !txtFolderNameFormat.Text.IsValidDirectory())
            {
                MessageBox.Show("Please check the custom subdirectory is a valid one and has no invalid characters"
                                , "TVRename Add/Edit Show",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);

                Folders.SelectedTab = tabPage5;
                txtFolderNameFormat.Focus();

                return(false);
            }

            return(true);
        }
Beispiel #3
0
        private bool OkToClose()
        {
            if (tabControl1.SelectedTab == tpTV && TVDoc.GetMediaCache(tvCodeFinder.Source).HasSeries(tvCodeFinder.SelectedCode()))
            {
                return(true);
            }
            if (tabControl1.SelectedTab == tpMovie && TVDoc.GetMediaCache(movieCodeFinder.Source).HasMovie(movieCodeFinder.SelectedCode()))
            {
                return(true);
            }

            DialogResult dr = MessageBox.Show("Code unknown, close anyway?", "TVRename Auto Add Media",
                                              MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            return(dr != DialogResult.No);
        }
Beispiel #4
0
        public static bool GenerateEpisodeDict([NotNull] ShowConfiguration si)
        {
            // copy data from tvdb
            // process as per rules
            // done!

            bool r = true;

            lock (TVDoc.GetMediaCache(si.Provider).SERIES_LOCK)
            {
                si.ClearEpisodes();

                CachedSeriesInfo ser = TVDoc.GetMediaCache(si.Provider).GetSeries(si.Code);

                if (ser is null)
                {
                    Logger.Warn($"Asked to generate episodes for {si.ShowName}, but this has not yet been downloaded from {si.Provider.PrettyPrint()}");
                    return(false);
                }

                foreach (Episode ep in ser.Episodes)
                {
                    si.AddEpisode(ep);
                }

                foreach (int snum in si.AppropriateSeasons().Keys.ToList())
                {
                    List <ProcessedEpisode> pel = GenerateEpisodes(si, snum, true);
                    si.SeasonEpisodes[snum] = pel;
                    if (pel is null)
                    {
                        r = false;
                    }
                }

                AddOverallCount(si);
            }

            return(r);
        }
Beispiel #5
0
        private ProcessedEpisode?GetNextMostRecentProcessedEpisode(int nDaysFuture, ICollection <ProcessedEpisode> found, DateTime notBefore)
        {
            ProcessedEpisode nextAfterThat = null;
            TimeSpan         howClose      = TimeSpan.MaxValue;

            foreach (ShowConfiguration si in GetSortedShowItems())
            {
                lock (TVDoc.GetMediaCache(si.Provider).SERIES_LOCK)
                {
                    if (!si.ShowNextAirdate)
                    {
                        continue;
                    }

                    foreach (KeyValuePair <int, List <ProcessedEpisode> > v in si.ActiveSeasons.ToList())
                    {
                        if (si.IgnoreSeasons.Contains(v.Key))
                        {
                            continue; // ignore this season
                        }

                        if (v.Key == 0 && TVSettings.Instance.IgnoreAllSpecials)
                        {
                            continue;
                        }

                        if (v.Value is null)
                        {
                            continue;
                        }

                        foreach (ProcessedEpisode ei in v.Value)
                        {
                            if (found.Contains(ei))
                            {
                                continue;
                            }

                            DateTime?airdt = ei.GetAirDateDt(true);

                            if (airdt is null || airdt == DateTime.MaxValue)
                            {
                                continue;
                            }

                            DateTime dt = airdt.Value;

                            TimeSpan timeUntil = dt.Subtract(DateTime.Now);
                            if (timeUntil.TotalDays > nDaysFuture)
                            {
                                continue; //episode is too far in the future
                            }

                            TimeSpan ts = dt.Subtract(notBefore);
                            if (ts.TotalSeconds < 0)
                            {
                                continue; //episode is too far in the past
                            }

                            //if we have a closer match
                            if (TimeSpan.Compare(ts, howClose) < 0)
                            {
                                howClose      = ts;
                                nextAfterThat = ei;
                            }
                        }
                    }
                }
            }

            return(nextAfterThat);
        }
Beispiel #6
0
 private int CountDirtyIdsFrom(TVDoc.ProviderType provider, MediaConfiguration.MediaType type)
 {
     return(type == MediaConfiguration.MediaType.tv
         ?downloadIds.Count(s => s.Provider == provider && s.Type == type && (TVDoc.GetMediaCache(provider).GetSeries(s.IdFor(provider))?.Dirty ?? true))
         :downloadIds.Count(s => s.Provider == provider && s.Type == type && (TVDoc.GetMediaCache(provider).GetMovie(s.IdFor(provider))?.Dirty ?? true)));
 }