private static string GuessShowName([NotNull] FoundFolder ai, [NotNull] ShowLibrary library) { // see if we can guess a season number and show name, too // Assume is blah\blah\blah\show\season X string showName = ai.Folder.FullName; foreach (string seasonWord in library.SeasonWords()) { string seasonFinder = ".*" + seasonWord + "[ _\\.]+([0-9]+).*"; if (Regex.Matches(showName, seasonFinder, RegexOptions.IgnoreCase).Count == 0) { continue; } try { // remove season folder from end of the path showName = Regex.Replace(showName, "(.*)\\\\" + seasonFinder, "$1", RegexOptions.IgnoreCase); break; } catch (ArgumentException) { } } // assume last folder element is the show name showName = showName.Substring(showName.LastIndexOf(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) + 1); return(showName); }
public static void GuessShowItem([NotNull] FoundFolder ai, [NotNull] ShowLibrary library, bool showErrorMsgBox) { string showName = GuessShowName(ai, library); int tvdbId = FindShowCode(ai); if (string.IsNullOrEmpty(showName) && tvdbId == -1) { return; } if (tvdbId != -1) { try { SeriesInfo series = TheTVDB.Instance.GetSeriesAndDownload(tvdbId); if (series != null) { ai.TVDBCode = tvdbId; return; } } catch (ShowNotFoundException) { //continue to try the next method } } SeriesInfo ser = TheTVDB.Instance.GetSeries(showName, showErrorMsgBox); if (ser != null) { ai.TVDBCode = ser.TvdbCode; return; } //Try removing any year string showNameNoYear = Regex.Replace(showName, @"\(\d{4}\)", "").Trim(); //Remove anything we can from hint to make it cleaner and hence more likely to match string refinedHint = FinderHelper.RemoveSeriesEpisodeIndicators(showNameNoYear, library.SeasonWords()); if (string.IsNullOrWhiteSpace(refinedHint)) { Logger.Info($"Ignoring {showName} as it refines to nothing."); } ser = TheTVDB.Instance.GetSeries(refinedHint, showErrorMsgBox); ai.RefinedHint = refinedHint; if (ser != null) { ai.TVDBCode = ser.TvdbCode; } }
public static void GuessShowItem([NotNull] PossibleNewTvShow ai, [NotNull] ShowLibrary library, bool showErrorMsgBox) { string languageCode = TVSettings.Instance.DefaultProvider == TVDoc.ProviderType.TMDB ? TVSettings.Instance.TMDBLanguage : TVSettings.Instance.PreferredLanguageCode; string showName = GuessShowName(ai, library); //todo - (BulkAdd Manager needs to work for new providers) int tvdbId = FindTVDBShowCode(ai); if (string.IsNullOrEmpty(showName) && tvdbId == -1) { return; } if (tvdbId != -1) { try { CachedSeriesInfo cachedSeries = TheTVDB.LocalCache.Instance.GetSeriesAndDownload(tvdbId, showErrorMsgBox); if (cachedSeries != null) { ai.SetId(tvdbId, TVDoc.ProviderType.TheTVDB); return; } } catch (MediaNotFoundException) { //continue to try the next method } } CachedSeriesInfo ser = TheTVDB.LocalCache.Instance.GetSeries(showName, showErrorMsgBox, languageCode); if (ser != null) { ai.SetId(tvdbId, TVDoc.ProviderType.TheTVDB); return; } //Try removing any year string showNameNoYear = Regex.Replace(showName, @"\(\d{4}\)", "").Trim(); //Remove anything we can from hint to make it cleaner and hence more likely to match string refinedHint = FinderHelper.RemoveSeriesEpisodeIndicators(showNameNoYear, library.SeasonWords()); if (string.IsNullOrWhiteSpace(refinedHint)) { Logger.Info($"Ignoring {showName} as it refines to nothing."); } ser = TheTVDB.LocalCache.Instance.GetSeries(refinedHint, showErrorMsgBox, languageCode); ai.RefinedHint = refinedHint; if (ser != null) { ai.SetId(tvdbId, TVDoc.ProviderType.TheTVDB); } }