diff --git a/.gitignore b/.gitignore index ba81862..ebcea88 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ bin/ obj/ +.idea/ .vs/ diff --git a/Jellyfin.Plugin.Fanart.sln b/Jellyfin.Plugin.Fanart.sln index 28c5d7c..fde9846 100644 --- a/Jellyfin.Plugin.Fanart.sln +++ b/Jellyfin.Plugin.Fanart.sln @@ -1,7 +1,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfin.Plugin.Template", "Jellyfin.Plugin.Template\Jellyfin.Plugin.Template.csproj", "{D921B930-CF91-406F-ACBC-08914DCD0D34}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfin.Plugin.Fanart", "Jellyfin.Plugin.Fanart\Jellyfin.Plugin.Fanart.csproj", "{D921B930-CF91-406F-ACBC-08914DCD0D34}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Jellyfin.Plugin.Fanart/Plugin.cs b/Jellyfin.Plugin.Fanart/Plugin.cs index 2a9c9ea..777a204 100644 --- a/Jellyfin.Plugin.Fanart/Plugin.cs +++ b/Jellyfin.Plugin.Fanart/Plugin.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using Jellyfin.Plugin.Template.Configuration; +using Jellyfin.Plugin.Fanart.Configuration; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Plugins; using MediaBrowser.Model.Plugins; diff --git a/Jellyfin.Plugin.Fanart/Providers/FanArtAlbumProvider.cs b/Jellyfin.Plugin.Fanart/Providers/AlbumProvider.cs similarity index 89% rename from Jellyfin.Plugin.Fanart/Providers/FanArtAlbumProvider.cs rename to Jellyfin.Plugin.Fanart/Providers/AlbumProvider.cs index ebb740f..ab8a337 100644 --- a/Jellyfin.Plugin.Fanart/Providers/FanArtAlbumProvider.cs +++ b/Jellyfin.Plugin.Fanart/Providers/AlbumProvider.cs @@ -17,9 +17,9 @@ using MediaBrowser.Model.IO; using MediaBrowser.Model.Providers; using MediaBrowser.Model.Serialization; -namespace MediaBrowser.Providers.Music +namespace Jellyfin.Plugin.Fanart.Providers { - public class FanartAlbumProvider : IRemoteImageProvider, IHasOrder + public class AlbumProvider : IRemoteImageProvider, IHasOrder { private readonly CultureInfo _usCulture = new CultureInfo("en-US"); private readonly IServerConfigurationManager _config; @@ -27,7 +27,7 @@ namespace MediaBrowser.Providers.Music private readonly IFileSystem _fileSystem; private readonly IJsonSerializer _jsonSerializer; - public FanartAlbumProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem, IJsonSerializer jsonSerializer) + public AlbumProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem, IJsonSerializer jsonSerializer) { _config = config; _httpClient = httpClient; @@ -37,7 +37,7 @@ namespace MediaBrowser.Providers.Music public string Name => ProviderName; - public static string ProviderName => "FanArt"; + public static string ProviderName => "Fanart"; public bool Supports(BaseItem item) { @@ -70,9 +70,9 @@ namespace MediaBrowser.Providers.Music if (!string.IsNullOrEmpty(artistMusicBrainzId)) { - await FanartArtistProvider.Current.EnsureArtistJson(artistMusicBrainzId, cancellationToken).ConfigureAwait(false); + await ArtistProvider.Current.EnsureArtistJson(artistMusicBrainzId, cancellationToken).ConfigureAwait(false); - var artistJsonPath = FanartArtistProvider.GetArtistJsonPath(_config.CommonApplicationPaths, artistMusicBrainzId); + var artistJsonPath = ArtistProvider.GetArtistJsonPath(_config.CommonApplicationPaths, artistMusicBrainzId); var musicBrainzReleaseGroupId = album.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup); @@ -131,7 +131,7 @@ namespace MediaBrowser.Providers.Music /// The cancellation token. private void AddImages(List list, string path, string releaseId, string releaseGroupId, CancellationToken cancellationToken) { - var obj = _jsonSerializer.DeserializeFromFile(path); + var obj = _jsonSerializer.DeserializeFromFile(path); if (obj.albums != null) { @@ -146,7 +146,7 @@ namespace MediaBrowser.Providers.Music } private void PopulateImages(List list, - List images, + List images, ImageType type, int width, int height) diff --git a/Jellyfin.Plugin.Fanart/Providers/FanArtArtistProvider.cs b/Jellyfin.Plugin.Fanart/Providers/ArtistProvider.cs similarity index 86% rename from Jellyfin.Plugin.Fanart/Providers/FanArtArtistProvider.cs rename to Jellyfin.Plugin.Fanart/Providers/ArtistProvider.cs index 75b4213..fae8228 100644 --- a/Jellyfin.Plugin.Fanart/Providers/FanArtArtistProvider.cs +++ b/Jellyfin.Plugin.Fanart/Providers/ArtistProvider.cs @@ -19,15 +19,13 @@ using MediaBrowser.Model.IO; using MediaBrowser.Model.Net; using MediaBrowser.Model.Providers; using MediaBrowser.Model.Serialization; -using MediaBrowser.Providers.TV; -using MediaBrowser.Providers.TV.FanArt; -namespace MediaBrowser.Providers.Music +namespace Jellyfin.Plugin.Fanart.Providers { - public class FanartArtistProvider : IRemoteImageProvider, IHasOrder + public class ArtistProvider : IRemoteImageProvider, IHasOrder { internal const string ApiKey = "184e1a2b1fe3b94935365411f919f638"; - private const string FanArtBaseUrl = "https://webservice.fanart.tv/v3.1/music/{1}?api_key={0}"; + private const string BaseUrl = "https://webservice.fanart.tv/v3.1/music/{1}?api_key={0}"; private readonly CultureInfo _usCulture = new CultureInfo("en-US"); private readonly IServerConfigurationManager _config; @@ -35,9 +33,9 @@ namespace MediaBrowser.Providers.Music private readonly IFileSystem _fileSystem; private readonly IJsonSerializer _jsonSerializer; - internal static FanartArtistProvider Current; + internal static ArtistProvider Current; - public FanartArtistProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem, IJsonSerializer jsonSerializer) + public ArtistProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem, IJsonSerializer jsonSerializer) { _config = config; _httpClient = httpClient; @@ -49,7 +47,7 @@ namespace MediaBrowser.Providers.Music public string Name => ProviderName; - public static string ProviderName => "FanArt"; + public static string ProviderName => "Fanart"; public bool Supports(BaseItem item) { @@ -133,7 +131,7 @@ namespace MediaBrowser.Providers.Music /// The cancellation token. private void AddImages(List list, string path, CancellationToken cancellationToken) { - var obj = _jsonSerializer.DeserializeFromFile(path); + var obj = _jsonSerializer.DeserializeFromFile(path); PopulateImages(list, obj.artistbackground, ImageType.Backdrop, 1920, 1080); PopulateImages(list, obj.artistthumb, ImageType.Primary, 500, 281); @@ -145,7 +143,7 @@ namespace MediaBrowser.Providers.Music } private void PopulateImages(List list, - List images, + List images, ImageType type, int width, int height) @@ -224,9 +222,9 @@ namespace MediaBrowser.Providers.Music { cancellationToken.ThrowIfCancellationRequested(); - var url = string.Format(FanArtBaseUrl, ApiKey, musicBrainzId); + var url = string.Format(BaseUrl, ApiKey, musicBrainzId); - var clientKey = FanartSeriesProvider.Current.GetFanartOptions().UserApiKey; + var clientKey = SeriesProvider.Current.GetOptions().ApiKey; if (!string.IsNullOrWhiteSpace(clientKey)) { url += "&client_key=" + clientKey; @@ -259,7 +257,7 @@ namespace MediaBrowser.Providers.Music { if (ex.StatusCode.HasValue && ex.StatusCode.Value == HttpStatusCode.NotFound) { - _jsonSerializer.SerializeToFile(new FanartArtistResponse(), jsonPath); + _jsonSerializer.SerializeToFile(new ArtistResponse(), jsonPath); } else { @@ -301,7 +299,7 @@ namespace MediaBrowser.Providers.Music } - public class FanartArtistImage + public class ArtistImage { public string id { get; set; } public string url { get; set; } @@ -314,21 +312,21 @@ namespace MediaBrowser.Providers.Music public class Album { public string release_group_id { get; set; } - public List cdart { get; set; } - public List albumcover { get; set; } + public List cdart { get; set; } + public List albumcover { get; set; } } - public class FanartArtistResponse + public class ArtistResponse { public string name { get; set; } public string mbid_id { get; set; } - public List artistthumb { get; set; } - public List artistbackground { get; set; } - public List hdmusiclogo { get; set; } - public List musicbanner { get; set; } - public List musiclogo { get; set; } - public List musicarts { get; set; } - public List hdmusicarts { get; set; } + public List artistthumb { get; set; } + public List artistbackground { get; set; } + public List hdmusiclogo { get; set; } + public List musicbanner { get; set; } + public List musiclogo { get; set; } + public List musicarts { get; set; } + public List hdmusicarts { get; set; } public List albums { get; set; } } } diff --git a/Jellyfin.Plugin.Fanart/Providers/FanartMovieImageProvider.cs b/Jellyfin.Plugin.Fanart/Providers/MovieProvider.cs similarity index 91% rename from Jellyfin.Plugin.Fanart/Providers/FanartMovieImageProvider.cs rename to Jellyfin.Plugin.Fanart/Providers/MovieProvider.cs index 70d187b..ac0b115 100644 --- a/Jellyfin.Plugin.Fanart/Providers/FanartMovieImageProvider.cs +++ b/Jellyfin.Plugin.Fanart/Providers/MovieProvider.cs @@ -18,13 +18,10 @@ using MediaBrowser.Model.IO; using MediaBrowser.Model.Net; using MediaBrowser.Model.Providers; using MediaBrowser.Model.Serialization; -using MediaBrowser.Providers.Music; -using MediaBrowser.Providers.TV; -using MediaBrowser.Providers.TV.FanArt; -namespace MediaBrowser.Providers.Movies +namespace Jellyfin.Plugin.Fanart.Providers { - public class FanartMovieImageProvider : IRemoteImageProvider, IHasOrder + public class MovieProvider : IRemoteImageProvider, IHasOrder { private readonly CultureInfo _usCulture = new CultureInfo("en-US"); private readonly IServerConfigurationManager _config; @@ -32,11 +29,11 @@ namespace MediaBrowser.Providers.Movies private readonly IFileSystem _fileSystem; private readonly IJsonSerializer _json; - private const string FanArtBaseUrl = "https://webservice.fanart.tv/v3/movies/{1}?api_key={0}"; + private const string BaseUrl = "https://webservice.fanart.tv/v3/movies/{1}?api_key={0}"; - internal static FanartMovieImageProvider Current; + internal static MovieProvider Current; - public FanartMovieImageProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem, IJsonSerializer json) + public MovieProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem, IJsonSerializer json) { _config = config; _httpClient = httpClient; @@ -48,7 +45,7 @@ namespace MediaBrowser.Providers.Movies public string Name => ProviderName; - public static string ProviderName => "FanArt"; + public static string ProviderName => "Fanart"; public bool Supports(BaseItem item) { @@ -91,7 +88,7 @@ namespace MediaBrowser.Providers.Movies } } - var path = GetFanartJsonPath(movieId); + var path = GetJsonPath(movieId); try { @@ -229,7 +226,7 @@ namespace MediaBrowser.Providers.Movies return dataPath; } - public string GetFanartJsonPath(string id) + public string GetJsonPath(string id) { var movieDataPath = GetMovieDataPath(_config.ApplicationPaths, id); return Path.Combine(movieDataPath, "fanart.json"); @@ -245,15 +242,15 @@ namespace MediaBrowser.Providers.Movies { cancellationToken.ThrowIfCancellationRequested(); - var url = string.Format(FanArtBaseUrl, FanartArtistProvider.ApiKey, id); + var url = string.Format(BaseUrl, ArtistProvider.ApiKey, id); - var clientKey = FanartSeriesProvider.Current.GetFanartOptions().UserApiKey; + var clientKey = SeriesProvider.Current.GetOptions().ApiKey; if (!string.IsNullOrWhiteSpace(clientKey)) { url += "&client_key=" + clientKey; } - var path = GetFanartJsonPath(id); + var path = GetJsonPath(id); Directory.CreateDirectory(Path.GetDirectoryName(path)); @@ -292,7 +289,7 @@ namespace MediaBrowser.Providers.Movies internal Task EnsureMovieJson(string id, CancellationToken cancellationToken) { - var path = GetFanartJsonPath(id); + var path = GetJsonPath(id); var fileInfo = _fileSystem.GetFileSystemInfo(path); diff --git a/Jellyfin.Plugin.Fanart/Providers/FanArtSeasonProvider.cs b/Jellyfin.Plugin.Fanart/Providers/SeasonProvider.cs similarity index 88% rename from Jellyfin.Plugin.Fanart/Providers/FanArtSeasonProvider.cs rename to Jellyfin.Plugin.Fanart/Providers/SeasonProvider.cs index 5835691..c1a9ab1 100644 --- a/Jellyfin.Plugin.Fanart/Providers/FanArtSeasonProvider.cs +++ b/Jellyfin.Plugin.Fanart/Providers/SeasonProvider.cs @@ -19,9 +19,9 @@ using MediaBrowser.Model.Net; using MediaBrowser.Model.Providers; using MediaBrowser.Model.Serialization; -namespace MediaBrowser.Providers.TV.FanArt +namespace Jellyfin.Plugin.Fanart.Providers { - public class FanArtSeasonProvider : IRemoteImageProvider, IHasOrder + public class SeasonProvider : IRemoteImageProvider, IHasOrder { private readonly CultureInfo _usCulture = new CultureInfo("en-US"); private readonly IServerConfigurationManager _config; @@ -29,7 +29,7 @@ namespace MediaBrowser.Providers.TV.FanArt private readonly IFileSystem _fileSystem; private readonly IJsonSerializer _json; - public FanArtSeasonProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem, IJsonSerializer json) + public SeasonProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem, IJsonSerializer json) { _config = config; _httpClient = httpClient; @@ -39,7 +39,7 @@ namespace MediaBrowser.Providers.TV.FanArt public string Name => ProviderName; - public static string ProviderName => "FanArt"; + public static string ProviderName => "Fanart"; public bool Supports(BaseItem item) { @@ -73,7 +73,7 @@ namespace MediaBrowser.Providers.TV.FanArt // Bad id entered try { - await FanartSeriesProvider.Current.EnsureSeriesJson(id, cancellationToken).ConfigureAwait(false); + await SeriesProvider.Current.EnsureSeriesJson(id, cancellationToken).ConfigureAwait(false); } catch (HttpException ex) { @@ -83,7 +83,7 @@ namespace MediaBrowser.Providers.TV.FanArt } } - var path = FanartSeriesProvider.Current.GetFanartJsonPath(id); + var path = SeriesProvider.Current.GetJsonPath(id); try { @@ -131,12 +131,12 @@ namespace MediaBrowser.Providers.TV.FanArt private void AddImages(List list, int seasonNumber, string path, CancellationToken cancellationToken) { - var root = _json.DeserializeFromFile(path); + var root = _json.DeserializeFromFile(path); AddImages(list, root, seasonNumber, cancellationToken); } - private void AddImages(List list, FanartSeriesProvider.RootObject obj, int seasonNumber, CancellationToken cancellationToken) + private void AddImages(List list, SeriesProvider.RootObject obj, int seasonNumber, CancellationToken cancellationToken) { PopulateImages(list, obj.seasonposter, ImageType.Primary, 1000, 1426, seasonNumber); PopulateImages(list, obj.seasonbanner, ImageType.Banner, 1000, 185, seasonNumber); @@ -145,7 +145,7 @@ namespace MediaBrowser.Providers.TV.FanArt } private void PopulateImages(List list, - List images, + List images, ImageType type, int width, int height, diff --git a/Jellyfin.Plugin.Fanart/Providers/FanartSeriesProvider.cs b/Jellyfin.Plugin.Fanart/Providers/SeriesProvider.cs similarity index 89% rename from Jellyfin.Plugin.Fanart/Providers/FanartSeriesProvider.cs rename to Jellyfin.Plugin.Fanart/Providers/SeriesProvider.cs index 49cd959..0facfb8 100644 --- a/Jellyfin.Plugin.Fanart/Providers/FanartSeriesProvider.cs +++ b/Jellyfin.Plugin.Fanart/Providers/SeriesProvider.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Net; using System.Threading; using System.Threading.Tasks; +using Jellyfin.Plugin.Fanart.Configuration; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; @@ -20,11 +21,10 @@ using MediaBrowser.Model.IO; using MediaBrowser.Model.Net; using MediaBrowser.Model.Providers; using MediaBrowser.Model.Serialization; -using MediaBrowser.Providers.Music; -namespace MediaBrowser.Providers.TV.FanArt +namespace Jellyfin.Plugin.Fanart.Providers { - public class FanartSeriesProvider : IRemoteImageProvider, IHasOrder + public class SeriesProvider : IRemoteImageProvider, IHasOrder { private readonly CultureInfo _usCulture = new CultureInfo("en-US"); private readonly IServerConfigurationManager _config; @@ -32,11 +32,11 @@ namespace MediaBrowser.Providers.TV.FanArt private readonly IFileSystem _fileSystem; private readonly IJsonSerializer _json; - private const string FanArtBaseUrl = "https://webservice.fanart.tv/v3/tv/{1}?api_key={0}"; + private const string BaseUrl = "https://webservice.fanart.tv/v3/tv/{1}?api_key={0}"; - internal static FanartSeriesProvider Current { get; private set; } + internal static SeriesProvider Current { get; private set; } - public FanartSeriesProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem, IJsonSerializer json) + public SeriesProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem, IJsonSerializer json) { _config = config; _httpClient = httpClient; @@ -48,7 +48,10 @@ namespace MediaBrowser.Providers.TV.FanArt public string Name => ProviderName; - public static string ProviderName => "FanArt"; + public static string ProviderName => "Fanart"; + + public PluginConfiguration GetOptions() + => Plugin.Instance.Configuration; public bool Supports(BaseItem item) { @@ -91,7 +94,7 @@ namespace MediaBrowser.Providers.TV.FanArt } } - var path = GetFanartJsonPath(id); + var path = GetJsonPath(id); try { @@ -239,7 +242,7 @@ namespace MediaBrowser.Providers.TV.FanArt return dataPath; } - public string GetFanartJsonPath(string tvdbId) + public string GetJsonPath(string tvdbId) { var dataPath = GetSeriesDataPath(_config.ApplicationPaths, tvdbId); return Path.Combine(dataPath, "fanart.json"); @@ -248,7 +251,7 @@ namespace MediaBrowser.Providers.TV.FanArt private readonly SemaphoreSlim _ensureSemaphore = new SemaphoreSlim(1, 1); internal async Task EnsureSeriesJson(string tvdbId, CancellationToken cancellationToken) { - var path = GetFanartJsonPath(tvdbId); + var path = GetJsonPath(tvdbId); // Only allow one thread in here at a time since every season will be calling this method, possibly concurrently await _ensureSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); @@ -273,11 +276,6 @@ namespace MediaBrowser.Providers.TV.FanArt } } - public FanartOptions GetFanartOptions() - { - return _config.GetConfiguration("fanart"); - } - /// /// Downloads the series json. /// @@ -288,15 +286,15 @@ namespace MediaBrowser.Providers.TV.FanArt { cancellationToken.ThrowIfCancellationRequested(); - var url = string.Format(FanArtBaseUrl, FanartArtistProvider.ApiKey, tvdbId); + var url = string.Format(BaseUrl, ArtistProvider.ApiKey, tvdbId); - var clientKey = GetFanartOptions().UserApiKey; + var clientKey = GetOptions().ApiKey; if (!string.IsNullOrWhiteSpace(clientKey)) { url += "&client_key=" + clientKey; } - var path = GetFanartJsonPath(tvdbId); + var path = GetJsonPath(tvdbId); Directory.CreateDirectory(Path.GetDirectoryName(path)); @@ -360,19 +358,4 @@ namespace MediaBrowser.Providers.TV.FanArt public List seasonbanner { get; set; } } } - - public class FanartConfigStore : IConfigurationFactory - { - public IEnumerable GetConfigurations() - { - return new ConfigurationStore[] - { - new ConfigurationStore - { - Key = "fanart", - ConfigurationType = typeof(FanartOptions) - } - }; - } - } }