private static (int seas, int ep, int maxEp) IdentifyEpisode(ShowItem 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); }
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))); }
private static ShowSummaryData AddShowDetails([NotNull] ShowItem si) { SeriesInfo ser; lock (LocalCache.SERIES_LOCK) { ser = LocalCache.Instance.GetSeries(si.TvdbCode); } ShowSummaryData showSummary = new ShowSummaryData { ShowName = si.ShowName, ShowItem = si }; if (ser != null) { foreach (int snum in si.AppropriateSeasons().Keys) { ShowSummaryData.ShowSummarySeasonData seasonData = GetSeasonDetails(si, snum); showSummary.AddSeason(seasonData); } } return(showSummary); }
private static bool FindSeasEpDateCheck([CanBeNull] string filename, out int seas, out int ep, out int maxEp, [CanBeNull] ShowItem si) { ep = -1; seas = -1; maxEp = -1; if (filename is null || si is null) { return(false); } // look for a valid airdate in the filename // check for YMD, DMY, and MDY // only check against airdates we expect for the given show SeriesInfo ser = LocalCache.Instance.GetSeries(si.TvdbCode); if (ser is null) { return(false); } string[] dateFormats = { "yyyy-MM-dd", "dd-MM-yyyy", "MM-dd-yyyy", "yy-MM-dd", "dd-MM-yy", "MM-dd-yy" }; // force possible date separators to a dash filename = filename.Replace("/", "-"); filename = filename.Replace(".", "-"); filename = filename.Replace(",", "-"); filename = filename.Replace(" ", "-"); Dictionary <int, Season> seasonsToUse = si.AppropriateSeasons(); if (seasonsToUse is null) { return(false); } foreach (KeyValuePair <int, Season> kvp in seasonsToUse) { if (kvp.Value?.Episodes?.Values is null) { continue; } if (!(si.IgnoreSeasons is null) && si.IgnoreSeasons.Contains(kvp.Value.SeasonNumber)) { continue; } if (kvp.Value.SeasonNumber == 0 && TVSettings.Instance.IgnoreAllSpecials) { continue; } foreach (Episode epi in kvp.Value.Episodes.Values) { LocalDateTime?dt = epi.GetAirDateDt(); // file will have local timezone date, not ours if (dt is null) { continue; } TimeSpan closestDate = TimeSpan.MaxValue; foreach (string dateFormat in dateFormats) { string datestr = dt.Value.ToString(dateFormat, CultureInfo.CurrentCulture); if (filename.Contains(datestr) && DateTime.TryParseExact(datestr, dateFormat, new CultureInfo("en-GB"), DateTimeStyles.None, out DateTime dtInFilename)) { TimeSpan timeAgo = DateTime.Now.Subtract(dtInFilename); if (timeAgo < closestDate) { seas = epi.GetSeasonNumber(si.Order); ep = epi.GetEpisodeNumber(si.Order); closestDate = timeAgo; } } } } } return(ep != -1 && seas != -1); }