示例#1
0
        public override void Check(SetProgressDelegate prog, int startpct, int totPct)
        {
            int c = this.TheActionList.Count + 2;
            int n = 1;

            prog.Invoke(100 * n / c);
            RSSItemList RSSList = new RSSItemList();

            foreach (string s in TVSettings.Instance.RSSURLs)
            {
                RSSList.DownloadRSS(s, TVSettings.Instance.FNPRegexs);
            }

            ItemList newItems = new ItemList();
            ItemList toRemove = new ItemList();

            foreach (Item Action1 in this.TheActionList)
            {
                if (this.ActionCancel)
                {
                    return;
                }

                n++;
                prog.Invoke(100 * n / c);

                if (!(Action1 is ItemMissing))
                {
                    continue;
                }

                ItemMissing Action = (ItemMissing)(Action1);

                ProcessedEpisode pe               = Action.Episode;
                string           simpleShowName   = Helpers.SimplifyName(pe.SI.ShowName);
                string           simpleSeriesName = Helpers.SimplifyName(pe.TheSeries.Name);

                foreach (RSSItem rss in RSSList)
                {
                    if ((FileHelper.SimplifyAndCheckFilename(rss.ShowName, simpleShowName, true, false) || (string.IsNullOrEmpty(rss.ShowName) && FileHelper.SimplifyAndCheckFilename(rss.Title, simpleSeriesName, true, false))) && (rss.Season == pe.SeasonNumber) && (rss.Episode == pe.EpNum))
                    {
                        newItems.Add(new ActionRSS(rss, Action.TheFileNoExt, pe));
                        toRemove.Add(Action1);
                    }
                }
            }
            foreach (Item i in toRemove)
            {
                this.TheActionList.Remove(i);
            }

            foreach (Item Action in newItems)
            {
                this.TheActionList.Add(Action);
            }

            prog.Invoke(100);
        }
示例#2
0
        public override void Check(SetProgressDelegate prog, int startpct, int totPct)
        {
            int c = this.ActionList.Count + 2;
            int n = 1;

            prog.Invoke(startpct);
            // ReSharper disable once InconsistentNaming
            RSSItemList RSSList = new RSSItemList();

            foreach (string s in TVSettings.Instance.RSSURLs)
            {
                RSSList.DownloadRSS(s, TVSettings.Instance.FNPRegexs);
            }

            ItemList newItems = new ItemList();
            ItemList toRemove = new ItemList();

            foreach (Item testItem in this.ActionList)
            {
                if (this.ActionCancel)
                {
                    return;
                }

                prog.Invoke(startpct + (totPct - startpct) * (++n) / (c));

                if (!(testItem is ItemMissing action))
                {
                    continue;
                }

                ProcessedEpisode pe               = action.Episode;
                string           simpleShowName   = Helpers.SimplifyName(pe.SI.ShowName);
                string           simpleSeriesName = Helpers.SimplifyName(pe.TheSeries.Name);

                foreach (RSSItem rss in RSSList)
                {
                    if (
                        !FileHelper.SimplifyAndCheckFilename(rss.ShowName, simpleShowName, true, false) &&
                        !(
                            string.IsNullOrEmpty(rss.ShowName) &&
                            FileHelper.SimplifyAndCheckFilename(rss.Title, simpleSeriesName, true, false)
                            )
                        )
                    {
                        continue;
                    }

                    if (rss.Season != pe.AppropriateSeasonNumber)
                    {
                        continue;
                    }
                    if (rss.Episode != pe.AppropriateEpNum)
                    {
                        continue;
                    }

                    Logger.Info($"Adding {rss.URL} as it appears to be match for {testItem.Episode.SI.ShowName} S{testItem.Episode.AppropriateSeasonNumber}E{testItem.Episode.AppropriateEpNum}");
                    newItems.Add(new ActionRSS(rss, action.TheFileNoExt, pe));
                    toRemove.Add(testItem);
                }
            }

            //We now want to rationlise the newItems - just in case we've added duplicates
            List <ActionRSS> duplicateActionRSS = new List <ActionRSS>();

            foreach (Item x in newItems)
            {
                if (!(x is ActionRSS testActionRSSOne))
                {
                    continue;
                }
                foreach (Item y in newItems)
                {
                    if (!(y is ActionRSS testActionRSSTwo))
                    {
                        continue;
                    }
                    if (x.Equals(y))
                    {
                        continue;
                    }

                    string[] preferredTerms = TVSettings.Instance.PreferredRSSSearchTerms();

                    if (testActionRSSOne.RSS.ShowName.ContainsOneOf(preferredTerms) &&
                        !testActionRSSTwo.RSS.ShowName.ContainsOneOf(preferredTerms))
                    {
                        duplicateActionRSS.Add(testActionRSSTwo);
                        Logger.Info($"Removing {testActionRSSTwo.RSS.URL} as it is not as good a match as {testActionRSSOne.RSS.URL }");
                    }

                    if (testActionRSSOne.RSS.Title.ContainsOneOf(preferredTerms) &&
                        !testActionRSSTwo.RSS.Title.ContainsOneOf(preferredTerms))
                    {
                        duplicateActionRSS.Add(testActionRSSTwo);
                        Logger.Info(
                            $"Removing {testActionRSSTwo.RSS.URL} as it is not as good a match as {testActionRSSOne.RSS.URL}");
                    }
                }
            }

            foreach (ActionRSS x in duplicateActionRSS)
            {
                newItems.Remove(x);
            }

            foreach (Item i in toRemove)
            {
                this.ActionList.Remove(i);
            }

            foreach (Item action in newItems)
            {
                this.ActionList.Add(action);
            }

            prog.Invoke(totPct);
        }