Skip to content

Commit

Permalink
Add original countries of series or movies as tags (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
scampower3 authored Oct 28, 2024
1 parent c46d02a commit 0d9c905
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Jellyfin.Plugin.Tvdb/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public int CacheDurationInDays
/// </summary>
public bool FallbackToOriginalLanguage { get; set; } = false;

/// <summary>
/// Gets or sets a value indicating whether to include original country in tags.
/// </summary>
public bool IncludeOriginalCountryInTags { get; set; } = false;

/// <summary>
/// Gets or sets the metadata update in hours for the Check for Metadata Updates Scheduled Task.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions Jellyfin.Plugin.Tvdb/Configuration/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ <h2 class="sectionTitle">TheTVDB Settings:</h2>
<input is="emby-checkbox" type="checkbox" id="fallbackToOriginalLanguage" />
<span>Fallback to Original Language (Last resort if other fallback languages fails)</span>
</label>
<label class="checkboxContainer">
<input is="emby-checkbox" type="checkbox" id="includeOriginalCountryInTags" />
<span>Include original country of the movie or series in tags.</span>
</label>
<div class="sectionTitleContainer flex align-items-center">
<h2 class="sectionTitle">Check for Metadata Updates Scheduled Task Settings:</h2>
</div>
Expand Down Expand Up @@ -104,6 +108,7 @@ <h2 class="sectionTitle">Check for Metadata Updates Scheduled Task Settings:</h2
document.getElementById('importSeasonName').checked = config.ImportSeasonName
document.getElementById('includeMissingSpecials').checked = config.IncludeMissingSpecials;
document.getElementById('fallbackToOriginalLanguage').checked = config.FallbackToOriginalLanguage;
document.getElementById('includeOriginalCountryInTags').checked = config.IncludeOriginalCountryInTags;

// Check for Metadata Updates Scheduled Task Settings
document.getElementById('metadataUpdateInHours').value = config.MetadataUpdateInHours;
Expand All @@ -126,6 +131,7 @@ <h2 class="sectionTitle">Check for Metadata Updates Scheduled Task Settings:</h2
config.ImportSeasonName = document.getElementById('importSeasonName').checked;
config.IncludeMissingSpecials = document.getElementById('includeMissingSpecials').checked;
config.FallbackToOriginalLanguage = document.getElementById('fallbackToOriginalLanguage').checked;
config.IncludeOriginalCountryInTags = document.getElementById('includeOriginalCountryInTags').checked;

//Check for Metadata Updates Scheduled Task Settings
config.MetadataUpdateInHours = document.getElementById('metadataUpdateInHours').value;
Expand Down
12 changes: 12 additions & 0 deletions Jellyfin.Plugin.Tvdb/Providers/TvdbMovieProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public TvdbMovieProvider(
/// <inheritdoc/>
public string Name => TvdbPlugin.ProviderName;

private static bool IncludeOriginalCountryInTags => TvdbPlugin.Instance?.Configuration.IncludeOriginalCountryInTags ?? false;

/// <inheritdoc/>
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(MovieInfo searchInfo, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -374,6 +376,16 @@ await _tvdbClientManager
{
_logger.LogError("Failed to retrieve actors for movie {TvdbId}:{MovieName}", tvdbId, movieInfo.Name);
}

if (IncludeOriginalCountryInTags && !string.IsNullOrWhiteSpace(movieResult.OriginalCountry))
{
var countries = await _tvdbClientManager.GetCountriesAsync(cancellationToken).ConfigureAwait(false);
var country = countries.FirstOrDefault(x => string.Equals(x.Id, movieResult.OriginalCountry, StringComparison.OrdinalIgnoreCase))?.Name;
if (!string.IsNullOrWhiteSpace(country))
{
movieMetadata.AddTag(country);
}
}
}
catch (Exception e)
{
Expand Down
12 changes: 12 additions & 0 deletions Jellyfin.Plugin.Tvdb/Providers/TvdbSeriesProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public TvdbSeriesProvider(IHttpClientFactory httpClientFactory, ILogger<TvdbSeri
/// <inheritdoc />
public string Name => TvdbPlugin.ProviderName;

private static bool IncludeOriginalCountryInTags => TvdbPlugin.Instance?.Configuration.IncludeOriginalCountryInTags ?? false;

/// <inheritdoc />
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -239,6 +241,16 @@ await _tvdbClientManager
{
_logger.LogError("Failed to retrieve actors for series {TvdbId}:{SeriesName}", tvdbId, seriesInfo.Name);
}

if (IncludeOriginalCountryInTags && !string.IsNullOrWhiteSpace(seriesResult.OriginalCountry))
{
var countries = await _tvdbClientManager.GetCountriesAsync(cancellationToken).ConfigureAwait(false);
var country = countries.FirstOrDefault(x => string.Equals(x.Id, seriesResult.OriginalCountry, StringComparison.OrdinalIgnoreCase))?.Name;
if (!string.IsNullOrWhiteSpace(country))
{
seriesMetadata.AddTag(country);
}
}
}
catch (Exception e)
{
Expand Down
23 changes: 23 additions & 0 deletions Jellyfin.Plugin.Tvdb/TvdbClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,28 @@ public async Task<IReadOnlyList<ArtworkType>> GetArtworkTypeAsync(CancellationTo
return artworkTypesResult.Data;
}

/// <summary>
/// Gets all tvdb Countries.
/// </summary>
/// <param name="cancellationToken">Cancellation Token.</param>
/// <returns>All tvdb countries.</returns>
public async Task<IReadOnlyList<Country>> GetCountriesAsync(CancellationToken cancellationToken)
{
var key = "TvdbCountries";
if (_memoryCache.TryGetValue(key, out IReadOnlyList<Country>? countries)
&& countries is not null)
{
return countries;
}

var countriesClient = _serviceProvider.GetRequiredService<ICountriesClient>();
await LoginAsync().ConfigureAwait(false);
var countriesResult = await countriesClient.GetAllCountriesAsync(cancellationToken: cancellationToken)
.ConfigureAwait(false);
_memoryCache.Set(key, countriesResult.Data, TimeSpan.FromDays(CacheDurationInDays));
return countriesResult.Data;
}

/// <summary>
/// Get an episode's tvdb id.
/// </summary>
Expand Down Expand Up @@ -753,6 +775,7 @@ private ServiceProvider ConfigureService(IApplicationHost applicationHost)
services.AddTransient<IArtworkClient>(_ => new ArtworkClient(_sdkClientSettings, _httpClientFactory.CreateClient(TvdbHttpClient)));
services.AddTransient<IArtwork_TypesClient>(_ => new Artwork_TypesClient(_sdkClientSettings, _httpClientFactory.CreateClient(TvdbHttpClient)));
services.AddTransient<ILanguagesClient>(_ => new LanguagesClient(_sdkClientSettings, _httpClientFactory.CreateClient(TvdbHttpClient)));
services.AddTransient<ICountriesClient>(_ => new CountriesClient(_sdkClientSettings, _httpClientFactory.CreateClient(TvdbHttpClient)));
services.AddTransient<IUpdatesClient>(_ => new UpdatesClient(_sdkClientSettings, _httpClientFactory.CreateClient(TvdbHttpClient)));
services.AddTransient<IMoviesClient>(_ => new MoviesClient(_sdkClientSettings, _httpClientFactory.CreateClient(TvdbHttpClient)));

Expand Down

0 comments on commit 0d9c905

Please sign in to comment.