コード例 #1
0
        private static (int seas, int ep, int maxEp) IdentifyEpisode(ShowConfiguration?si, [NotNull] Match m, TVSettings.FilenameProcessorRE re)
        {
            if (!int.TryParse(m.Groups["s"].ToString(), out int seas))
            {
                if (!re.RegExpression.Contains("<s>") && (si?.AppropriateSeasons().Count ?? 0) == 1)
                {
                    seas = 1;
                }
                else
                {
                    seas = -1;
                }
            }

            if (!int.TryParse(m.Groups["e"].ToString(), out int ep))
            {
                ep = -1;
            }

            if (!int.TryParse(m.Groups["f"].ToString(), out int maxEp))
            {
                maxEp = -1;
            }

            return(seas, ep, maxEp);
        }
コード例 #2
0
        public static bool FindSeasEp(string directory, string filename, out int seas, out int ep, out int maxEp,
                                      [CanBeNull] ShowItem si, [NotNull] IEnumerable <TVSettings.FilenameProcessorRE> rexps, [CanBeNull] out TVSettings.FilenameProcessorRE rex)
        {
            string showNameHint = (si != null) ? si.ShowName : string.Empty;

            maxEp = -1;
            seas  = -1;
            ep    = -1;
            rex   = null;

            filename = SimplifyFilename(filename, showNameHint);

            string fullPath =
                directory + Path.DirectorySeparatorChar +
                filename; // construct full path with sanitised filename

            fullPath = fullPath.ToLower() + " ";

            foreach (TVSettings.FilenameProcessorRE re in rexps.Where(re => re.Enabled))
            {
                try
                {
                    string pathToTest = re.UseFullPath ? fullPath : filename.ToLower() + " ";

                    Match m = Regex.Match(pathToTest, re.RegExpression, RegexOptions.IgnoreCase);

                    if (m.Success)
                    {
                        (seas, ep, maxEp) = IdentifyEpisode(si, m, re);

                        rex = re;
                        if ((seas != -1) && (ep != -1))
                        {
                            return(true);
                        }
                    }
                }
                catch (FormatException)
                {
                }
                catch (ArgumentException)
                {
                }
            }

            return((seas != -1) && (ep != -1));
        }
コード例 #3
0
 public static bool FindSeasEp(FileInfo fi, out int seas, out int ep, out int maxEp, ShowItem si,
                               [CanBeNull] out TVSettings.FilenameProcessorRE re)
 {
     return(FindSeasEp(fi, out seas, out ep, out maxEp, si, TVSettings.Instance.FNPRegexs,
                       TVSettings.Instance.LookForDateInFilename, out re));
 }
コード例 #4
0
        public static bool FindSeasEp([CanBeNull] FileInfo fi, out int seas, out int ep, out int maxEp, ShowItem si,
                                      List <TVSettings.FilenameProcessorRE> rexps, bool doDateCheck, [CanBeNull] out TVSettings.FilenameProcessorRE re)
        {
            re = null;
            if (fi is null)
            {
                seas  = -1;
                ep    = -1;
                maxEp = -1;
                return(false);
            }

            if (doDateCheck && FindSeasEpDateCheck(fi, out seas, out ep, out maxEp, si))
            {
                return(true);
            }

            string filename = fi.Name;
            int    l        = filename.Length;
            int    le       = fi.Extension.Length;

            filename = filename.Substring(0, l - le);
            return(FindSeasEp(fi.Directory.FullName, filename, out seas, out ep, out maxEp, si, rexps, out re));
        }
コード例 #5
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);
        }