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

Add Tvdb Collection Ids #162

Merged
merged 7 commits into from
Jul 15, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;

namespace Jellyfin.Plugin.Tvdb.Providers.ExternalId
{
/// <inheritdoc/>
public class TvdbCollectionsExternalId : IExternalId
{
/// <inheritdoc/>
public string ProviderName => TvdbPlugin.ProviderName;

/// <inheritdoc/>
public string Key => TvdbPlugin.CollectionProviderId;

/// <inheritdoc/>
public ExternalIdMediaType? Type => ExternalIdMediaType.BoxSet;

/// <inheritdoc/>
public string? UrlFormatString => null;

/// <inheritdoc/>
public bool Supports(IHasProviderIds item)
{
return item is Movie || item is Series;
}
}
}
22 changes: 21 additions & 1 deletion Jellyfin.Plugin.Tvdb/Providers/TvdbSeriesProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@
}
}

private static void MapSeriesToResult(MetadataResult<Series> result, SeriesExtendedRecord tvdbSeries, SeriesInfo info)
private void MapSeriesToResult(MetadataResult<Series> result, SeriesExtendedRecord tvdbSeries, SeriesInfo info)
{
Series series = result.Item;
series.SetTvdbId(tvdbSeries.Id);
Expand All @@ -455,6 +455,26 @@
// series.CommunityRating = (float?)tvdbSeries.SiteRating;
// Attempts to default to USA if not found
series.OfficialRating = tvdbSeries.ContentRatings.FirstOrDefault(x => string.Equals(x.Country, TvdbCultureInfo.GetCountryInfo(info.MetadataCountryCode)?.ThreeLetterISORegionName, StringComparison.OrdinalIgnoreCase))?.Name ?? tvdbSeries.ContentRatings.FirstOrDefault(x => string.Equals(x.Country, "usa", StringComparison.OrdinalIgnoreCase))?.Name;
if (tvdbSeries.Lists is not null && tvdbSeries.Lists is JsonElement jsonElement)
{
var collections = jsonElement.Deserialize<List<object>>();
if (collections is not null)
{
try
{
var collectionIds = collections.OfType<JsonElement>()
.Where(x => x.GetProperty("isOfficial").GetBoolean())
.Select(x => x.GetProperty("id").GetInt32().ToString(CultureInfo.InvariantCulture))
.Aggregate(new StringBuilder(), (sb, id) => sb.Append(id).Append(';'));

series.SetProviderIdIfHasValue(TvdbPlugin.CollectionProviderId, collectionIds.ToString());
}
catch (Exception e)
{
_logger.LogError(e, "Failed to retrieve collection for series {TvdbId}:{SeriesName}", tvdbSeries.Id, tvdbSeries.Name);
}
Comment on lines +472 to +475

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.
}
}

var imdbId = tvdbSeries.RemoteIds?.FirstOrDefault(x => string.Equals(x.SourceName, "IMDB", StringComparison.OrdinalIgnoreCase))?.Id.ToString();
series.SetProviderIdIfHasValue(MetadataProvider.Imdb, imdbId);
Expand Down
9 changes: 7 additions & 2 deletions Jellyfin.Plugin.Tvdb/TvdbPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using Jellyfin.Plugin.Tvdb.Configuration;
using MediaBrowser.Common.Configuration;
Expand All @@ -23,6 +23,11 @@ public class TvdbPlugin : BasePlugin<PluginConfiguration>, IHasWebPages
/// </summary>
public const string ProviderId = "Tvdb";

/// <summary>
/// Gets the collection provider id.
/// </summary>
public const string CollectionProviderId = "TvdbCollection";

/// <summary>
/// Initializes a new instance of the <see cref="TvdbPlugin"/> class.
/// </summary>
Expand Down Expand Up @@ -55,4 +60,4 @@ public IEnumerable<PluginPageInfo> GetPages()
};
}
}
}
}