Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issues retrieving episode metadata #116

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
|| 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));
Comment on lines +25 to +27

Check notice

Code scanning / CodeQL

Complex condition Note

Complex condition: too many logical operations in this expression.
}

/// <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