Skip to content

Commit

Permalink
Add Tvdb Collection Ids (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
scampower3 authored Jul 15, 2024
1 parent 0d86fd1 commit f47458a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
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 async Task Identify(SeriesInfo info)
}
}

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 @@ private static void MapSeriesToResult(MetadataResult<Series> result, SeriesExten
// 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);
}
}
}

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()
};
}
}
}
}

0 comments on commit f47458a

Please sign in to comment.