Пример #1
0
        private static bool IsOneFound([NotNull] StringBuilder output, DirFilesCache dfc, [NotNull] ProcessedEpisode pep, [NotNull] ProcessedEpisode comparePep, ref bool largerFileSize)
        {
            output.AppendLine("####### POSSIBLE DUPLICATE DUE TO NAME##########");

            //Do the missing Test (ie is one missing and not the other)
            bool pepFound        = dfc.FindEpOnDisk(pep).Any();
            bool comparePepFound = dfc.FindEpOnDisk(comparePep).Any();
            bool oneFound        = pepFound ^ comparePepFound;

            if (oneFound)
            {
                output.AppendLine(
                    "####### POSSIBLE DUPLICATE DUE TO ONE MISSING AND ONE FOUND ##########");

                ProcessedEpisode possibleDupEpisode = pepFound ? pep : comparePep;
                //Test the file sizes in the season
                //More than 40% longer
                FileInfo   possibleDupFile   = dfc.FindEpOnDisk(possibleDupEpisode)[0];
                int        dupMovieLength    = possibleDupFile.GetFilmLength();
                List <int> otherMovieLengths = new List <int>();
                foreach (FileInfo file in possibleDupFile.Directory.EnumerateFiles())
                {
                    if (file.IsMovieFile())
                    {
                        otherMovieLengths.Add(file.GetFilmLength());
                    }
                }

                int averageMovieLength = otherMovieLengths.Count == 1
                    ?otherMovieLengths.Sum()
                    :(otherMovieLengths.Sum() - dupMovieLength) / (otherMovieLengths.Count - 1);

                largerFileSize = dupMovieLength > averageMovieLength * 1.4;
                if (largerFileSize)
                {
                    {
                        output.AppendLine(
                            "######################################################################");

                        output.AppendLine(
                            "####### SURELY WE HAVE ONE NOW                              ##########");

                        output.AppendLine(
                            $"####### {possibleDupEpisode.AiredEpNum}({possibleDupEpisode.Name}) has length {dupMovieLength} greater than the average in the directory of {averageMovieLength}");

                        output.AppendLine(
                            "######################################################################");
                    }
                }
            }

            return(oneFound);
        }
Пример #2
0
        private static ShowSummaryData.ShowSummarySeasonData GetSeasonDetails([NotNull] ShowItem si, int snum)
        {
            int           epCount      = 0;
            int           epGotCount   = 0;
            int           epAiredCount = 0;
            DirFilesCache dfc          = new DirFilesCache();
            Season        season       = null;

            Dictionary <int, Season> seasons = si.AppropriateSeasons();

            if (snum >= 0 && seasons.ContainsKey(snum))
            {
                season = seasons[snum];

                List <ProcessedEpisode> eis = si.SeasonEpisodes[snum];

                foreach (ProcessedEpisode ei in eis)
                {
                    epCount++;

                    // if has air date and has been aired in the past
                    if (ei.FirstAired != null && ei.FirstAired < DateTime.Now)
                    {
                        epAiredCount++;
                    }

                    List <FileInfo> fl = dfc.FindEpOnDisk(ei, false);
                    if (fl.Count != 0)
                    {
                        epGotCount++;
                    }
                }
            }
            return(new ShowSummaryData.ShowSummarySeasonData(snum, epCount, epAiredCount, epGotCount, season, si.IgnoreSeasons.Contains(snum)));
        }
Пример #3
0
            private void GenerateRightClickWatchMenu([NotNull] Season seas)
            {
                // for each episode in season, find it on disk
                bool          first = true;
                DirFilesCache dfc   = new DirFilesCache();

                foreach (ProcessedEpisode epds in show.SeasonEpisodes[seas.SeasonNumber])
                {
                    List <FileInfo> fl = dfc.FindEpOnDisk(epds, false);
                    if (fl.Count > 0)
                    {
                        if (first)
                        {
                            GenerateSeparator(gridSummary.showRightClickMenu);
                            first = false;
                        }

                        int n = gridSummary.mLastFileList.Count;
                        foreach (FileInfo fi in fl)
                        {
                            GenerateMenu(gridSummary.showRightClickMenu, "Watch: " + fi.FullName,
                                         (int)RightClickCommands.kWatchBase + n);

                            gridSummary.mLastFileList.Add(fi);
                            n++;
                        }
                    }
                }
            }
Пример #4
0
        private IEnumerable <ProcessedEpisode> GetMissingEps(DirFilesCache dfc, [NotNull] IEnumerable <ProcessedEpisode> lpe)
        {
            List <ProcessedEpisode> missing = new List <ProcessedEpisode>();

            foreach (ProcessedEpisode pe in lpe)
            {
                bool foundOnDisk = dfc.FindEpOnDisk(pe).Any();
                bool alreadyAired;

                DateTime?airDate = pe.GetAirDateDt(true);

                if (airDate.HasValue)
                {
                    alreadyAired = airDate.Value.CompareTo(DateTime.Now) < 0;
                }
                else
                {
                    alreadyAired = true;
                }

                if (!foundOnDisk && alreadyAired && (pe.Show.DoMissingCheck))
                {
                    missing.Add(pe);
                }
            }

            return(missing);
        }
Пример #5
0
        private static IEnumerable <ProcessedEpisode> GetMissingEps(DirFilesCache dfc, [NotNull] IEnumerable <ProcessedEpisode> lpe)
        {
            List <ProcessedEpisode> missing = new List <ProcessedEpisode>();

            foreach (ProcessedEpisode pe in lpe)
            {
                List <FileInfo> fl          = dfc.FindEpOnDisk(pe);
                bool            foundOnDisk = fl.Any(file => file.Name.StartsWith(TVSettings.Instance.FilenameFriendly(TVSettings.Instance.NamingStyle.NameFor(pe)), StringComparison.OrdinalIgnoreCase));
                bool            alreadyAired;

                DateTime?airDate = pe.GetAirDateDt(true);

                if (airDate.HasValue)
                {
                    alreadyAired = airDate.Value.CompareTo(DateTime.Now) < 0;
                }
                else
                {
                    alreadyAired = true;
                }

                if (!foundOnDisk && alreadyAired && pe.Show.DoMissingCheck)
                {
                    missing.Add(pe);
                }
            }

            return(missing);
        }
Пример #6
0
        protected override void Do()
        {
            IEnumerable <ProcessedEpisode> lpe = doc.Library.RecentEpisodes(TVSettings.Instance.WTWRecentDays);
            DirFilesCache dfc = new DirFilesCache();

            //Write Contents to file
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(Location()))
            {
                file.WriteLine(GenerateHeader());
                foreach (ProcessedEpisode episode in lpe)
                {
                    try
                    {
                        List <FileInfo> files = dfc.FindEpOnDisk(episode, false);

                        if (!files.Any())
                        {
                            continue;
                        }

                        string name   = TVSettings.Instance.NamingStyle.NameFor(episode);
                        int    length = files.First().GetFilmLength();

                        file.WriteLine(GenerateRecord(episode, files.First(), name, length));
                    }
                    catch (Exception ex)
                    {
                        LOGGER.Error(ex,
                                     $"Had to skip saving {episode?.Show?.ShowName} S{episode?.AppropriateSeasonNumber}E{episode?.AppropriateEpNum} saving to {Location()}");
                    }
                }

                file.WriteLine(GenerateFooter());
            }
        }
Пример #7
0
            private void GenerateRightClickWatchMenu([NotNull] ProcessedSeason seas)
            {
                // for each episode in season, find it on disk
                bool          first = true;
                DirFilesCache dfc   = new DirFilesCache();

                foreach (ProcessedEpisode epds in show.SeasonEpisodes[seas.SeasonNumber])
                {
                    List <FileInfo> fl = dfc.FindEpOnDisk(epds, false);
                    if (fl.Count > 0)
                    {
                        if (first)
                        {
                            GenerateSeparator(gridSummary.showRightClickMenu);
                            first = false;
                        }

                        foreach (FileInfo fi in fl)
                        {
                            ToolStripMenuItem tsi = new ToolStripMenuItem("Watch: " + fi.FullName);
                            tsi.Click += (sender, args) => { Helpers.OpenFile(fi.FullName); };
                            gridSummary.showRightClickMenu.Items.Add(tsi);
                        }
                    }
                }
            }
Пример #8
0
        public static string GetSeasonHtmlOverview([NotNull] this ShowItem si, [NotNull] Season s, bool includeDirectoryLinks)
        {
            StringBuilder sb  = new StringBuilder();
            DirFilesCache dfc = new DirFilesCache();
            Color         col = Color.FromName("ButtonFace");

            sb.AppendLine(HTMLHeader(10, col));
            sb.AppendSeason(s, si, col, includeDirectoryLinks);
            foreach (ProcessedEpisode ep in GetBestEpisodes(si, s))
            {
                List <FileInfo> fl = dfc.FindEpOnDisk(ep);
                sb.AppendEpisode(ep, fl, col);
            }
            sb.AppendLine(HTMLFooter());
            return(sb.ToString());
        }
Пример #9
0
        private static (ProcessedEpisode firstMatchingPep, bool fileCanBeDeleted) FirstMatchingPep(bool unattended,
                                                                                                   DirFilesCache dfc, FileInfo fi, List <ShowItem> matchingShows, SeriesInfo s, int seasF, int epF, ShowItem si,
                                                                                                   ProcessedEpisode firstMatchingPep, List <Item> returnActions, [CanBeNull] TVSettings.FilenameProcessorRE re, bool fileCanBeDeleted)
        {
            try
            {
                Episode          ep  = s.GetEpisode(seasF, epF, si.DvdOrder);
                ProcessedEpisode pep = new ProcessedEpisode(ep, si);
                firstMatchingPep = pep;
                List <FileInfo> encumbants = dfc.FindEpOnDisk(pep, false);

                if (encumbants.Count == 0)
                {
                    //File is needed as there are no files for that series/episode
                    fileCanBeDeleted = false;

                    returnActions.AddRange(CopyFutureDatedFile(fi, pep));
                }
                else
                {
                    foreach (FileInfo existingFile in encumbants)
                    {
                        if (existingFile.FullName.Equals(fi.FullName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            //the user has put the search folder and the download folder in the same place - DO NOT DELETE
                            fileCanBeDeleted = false;
                            continue;
                        }

                        fileCanBeDeleted = ReviewFile(unattended, fi, matchingShows, existingFile, fileCanBeDeleted,
                                                      returnActions, pep);
                    }
                }
            }
            catch (SeriesInfo.EpisodeNotFoundException)
            {
                LOGGER.Info(
                    $"Can't find the right episode for {fi.FullName} coming out as S{seasF}E{epF} using rule '{re?.Notes}'");

                fileCanBeDeleted = false;
            }

            return(firstMatchingPep, fileCanBeDeleted);
        }
Пример #10
0
        internal static void LogShowEpisodeSizes([NotNull] TVDoc doc)
        {
            doc.PreventAutoScan("Show File Sizes");
            StringBuilder output = new StringBuilder();

            output.AppendLine("");
            output.AppendLine("##################################################");
            output.AppendLine("File Quailty FINDER - Start");
            output.AppendLine("##################################################");
            Logger.Info(output.ToString());

            DirFilesCache dfc = new DirFilesCache();

            foreach (ShowItem si in doc.Library.Values)
            {
                foreach (List <ProcessedEpisode> episodes in si.SeasonEpisodes.Values.ToList())
                {
                    foreach (ProcessedEpisode pep in episodes)
                    {
                        List <FileInfo> files = dfc.FindEpOnDisk(pep);
                        foreach (FileInfo file in files)
                        {
                            int width  = file.GetFrameWidth();
                            int height = file.GetFrameHeight();
                            int length = file.GetFilmLength();
                            Logger.Info($"{width,-10}   {height,-10}   {length,-10}    {pep.Show.ShowName,-50}  {file.Name}");
                        }
                    }
                }
            }

            output.Clear();
            output.AppendLine("##################################################");
            output.AppendLine("File Quailty FINDER - End");
            output.AppendLine("##################################################");

            Logger.Info(output.ToString());
            doc.AllowAutoScan();
        }
Пример #11
0
        private static ShowSummaryData.ShowSummarySeasonData?GetSeasonDetails([NotNull] ShowConfiguration si, int snum)
        {
            int             epCount         = 0;
            int             epGotCount      = 0;
            int             epAiredCount    = 0;
            DirFilesCache   dfc             = new DirFilesCache();
            ProcessedSeason processedSeason = null;

            if (snum >= 0 && si.AppropriateSeasons().TryGetValue(snum, out processedSeason))
            {
                List <ProcessedEpisode> eis = si.SeasonEpisodes[snum];

                foreach (ProcessedEpisode ei in eis)
                {
                    epCount++;

                    // if has air date and has been aired in the past
                    if (ei.FirstAired != null && ei.FirstAired < DateTime.Now)
                    {
                        epAiredCount++;
                    }

                    List <FileInfo> fl = dfc.FindEpOnDisk(ei, false);
                    if (fl.Count != 0)
                    {
                        epGotCount++;
                    }
                }
            }

            if (processedSeason != null)
            {
                return(new ShowSummaryData.ShowSummarySeasonData(snum, epCount, epAiredCount, epGotCount,
                                                                 processedSeason, si.IgnoreSeasons.Contains(snum)));
            }

            return(null);
        }
Пример #12
0
        private ShowSummaryData.ShowSummarySeasonData getSeasonDetails([NotNull] ShowItem si, [NotNull] SeriesInfo ser, int snum)
        {
            int           epCount      = 0;
            int           epGotCount   = 0;
            int           epAiredCount = 0;
            DirFilesCache dfc          = new DirFilesCache();
            Season        season       = null;

            Dictionary <int, Season> seasons = si.DvdOrder ? ser.DvdSeasons : ser.AiredSeasons;

            if (snum >= 0 && seasons.ContainsKey(snum))
            {
                season = seasons[snum];

                List <ProcessedEpisode> eis = si.SeasonEpisodes.ContainsKey(snum)
                    ? si.SeasonEpisodes[snum] // use processed episodes if they are available
                    : ShowItem.ProcessedListFromEpisodes(season.Episodes.Values, si);

                foreach (ProcessedEpisode ei in eis)
                {
                    epCount++;

                    // if has air date and has been aired in the past
                    if (ei.FirstAired != null && ei.FirstAired < DateTime.Now)
                    {
                        epAiredCount++;
                    }

                    List <FileInfo> fl = dfc.FindEpOnDisk(ei, false);
                    if (fl.Count != 0)
                    {
                        epGotCount++;
                    }
                }
            }
            return(new ShowSummaryData.ShowSummarySeasonData(snum, epCount, epAiredCount, epGotCount, season, si.IgnoreSeasons.Contains(snum)));
        }
Пример #13
0
        protected override bool  Generate([NotNull] System.IO.Stream str, [NotNull] List <ProcessedEpisode> elist)
        {
            DirFilesCache     dfc      = new DirFilesCache();
            XmlWriterSettings settings = new XmlWriterSettings
            {
                Indent = true,
                NewLineOnAttributes = true,
                Encoding            = System.Text.Encoding.ASCII
            };

            using (XmlWriter writer = XmlWriter.Create(str, settings))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("WhenToWatch");

                foreach (ProcessedEpisode ei in elist)
                {
                    writer.WriteStartElement("item");
                    writer.WriteElement("id", ei.TheSeries.TvdbCode);
                    writer.WriteElement("SeriesName", ei.TheSeries.Name);
                    writer.WriteElement("SeasonNumber", Helpers.Pad(ei.AppropriateSeasonNumber));
                    writer.WriteElement("EpisodeNumber", Helpers.Pad(ei.AppropriateEpNum));
                    writer.WriteElement("EpisodeName", ei.Name);

                    writer.WriteStartElement("available");
                    DateTime?airdt = ei.GetAirDateDt(true);

                    if (airdt.HasValue && airdt.Value.CompareTo(DateTime.Now) < 0) // has aired
                    {
                        List <FileInfo> fl = dfc.FindEpOnDisk(ei);
                        if (fl.Count > 0)
                        {
                            writer.WriteValue("true");
                        }
                        else if (ei.Show.DoMissingCheck)
                        {
                            writer.WriteValue("false");
                        }
                        else
                        {
                            writer.WriteValue("no missing check");
                        }
                    }
                    else
                    {
                        writer.WriteValue("future");
                    }

                    writer.WriteEndElement();
                    writer.WriteElement("Overview", ei.Overview);

                    writer.WriteStartElement("FirstAired");
                    DateTime?dt = ei.GetAirDateDt(true);
                    if (dt != null)
                    {
                        writer.WriteValue(dt.Value.ToString("F"));
                    }

                    writer.WriteEndElement();

                    writer.WriteElement("Rating", ei.EpisodeRating);
                    writer.WriteElement("filename", ei.Filename);

                    writer.WriteEndElement(); // item
                }
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
            return(true);
        }
Пример #14
0
        private void ReviewFileInDownloadDirectory(bool unattended, FileInfo fi, [NotNull] List <ShowConfiguration> matchingShows, IDialogParent owner)
        {
            bool             fileCanBeDeleted = TVSettings.Instance.RemoveDownloadDirectoriesFiles;
            ProcessedEpisode firstMatchingPep = null;

            foreach (ShowConfiguration si in matchingShows)
            {
                FinderHelper.FindSeasEp(fi, out int seasF, out int epF, out int _, si, out TVSettings.FilenameProcessorRE re);

                if (!si.SeasonEpisodes.ContainsKey(seasF))
                {
                    LOGGER.Info($"Can't find the right season for {fi.FullName} coming out as S{seasF}E{epF} using rule '{re?.Notes}'");
                    fileCanBeDeleted = false;
                    continue;
                }

                ProcessedEpisode?pep = si.SeasonEpisodes[seasF].FirstOrDefault(ep => ep.AppropriateEpNum == epF);

                if (pep == null)
                {
                    LOGGER.Info($"Can't find the right episode for {fi.FullName} coming out as S{seasF}E{epF} using rule '{re?.Notes}'");
                    fileCanBeDeleted = false;
                    continue;
                }

                firstMatchingPep = pep;
                List <FileInfo> encumbants = dfc.FindEpOnDisk(pep, false);

                if (encumbants.Count == 0)
                {
                    //File is needed as there are no files for that cachedSeries/episode
                    fileCanBeDeleted = false;

                    CopyFutureDatedFile(fi, pep, MDoc);
                }
                else
                {
                    foreach (FileInfo existingFile in encumbants)
                    {
                        if (existingFile.FullName.Equals(fi.FullName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            //the user has put the search folder and the download folder in the same place - DO NOT DELETE
                            fileCanBeDeleted = false;
                            continue;
                        }

                        bool?deleteFile = ReviewFile(unattended, fi, matchingShows, existingFile, pep, owner);
                        if (deleteFile.HasValue && deleteFile.Value == false)
                        {
                            fileCanBeDeleted = false;
                        }
                    }
                }
            }

            if (fileCanBeDeleted)
            {
                LOGGER.Info(
                    $"Removing {fi.FullName} as it matches { matchingShows.Select(s => s.ShowName).ToCsv()} and no episodes are needed");

                returnActions.Add(new ActionDeleteFile(fi, firstMatchingPep, TVSettings.Instance.Tidyup));
            }
            else
            {
                filesThatMayBeNeeded.Add(fi);
            }
        }
Пример #15
0
        public static string GetSeasonHtmlOverviewOffline([NotNull] this ShowItem si, [NotNull] Season s)
        {
            SeriesInfo ser  = s.TheSeries;
            int        snum = s.SeasonNumber;
            string     body = "";

            if (!string.IsNullOrEmpty(ser.GetSeriesWideBannerPath()) &&
                !string.IsNullOrEmpty(TheTVDB.GetImageURL(ser.GetSeriesWideBannerPath())))
            {
                body += "<img width=758 height=140 src=\"" + TheTVDB.GetImageURL(ser.GetSeriesWideBannerPath()) +
                        "\"><br/>";
            }

            List <ProcessedEpisode> eis = si.SeasonEpisodes.ContainsKey(snum) ?
                                          si.SeasonEpisodes[snum] :
                                          ShowItem.ProcessedListFromEpisodes(s.Episodes.Values, si);

            string seasText = SeasonName(si, snum);

            if ((eis.Count > 0) && (eis[0].SeasonId > 0))
            {
                seasText = " - <A HREF=\"" + TheTVDB.Instance.WebsiteUrl(ser.TvdbCode, eis[0].SeasonId, false) + "\">" +
                           seasText + "</a>";
            }
            else
            {
                seasText = " - " + seasText;
            }

            body += "<h1><A HREF=\"" + TheTVDB.Instance.WebsiteUrl(si.TvdbCode, -1, true) + "\">" + si.ShowName +
                    "</A>" + seasText + "</h1>";

            DirFilesCache dfc = new DirFilesCache();

            foreach (ProcessedEpisode ei in eis)
            {
                string epl = ei.NumsAsString();

                string episodeUrl = TheTVDB.Instance.WebsiteUrl(ei.SeriesId, ei.SeasonId, ei.EpisodeId);

                body += "<A href=\"" + episodeUrl + "\" name=\"ep" + epl + "\">"; // anchor
                if (si.DvdOrder && snum == 0)
                {
                    body += "<b>" + ei.Name + "</b>";
                }
                else
                {
                    body += "<b>" + HttpUtility.HtmlEncode(CustomEpisodeName.NameForNoExt(ei, CustomEpisodeName.OldNStyle(6))) +
                            "</b>";
                }

                body += "</A>"; // anchor
                if (si.UseSequentialMatch && (ei.OverallNumber != -1))
                {
                    body += " (#" + ei.OverallNumber + ")";
                }

                List <FileInfo> fl = dfc.FindEpOnDisk(ei);
                if (fl.Count > 0)
                {
                    foreach (FileInfo fi in fl)
                    {
                        string urlFilename = HttpUtility.UrlEncode(fi.FullName);
                        body += $" <A HREF=\"watch://{urlFilename}\" class=\"search\">Watch</A>";
                        body += $" <A HREF=\"explore://{urlFilename}\" class=\"search\">Show in Explorer</A>";
                    }
                }
                else
                {
                    body += " <A HREF=\"" + TVSettings.Instance.BTSearchURL(ei) + "\" class=\"search\">Search</A>";
                }

                DateTime?dt = ei.GetAirDateDt(true);
                if ((dt != null) && (dt.Value.CompareTo(DateTime.MaxValue) != 0))
                {
                    body += "<p>" + dt.Value.ToShortDateString() + " (" + ei.HowLong() + ")";
                }

                body += "<p><p>";

                if ((TVSettings.Instance.ShowEpisodePictures) ||
                    (TVSettings.Instance.HideMyShowsSpoilers && ei.HowLong() != "Aired"))
                {
                    body += "<table><tr>";
                    body += "<td width=100% valign=top>" + GetOverview(ei) + "</td><td width=300 height=225>";
                    // 300x168 / 300x225
                    if (!string.IsNullOrEmpty(ei.Filename))
                    {
                        body += "<img src=" + TheTVDB.GetImageURL(ei.Filename) + ">";
                    }

                    body += "</td></tr></table>";
                }
                else
                {
                    body += GetOverview(ei);
                }

                body += "<p><hr><p>";
            } // for each episode in this season

            return(body);
        }
Пример #16
0
        private void ReviewFileInDownloadDirectory(bool unattended, FileInfo fi, [NotNull] List <ShowConfiguration> matchingShows, [NotNull] List <MovieConfiguration> matchingMovies, IDialogParent owner)
        {
            if (!matchingMovies.Any() && !matchingShows.Any())
            {
                // Some sort of random file - ignore
                return;
            }

            bool             fileCanBeDeleted = (TVSettings.Instance.RemoveDownloadDirectoriesFiles && matchingShows.Any()) || (TVSettings.Instance.RemoveDownloadDirectoriesFilesMatchMovies && matchingMovies.Any());
            ProcessedEpisode firstMatchingPep = null;

            foreach (ShowConfiguration si in matchingShows)
            {
                FinderHelper.FindSeasEp(fi, out int seasF, out int epF, out int _, si, out TVSettings.FilenameProcessorRE re);

                if (!si.SeasonEpisodes.ContainsKey(seasF))
                {
                    if (seasF == -1)
                    {
                        LOGGER.Info(
                            $"Can't find the right season for {fi.FullName} coming out as S{seasF}E{epF} using rule '{re?.Notes}' for show {si.ShowName}:{si.Code}");
                    }
                    else
                    {
                        LOGGER.Warn(
                            $"Can't find the right season for {fi.FullName} coming out as S{seasF}E{epF} using rule '{re?.Notes}' for show {si.ShowName}:{si.Code}");
                    }

                    fileCanBeDeleted = false;
                    continue;
                }

                ProcessedEpisode?pep = si.SeasonEpisodes[seasF].FirstOrDefault(ep => ep.AppropriateEpNum == epF);

                if (pep == null)
                {
                    if (seasF == -1)
                    {
                        LOGGER.Info(
                            $"Can't find the right episode for {fi.FullName} coming out as S{seasF}E{epF} using rule '{re?.Notes}' for show {si.ShowName}:{si.Code}");
                    }
                    else
                    {
                        LOGGER.Warn(
                            $"Can't find the right episode for {fi.FullName} coming out as S{seasF}E{epF} using rule '{re?.Notes}' for show {si.ShowName}:{si.Code}");
                    }

                    fileCanBeDeleted = false;
                    continue;
                }

                firstMatchingPep = pep;
                List <FileInfo> encumbants = dfc.FindEpOnDisk(pep, false);

                if (encumbants.Count == 0)
                {
                    //File is needed as there are no files for that cachedSeries/episode
                    fileCanBeDeleted = false;

                    CopyFutureDatedFile(fi, pep, MDoc);
                }
                else
                {
                    foreach (FileInfo existingFile in encumbants)
                    {
                        if (existingFile.FullName.Equals(fi.FullName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            //the user has put the search folder and the download folder in the same place - DO NOT DELETE
                            fileCanBeDeleted = false;
                            continue;
                        }

                        bool?deleteFile = ReviewFile(unattended, fi, matchingShows, existingFile, pep, owner);
                        if (deleteFile.HasValue && deleteFile.Value == false)
                        {
                            fileCanBeDeleted = false;
                        }
                    }
                }
            }

            List <MovieConfiguration> neededMatchingMovie = matchingMovies.Where(si => FinderHelper.FileNeeded(fi, si, dfc)).ToList();

            if (neededMatchingMovie.Any())
            {
                LOGGER.Info($"Not removing {fi.FullName} as it may be needed for {neededMatchingMovie.Select(x => x.ShowName).ToCsv()}");

                fileCanBeDeleted = false;
            }
            else
            {
                if (TVSettings.Instance.RemoveDownloadDirectoriesFilesMatchMoviesLengthCheck && (matchingMovies.Max(c => c.ShowName.Length) <= TVSettings.Instance.RemoveDownloadDirectoriesFilesMatchMoviesLengthCheckLength))
                {
                    LOGGER.Info($"Not removing {fi.FullName} as it may be needed for {matchingMovies.Select(x => x.ShowName).ToCsv()} and they are all too short");

                    fileCanBeDeleted = false;
                }

                if (TVSettings.Instance.ReplaceMoviesWithBetterQuality)
                {
                    foreach (var testMovie in matchingMovies)
                    {
                        List <FileInfo> encumbants = dfc.FindMovieOnDisk(testMovie).ToList();

                        foreach (FileInfo existingFile in encumbants)
                        {
                            if (existingFile.FullName.Equals(fi.FullName, StringComparison.InvariantCultureIgnoreCase))
                            {
                                //the user has put the search folder and the download folder in the same place - DO NOT DELETE
                                fileCanBeDeleted = false;
                                continue;
                            }

                            bool?deleteFile = ReviewFile(unattended, fi, matchingMovies, existingFile, testMovie, owner);
                            if (deleteFile.HasValue && deleteFile.Value == false)
                            {
                                fileCanBeDeleted = false;
                            }
                        }
                    }
                }
            }

            if (fileCanBeDeleted)
            {
                if (matchingMovies.Any())
                {
                    LOGGER.Info(
                        $"Removing {fi.FullName} as it matches {matchingMovies.Select(s => s.ShowName).ToCsv()} and no files are needed for those movies");
                    returnActions.Add(new ActionDeleteFile(fi, matchingMovies.LongestShowName(), TVSettings.Instance.Tidyup));
                }
                if (matchingShows.Any())
                {
                    LOGGER.Info(
                        $"Removing {fi.FullName} as it matches {matchingShows.Select(s => s.ShowName).ToCsv()} and no episodes are needed");

                    if (!matchingShows.Any())
                    {
                        returnActions.Add(new ActionDeleteFile(fi, firstMatchingPep, TVSettings.Instance.Tidyup));
                    }
                }
            }
            else
            {
                filesThatMayBeNeeded.Add(fi);
            }
        }
Пример #17
0
        private static bool IsFound(DirFilesCache dfc, ProcessedEpisode episode)
        {
            List <FileInfo> fl = dfc.FindEpOnDisk(episode);

            return(fl.Any());
        }