Skip to content

Commit

Permalink
Display order change fix, Cache collision fix, restrict airsbefore/af…
Browse files Browse the repository at this point in the history
…ter to aired display order (#143)
  • Loading branch information
scampower3 authored May 22, 2024
1 parent 7c62aa8 commit f79c195
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
13 changes: 9 additions & 4 deletions Jellyfin.Plugin.Tvdb/Providers/TvdbEpisodeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private async Task<MetadataResult<Episode>> 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)
Expand Down Expand Up @@ -215,9 +215,6 @@ private async Task<MetadataResult<Episode>> 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,
Expand All @@ -232,6 +229,14 @@ private async Task<MetadataResult<Episode>> 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)
{
Expand Down
12 changes: 9 additions & 3 deletions Jellyfin.Plugin.Tvdb/Providers/TvdbMissingEpisodeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Jellyfin.Plugin.Tvdb/ScheduledTasks/UpdateTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public async Task ExecuteAsync(IProgress<double> progress, CancellationToken can
{
MetadataRefreshMode = MetadataRefreshMode.FullRefresh,
ReplaceAllMetadata = true,
IsAutomated = false,
};
double increment = 90.0 / toUpdateItems.Count;
double currentProgress = 10;
Expand Down
2 changes: 1 addition & 1 deletion Jellyfin.Plugin.Tvdb/TvdbClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ public async Task<IReadOnlyList<ArtworkType>> 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)
{
Expand Down

0 comments on commit f79c195

Please sign in to comment.