diff --git a/Jellyfin.Plugin.Tvdb/Configuration/PluginConfiguration.cs b/Jellyfin.Plugin.Tvdb/Configuration/PluginConfiguration.cs index 00e57ae..3fdb272 100644 --- a/Jellyfin.Plugin.Tvdb/Configuration/PluginConfiguration.cs +++ b/Jellyfin.Plugin.Tvdb/Configuration/PluginConfiguration.cs @@ -61,6 +61,11 @@ public int CacheDurationInDays /// public bool FallbackToOriginalLanguage { get; set; } = false; + /// + /// Gets or sets a value indicating whether to include original country in tags. + /// + public bool IncludeOriginalCountryInTags { get; set; } = false; + /// /// Gets or sets the metadata update in hours for the Check for Metadata Updates Scheduled Task. /// diff --git a/Jellyfin.Plugin.Tvdb/Configuration/config.html b/Jellyfin.Plugin.Tvdb/Configuration/config.html index 309668f..f293506 100644 --- a/Jellyfin.Plugin.Tvdb/Configuration/config.html +++ b/Jellyfin.Plugin.Tvdb/Configuration/config.html @@ -54,6 +54,10 @@

TheTVDB Settings:

Fallback to Original Language (Last resort if other fallback languages fails) +

Check for Metadata Updates Scheduled Task Settings:

@@ -104,6 +108,7 @@

Check for Metadata Updates Scheduled Task Settings:

Check for Metadata Updates Scheduled Task Settings: public string Name => TvdbPlugin.ProviderName; + private static bool IncludeOriginalCountryInTags => TvdbPlugin.Instance?.Configuration.IncludeOriginalCountryInTags ?? false; + /// public async Task> GetSearchResults(MovieInfo searchInfo, CancellationToken cancellationToken) { @@ -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) { diff --git a/Jellyfin.Plugin.Tvdb/Providers/TvdbSeriesProvider.cs b/Jellyfin.Plugin.Tvdb/Providers/TvdbSeriesProvider.cs index 9be0aa5..b54b17a 100644 --- a/Jellyfin.Plugin.Tvdb/Providers/TvdbSeriesProvider.cs +++ b/Jellyfin.Plugin.Tvdb/Providers/TvdbSeriesProvider.cs @@ -49,6 +49,8 @@ public TvdbSeriesProvider(IHttpClientFactory httpClientFactory, ILogger public string Name => TvdbPlugin.ProviderName; + private static bool IncludeOriginalCountryInTags => TvdbPlugin.Instance?.Configuration.IncludeOriginalCountryInTags ?? false; + /// public async Task> GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken) { @@ -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) { diff --git a/Jellyfin.Plugin.Tvdb/TvdbClientManager.cs b/Jellyfin.Plugin.Tvdb/TvdbClientManager.cs index afd3720..85b1930 100644 --- a/Jellyfin.Plugin.Tvdb/TvdbClientManager.cs +++ b/Jellyfin.Plugin.Tvdb/TvdbClientManager.cs @@ -553,6 +553,28 @@ public async Task> GetArtworkTypeAsync(CancellationTo return artworkTypesResult.Data; } + /// + /// Gets all tvdb Countries. + /// + /// Cancellation Token. + /// All tvdb countries. + public async Task> GetCountriesAsync(CancellationToken cancellationToken) + { + var key = "TvdbCountries"; + if (_memoryCache.TryGetValue(key, out IReadOnlyList? countries) + && countries is not null) + { + return countries; + } + + var countriesClient = _serviceProvider.GetRequiredService(); + await LoginAsync().ConfigureAwait(false); + var countriesResult = await countriesClient.GetAllCountriesAsync(cancellationToken: cancellationToken) + .ConfigureAwait(false); + _memoryCache.Set(key, countriesResult.Data, TimeSpan.FromDays(CacheDurationInDays)); + return countriesResult.Data; + } + /// /// Get an episode's tvdb id. /// @@ -753,6 +775,7 @@ private ServiceProvider ConfigureService(IApplicationHost applicationHost) services.AddTransient(_ => new ArtworkClient(_sdkClientSettings, _httpClientFactory.CreateClient(TvdbHttpClient))); services.AddTransient(_ => new Artwork_TypesClient(_sdkClientSettings, _httpClientFactory.CreateClient(TvdbHttpClient))); services.AddTransient(_ => new LanguagesClient(_sdkClientSettings, _httpClientFactory.CreateClient(TvdbHttpClient))); + services.AddTransient(_ => new CountriesClient(_sdkClientSettings, _httpClientFactory.CreateClient(TvdbHttpClient))); services.AddTransient(_ => new UpdatesClient(_sdkClientSettings, _httpClientFactory.CreateClient(TvdbHttpClient))); services.AddTransient(_ => new MoviesClient(_sdkClientSettings, _httpClientFactory.CreateClient(TvdbHttpClient)));