Skip to content

Commit

Permalink
Fixes issues retrieving episode metadata (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
scampower3 authored Mar 1, 2024
1 parent 1e7864f commit 6862c4d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
8 changes: 8 additions & 0 deletions Jellyfin.Plugin.Tvdb/ProviderIdsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;

using MediaBrowser.Model.Entities;
Expand All @@ -19,6 +20,13 @@ internal static bool IsSupported(this IHasProviderIds? item)
|| HasProviderId(item, MetadataProvider.Zap2It);
}

internal static bool IsSupported(this Dictionary<string, string> item)
{
return (item.TryGetValue(MetadataProvider.Tvdb.ToString(), out var tvdbId) && !string.IsNullOrEmpty(tvdbId))
|| (item.TryGetValue(MetadataProvider.Imdb.ToString(), out var imdbId) && !string.IsNullOrEmpty(imdbId))
|| (item.TryGetValue(MetadataProvider.Zap2It.ToString(), out var zap2ItId) && !string.IsNullOrEmpty(zap2ItId));
}

/// <summary>
/// Get the TvDB id stored within the item.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Jellyfin.Plugin.Tvdb/Providers/TvdbEpisodeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(EpisodeInfo

// Either an episode number or date must be provided; and the dictionary of provider ids must be valid
if ((searchInfo.IndexNumber == null && searchInfo.PremiereDate == null)
|| !searchInfo.IsSupported())
|| !searchInfo.SeriesProviderIds.IsSupported())
{
return list;
}
Expand Down Expand Up @@ -83,7 +83,7 @@ public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(EpisodeInfo
public async Task<MetadataResult<Episode>> GetMetadata(EpisodeInfo info, CancellationToken cancellationToken)
{
if ((info.IndexNumber == null && info.PremiereDate == null)
|| !info.IsSupported())
|| !info.SeriesProviderIds.IsSupported())
{
_logger.LogDebug("No series identity found for {EpisodeName}", info.Name);
return new MetadataResult<Episode>
Expand Down
12 changes: 9 additions & 3 deletions Jellyfin.Plugin.Tvdb/TvdbClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@ public async Task<IReadOnlyList<ArtworkType>> GetArtworkTypeAsync(CancellationTo
{
var seriesClient = _serviceProvider.GetRequiredService<ISeriesClient>();
await LoginAsync().ConfigureAwait(false);
if (!searchInfo.SeriesProviderIds.TryGetValue(TvdbPlugin.ProviderId, out var seriesTvdbIdString))
{
return null;
}

int seriesTvdbId = int.Parse(seriesTvdbIdString, CultureInfo.InvariantCulture);
int? episodeNumber = null;
int? seasonNumber = null;
string? airDate = null;
Expand Down Expand Up @@ -367,16 +373,16 @@ public async Task<IReadOnlyList<ArtworkType>> GetArtworkTypeAsync(CancellationTo
{
case "dvd":
case "absolute":
seriesResponse = await seriesClient.GetSeriesEpisodesAsync(page: 0, id: searchInfo.GetTvdbId(), season_type: searchInfo.SeriesDisplayOrder, season: seasonNumber, episodeNumber: episodeNumber, airDate: airDate, cancellationToken: cancellationToken).ConfigureAwait(false);
seriesResponse = await seriesClient.GetSeriesEpisodesAsync(page: 0, id: seriesTvdbId, season_type: searchInfo.SeriesDisplayOrder, season: seasonNumber, episodeNumber: episodeNumber, airDate: airDate, cancellationToken: cancellationToken).ConfigureAwait(false);
break;
default:
seriesResponse = await seriesClient.GetSeriesEpisodesAsync(page: 0, id: searchInfo.GetTvdbId(), season_type: "default", season: seasonNumber, episodeNumber: episodeNumber, airDate: airDate, cancellationToken: cancellationToken).ConfigureAwait(false);
seriesResponse = await seriesClient.GetSeriesEpisodesAsync(page: 0, id: seriesTvdbId, season_type: "default", season: seasonNumber, episodeNumber: episodeNumber, airDate: airDate, cancellationToken: cancellationToken).ConfigureAwait(false);
break;
}
}
else // when special use default order
{
seriesResponse = await seriesClient.GetSeriesEpisodesAsync(page: 0, id: searchInfo.GetTvdbId(), season_type: "default", season: seasonNumber, episodeNumber: episodeNumber, airDate: airDate, cancellationToken: cancellationToken).ConfigureAwait(false);
seriesResponse = await seriesClient.GetSeriesEpisodesAsync(page: 0, id: seriesTvdbId, season_type: "default", season: seasonNumber, episodeNumber: episodeNumber, airDate: airDate, cancellationToken: cancellationToken).ConfigureAwait(false);
}

Data2 seriesData = seriesResponse.Data;
Expand Down

0 comments on commit 6862c4d

Please sign in to comment.