From f79c195b63820c667fdb89fa9b2048f8da83de3f Mon Sep 17 00:00:00 2001 From: scampower3 <81431263+scampower3@users.noreply.github.com> Date: Wed, 22 May 2024 21:17:15 +0800 Subject: [PATCH] Display order change fix, Cache collision fix, restrict airsbefore/after to aired display order (#143) --- .../Providers/TvdbEpisodeProvider.cs | 13 +++++++++---- .../Providers/TvdbMissingEpisodeProvider.cs | 12 +++++++++--- Jellyfin.Plugin.Tvdb/ScheduledTasks/UpdateTask.cs | 1 + Jellyfin.Plugin.Tvdb/TvdbClientManager.cs | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Jellyfin.Plugin.Tvdb/Providers/TvdbEpisodeProvider.cs b/Jellyfin.Plugin.Tvdb/Providers/TvdbEpisodeProvider.cs index 4b199ba..99e6fea 100644 --- a/Jellyfin.Plugin.Tvdb/Providers/TvdbEpisodeProvider.cs +++ b/Jellyfin.Plugin.Tvdb/Providers/TvdbEpisodeProvider.cs @@ -168,7 +168,7 @@ private async Task> GetEpisode(EpisodeInfo searchInfo, C var episodeTvdbId = searchInfo.GetTvdbId().ToString(CultureInfo.InvariantCulture); try { - if (string.Equals(episodeTvdbId, "0", StringComparison.OrdinalIgnoreCase) || ignoreTvdbIdField) + if (string.Equals(episodeTvdbId, "0", StringComparison.OrdinalIgnoreCase) || ignoreTvdbIdField || searchInfo.IsAutomated) { episodeTvdbId = await _tvdbClientManager .GetEpisodeTvdbId(searchInfo, searchInfo.MetadataLanguage, cancellationToken) @@ -215,9 +215,6 @@ private async Task> MapEpisodeToResult(EpisodeInfo id, E IndexNumber = id.IndexNumber, ParentIndexNumber = id.ParentIndexNumber, IndexNumberEnd = id.IndexNumberEnd, - AirsBeforeEpisodeNumber = episode.AirsBeforeEpisode, - AirsAfterSeasonNumber = episode.AirsAfterSeason, - AirsBeforeSeasonNumber = episode.AirsBeforeSeason, // Tvdb uses 3 letter code for language (prob ISO 639-2) // Reverts to OriginalName if no translation is found Name = episode.Translations.GetTranslatedNamedOrDefault(id.MetadataLanguage) ?? episode.Name, @@ -232,6 +229,14 @@ private async Task> MapEpisodeToResult(EpisodeInfo id, E var imdbID = episode.RemoteIds.FirstOrDefault(x => string.Equals(x.SourceName, "IMDB", StringComparison.OrdinalIgnoreCase))?.Id; item.SetProviderIdIfHasValue(MetadataProvider.Imdb, imdbID); + // Below metadata info only applicable for Aired Order + if (string.IsNullOrEmpty(id.SeriesDisplayOrder)) + { + item.AirsBeforeEpisodeNumber = episode.AirsBeforeEpisode; + item.AirsAfterSeasonNumber = episode.AirsAfterSeason; + item.AirsBeforeSeasonNumber = episode.AirsBeforeSeason; + } + // Missing episodes loses the episode number when refreshed. if (id.IsMissingEpisode) { diff --git a/Jellyfin.Plugin.Tvdb/Providers/TvdbMissingEpisodeProvider.cs b/Jellyfin.Plugin.Tvdb/Providers/TvdbMissingEpisodeProvider.cs index d0d9bd5..0559eb0 100644 --- a/Jellyfin.Plugin.Tvdb/Providers/TvdbMissingEpisodeProvider.cs +++ b/Jellyfin.Plugin.Tvdb/Providers/TvdbMissingEpisodeProvider.cs @@ -449,15 +449,21 @@ private void AddVirtualEpisode(EpisodeBaseRecord? episode, Season? season) IsVirtualItem = true, SeasonId = season.Id, SeriesId = season.Series.Id, - AirsBeforeEpisodeNumber = episode.AirsBeforeEpisode, - AirsAfterSeasonNumber = episode.AirsAfterSeason, - AirsBeforeSeasonNumber = episode.AirsBeforeSeason, Overview = episode.Overview, SeriesName = season.Series.Name, SeriesPresentationUniqueKey = season.SeriesPresentationUniqueKey, SeasonName = season.Name, DateLastSaved = DateTime.UtcNow }; + + // Below metadata info only applicable for Aired Order + if (string.IsNullOrEmpty(season.Series.DisplayOrder)) + { + newEpisode.AirsBeforeEpisodeNumber = episode.AirsBeforeEpisode; + newEpisode.AirsAfterSeasonNumber = episode.AirsAfterSeason; + newEpisode.AirsBeforeSeasonNumber = episode.AirsBeforeSeason; + } + if (DateTime.TryParse(episode!.Aired, out var premiereDate)) { newEpisode.PremiereDate = premiereDate; diff --git a/Jellyfin.Plugin.Tvdb/ScheduledTasks/UpdateTask.cs b/Jellyfin.Plugin.Tvdb/ScheduledTasks/UpdateTask.cs index 0a59e26..98c055a 100644 --- a/Jellyfin.Plugin.Tvdb/ScheduledTasks/UpdateTask.cs +++ b/Jellyfin.Plugin.Tvdb/ScheduledTasks/UpdateTask.cs @@ -74,6 +74,7 @@ public async Task ExecuteAsync(IProgress progress, CancellationToken can { MetadataRefreshMode = MetadataRefreshMode.FullRefresh, ReplaceAllMetadata = true, + IsAutomated = false, }; double increment = 90.0 / toUpdateItems.Count; double currentProgress = 10; diff --git a/Jellyfin.Plugin.Tvdb/TvdbClientManager.cs b/Jellyfin.Plugin.Tvdb/TvdbClientManager.cs index f7b5101..7e1fbeb 100644 --- a/Jellyfin.Plugin.Tvdb/TvdbClientManager.cs +++ b/Jellyfin.Plugin.Tvdb/TvdbClientManager.cs @@ -477,7 +477,7 @@ public async Task> GetArtworkTypeAsync(CancellationTo break; } - key = $"FindTvdbEpisodeId_{seriesTvdbIdString}_{seasonNumber.Value.ToString(CultureInfo.InvariantCulture)}_{episodeNumber.Value.ToString(CultureInfo.InvariantCulture)}"; + key = $"FindTvdbEpisodeId_{seriesTvdbIdString}_{seasonNumber.Value.ToString(CultureInfo.InvariantCulture)}_{episodeNumber.Value.ToString(CultureInfo.InvariantCulture)}_{searchInfo.SeriesDisplayOrder}"; } else if (searchInfo.PremiereDate.HasValue) {