From 6bcc7b2605b46cba51e3a68d2af3e722cfd24422 Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Wed, 4 Sep 2024 18:10:37 +0200 Subject: [PATCH] Update to .NET 8 --- .../Configuration/PluginConfiguration.cs | 13 +- Jellyfin.Plugin.ITunes/Dtos/AlbumResult.cs | 142 +++++++++++ Jellyfin.Plugin.ITunes/Dtos/ArtistResult.cs | 105 ++++---- Jellyfin.Plugin.ITunes/Dtos/ITunesAlbumDto.cs | 35 ++- .../Dtos/ITunesArtistDto.cs | 35 ++- Jellyfin.Plugin.ITunes/Dtos/Result.cs | 143 ----------- Jellyfin.Plugin.ITunes/ITunesPlugin.cs | 43 ++-- .../Jellyfin.Plugin.ITunes.csproj | 14 +- .../Providers/ITunesAlbumImageProvider.cs | 230 +++++++++--------- .../Providers/ITunesArtistImageProvider.cs | 184 +++++++------- build.yaml | 9 +- 11 files changed, 471 insertions(+), 482 deletions(-) create mode 100644 Jellyfin.Plugin.ITunes/Dtos/AlbumResult.cs delete mode 100644 Jellyfin.Plugin.ITunes/Dtos/Result.cs diff --git a/Jellyfin.Plugin.ITunes/Configuration/PluginConfiguration.cs b/Jellyfin.Plugin.ITunes/Configuration/PluginConfiguration.cs index a5d9720..c4c6fc1 100644 --- a/Jellyfin.Plugin.ITunes/Configuration/PluginConfiguration.cs +++ b/Jellyfin.Plugin.ITunes/Configuration/PluginConfiguration.cs @@ -1,11 +1,10 @@ using MediaBrowser.Model.Plugins; -namespace Jellyfin.Plugin.ITunes.Configuration +namespace Jellyfin.Plugin.ITunes.Configuration; + +/// +/// The (empty) plugin configuration. +/// +public class PluginConfiguration : BasePluginConfiguration { - /// - /// The (empty) plugin configuration. - /// - public class PluginConfiguration : BasePluginConfiguration - { - } } diff --git a/Jellyfin.Plugin.ITunes/Dtos/AlbumResult.cs b/Jellyfin.Plugin.ITunes/Dtos/AlbumResult.cs new file mode 100644 index 0000000..b4cfb66 --- /dev/null +++ b/Jellyfin.Plugin.ITunes/Dtos/AlbumResult.cs @@ -0,0 +1,142 @@ +using System.Text.Json.Serialization; + +namespace Jellyfin.Plugin.ITunes.Dtos; + +/// +/// Album result. +/// +public class AlbumResult +{ + /// + /// Gets or sets the wrapper type. + /// + [JsonPropertyName("wrapperType")] + public string? WrapperType { get; set; } + + /// + /// Gets or sets the collection type. + /// + [JsonPropertyName("collectionType")] + public string? CollectionType { get; set; } + + /// + /// Gets or sets the artist id. + /// + [JsonPropertyName("artistId")] + public long? ArtistId { get; set; } + + /// + /// Gets or sets the collection id. + /// + [JsonPropertyName("collectionId")] + public long? CollectionId { get; set; } + + /// + /// Gets or sets the artist name. + /// + [JsonPropertyName("artistName")] + public string? ArtistName { get; set; } + + /// + /// Gets or sets the collection name. + /// + [JsonPropertyName("collectionName")] + public string? CollectionName { get; set; } + + /// + /// Gets or sets the censored collection name. + /// + [JsonPropertyName("collectionCensoredName")] + public string? CollectionCensoredName { get; set; } + + /// + /// Gets or sets the artist view URL. + /// + [JsonPropertyName("artistViewUrl")] + public string? ArtistViewUrl { get; set; } + + /// + /// Gets or sets the collection view URL. + /// + [JsonPropertyName("collectionViewUrl")] + + public string? CollectionViewUrl { get; set; } + + /// + /// Gets or sets the 60px artwork URL. + /// + [JsonPropertyName("artworkUrl60")] + public string? ArtworkUrl60 { get; set; } + + /// + /// Gets or sets the 100px artwork URL. + /// + [JsonPropertyName("artworkUrl100")] + public string? ArtworkUrl100 { get; set; } + + /// + /// Gets or sets the collection price. + /// + [JsonPropertyName("collectionPrice")] + public double? CollectionPrice { get; set; } + + /// + /// Gets or sets the collection explicitness. + /// + [JsonPropertyName("collectionExplicitness")] + public string? CollectionExplicitness { get; set; } + + /// + /// Gets or sets the track count. + /// + [JsonPropertyName("trackCount")] + public long? TrackCount { get; set; } + + /// + /// Gets or sets the copyright. + /// + [JsonPropertyName("copyright")] + public string? Copyright { get; set; } + + /// + /// Gets or sets the country. + /// + /// The country. + [JsonPropertyName("country")] + public string? Country { get; set; } + + /// + /// Gets or sets the currency. + /// + /// The currency. + [JsonPropertyName("currency")] + public string? Currency { get; set; } + + /// + /// Gets or sets the release date. + /// + /// The release date. + [JsonPropertyName("releaseDate")] + public string? ReleaseDate { get; set; } + + /// + /// Gets or sets the primary genre name. + /// + /// The primary genre name. + [JsonPropertyName("primaryGenreName")] + public string? PrimaryGenreName { get; set; } + + /// + /// Gets or sets the content advisory rating. + /// + /// The content advisory rating. + [JsonPropertyName("contentAdvisoryRating")] + public string? ContentAdvisoryRating { get; set; } + + /// + /// Gets or sets the amg artist id. + /// + /// The amg artist id. + [JsonPropertyName("amgArtistId")] + public long? AmgArtistId { get; set; } +} diff --git a/Jellyfin.Plugin.ITunes/Dtos/ArtistResult.cs b/Jellyfin.Plugin.ITunes/Dtos/ArtistResult.cs index 67d859c..ddd246b 100644 --- a/Jellyfin.Plugin.ITunes/Dtos/ArtistResult.cs +++ b/Jellyfin.Plugin.ITunes/Dtos/ArtistResult.cs @@ -1,66 +1,65 @@ using System.Text.Json.Serialization; -namespace Jellyfin.Plugin.ITunes.Dtos +namespace Jellyfin.Plugin.ITunes.Dtos; + +/// +/// Artist result. +/// +public class ArtistResult { /// - /// Artist result. + /// Gets or sets the wrapper type. /// - public class ArtistResult - { - /// - /// Gets or sets the wrapper type. - /// - /// The wrapper type. - [JsonPropertyName("wrapperType")] - public string? WrapperType { get; set; } + /// The wrapper type. + [JsonPropertyName("wrapperType")] + public string? WrapperType { get; set; } - /// - /// Gets or sets the artist type. - /// - /// The artist type. - [JsonPropertyName("artistType")] - public string? ArtistType { get; set; } + /// + /// Gets or sets the artist type. + /// + /// The artist type. + [JsonPropertyName("artistType")] + public string? ArtistType { get; set; } - /// - /// Gets or sets the artist name. - /// - /// The artist name. - [JsonPropertyName("artistName")] - public string? ArtistName { get; set; } + /// + /// Gets or sets the artist name. + /// + /// The artist name. + [JsonPropertyName("artistName")] + public string? ArtistName { get; set; } - /// - /// Gets or sets the artist link url. - /// - /// The artist link url. - [JsonPropertyName("artistLinkUrl")] - public string? ArtistLinkUrl { get; set; } + /// + /// Gets or sets the artist link url. + /// + /// The artist link url. + [JsonPropertyName("artistLinkUrl")] + public string? ArtistLinkUrl { get; set; } - /// - /// Gets or sets the artist id. - /// - /// The artist id. - [JsonPropertyName("artistId")] - public long? ArtistId { get; set; } + /// + /// Gets or sets the artist id. + /// + /// The artist id. + [JsonPropertyName("artistId")] + public long? ArtistId { get; set; } - /// - /// Gets or sets the primary genre name. - /// - /// The primary genre name. - [JsonPropertyName("primaryGenreName")] - public string? PrimaryGenreName { get; set; } + /// + /// Gets or sets the primary genre name. + /// + /// The primary genre name. + [JsonPropertyName("primaryGenreName")] + public string? PrimaryGenreName { get; set; } - /// - /// Gets or sets the primary genre id. - /// - /// The primary genre id. - [JsonPropertyName("primaryGenreId")] - public long? PrimaryGenreId { get; set; } + /// + /// Gets or sets the primary genre id. + /// + /// The primary genre id. + [JsonPropertyName("primaryGenreId")] + public long? PrimaryGenreId { get; set; } - /// - /// Gets or sets the amg artist id. - /// - /// The amg artist id. - [JsonPropertyName("amgArtistId")] - public long? AmgArtistId { get; set; } - } + /// + /// Gets or sets the amg artist id. + /// + /// The amg artist id. + [JsonPropertyName("amgArtistId")] + public long? AmgArtistId { get; set; } } diff --git a/Jellyfin.Plugin.ITunes/Dtos/ITunesAlbumDto.cs b/Jellyfin.Plugin.ITunes/Dtos/ITunesAlbumDto.cs index 968cc74..0f3e951 100644 --- a/Jellyfin.Plugin.ITunes/Dtos/ITunesAlbumDto.cs +++ b/Jellyfin.Plugin.ITunes/Dtos/ITunesAlbumDto.cs @@ -1,25 +1,24 @@ -using System; +using System.Collections.Generic; using System.Text.Json.Serialization; -namespace Jellyfin.Plugin.ITunes.Dtos +namespace Jellyfin.Plugin.ITunes.Dtos; + +/// +/// The ALbum DTO. +/// +public class ITunesAlbumDto { /// - /// The ALbum DTO. + /// Gets or sets the result count. /// - public class ITunesAlbumDto - { - /// - /// Gets or sets the result count. - /// - /// The result count. - [JsonPropertyName("resultCount")] - public long ResultCount { get; set; } + /// The result count. + [JsonPropertyName("resultCount")] + public long ResultCount { get; set; } - /// - /// Gets or sets the results. - /// - /// The results. - [JsonPropertyName("results")] - public Result[] Results { get; set; } = Array.Empty(); - } + /// + /// Gets or sets the results. + /// + /// The results. + [JsonPropertyName("results")] + public IReadOnlyList Results { get; set; } = []; } diff --git a/Jellyfin.Plugin.ITunes/Dtos/ITunesArtistDto.cs b/Jellyfin.Plugin.ITunes/Dtos/ITunesArtistDto.cs index 0a6c4f2..0367e2d 100644 --- a/Jellyfin.Plugin.ITunes/Dtos/ITunesArtistDto.cs +++ b/Jellyfin.Plugin.ITunes/Dtos/ITunesArtistDto.cs @@ -1,25 +1,24 @@ -using System; +using System.Collections.Generic; using System.Text.Json.Serialization; -namespace Jellyfin.Plugin.ITunes.Dtos +namespace Jellyfin.Plugin.ITunes.Dtos; + +/// +/// The artist DTO. +/// +public class ITunesArtistDto { /// - /// The artist DTO. + /// Gets or sets the result count. /// - public class ITunesArtistDto - { - /// - /// Gets or sets the result count. - /// - /// The result count. - [JsonPropertyName("resultCount")] - public long ResultCount { get; set; } + /// The result count. + [JsonPropertyName("resultCount")] + public long ResultCount { get; set; } - /// - /// Gets or sets the results. - /// - /// The results. - [JsonPropertyName("results")] - public ArtistResult[] Results { get; set; } = Array.Empty(); - } + /// + /// Gets or sets the results. + /// + /// The results. + [JsonPropertyName("results")] + public IReadOnlyList Results { get; set; } = []; } diff --git a/Jellyfin.Plugin.ITunes/Dtos/Result.cs b/Jellyfin.Plugin.ITunes/Dtos/Result.cs deleted file mode 100644 index d1bf3f2..0000000 --- a/Jellyfin.Plugin.ITunes/Dtos/Result.cs +++ /dev/null @@ -1,143 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Jellyfin.Plugin.ITunes.Dtos -{ - /// - /// Result. - /// - public class Result - { - /// - /// Gets or sets the wrapper type. - /// - [JsonPropertyName("wrapperType")] - public string? WrapperType { get; set; } - - /// - /// Gets or sets the collection type. - /// - [JsonPropertyName("collectionType")] - public string? CollectionType { get; set; } - - /// - /// Gets or sets the artist id. - /// - [JsonPropertyName("artistId")] - public long? ArtistId { get; set; } - - /// - /// Gets or sets the collection id. - /// - [JsonPropertyName("collectionId")] - public long? CollectionId { get; set; } - - /// - /// Gets or sets the artist name. - /// - [JsonPropertyName("artistName")] - public string? ArtistName { get; set; } - - /// - /// Gets or sets the collection name. - /// - [JsonPropertyName("collectionName")] - public string? CollectionName { get; set; } - - /// - /// Gets or sets the censored collection name. - /// - [JsonPropertyName("collectionCensoredName")] - public string? CollectionCensoredName { get; set; } - - /// - /// Gets or sets the artist view URL. - /// - [JsonPropertyName("artistViewUrl")] - public string? ArtistViewUrl { get; set; } - - /// - /// Gets or sets the collection view URL. - /// - [JsonPropertyName("collectionViewUrl")] - - public string? CollectionViewUrl { get; set; } - - /// - /// Gets or sets the 60px artwork URL. - /// - [JsonPropertyName("artworkUrl60")] - public string? ArtworkUrl60 { get; set; } - - /// - /// Gets or sets the 100px artwork URL. - /// - [JsonPropertyName("artworkUrl100")] - public string? ArtworkUrl100 { get; set; } - - /// - /// Gets or sets the collection price. - /// - [JsonPropertyName("collectionPrice")] - public double? CollectionPrice { get; set; } - - /// - /// Gets or sets the collection explicitness. - /// - [JsonPropertyName("collectionExplicitness")] - public string? CollectionExplicitness { get; set; } - - /// - /// Gets or sets the track count. - /// - [JsonPropertyName("trackCount")] - public long? TrackCount { get; set; } - - /// - /// Gets or sets the copyright. - /// - [JsonPropertyName("copyright")] - public string? Copyright { get; set; } - - /// - /// Gets or sets the country. - /// - /// The country. - [JsonPropertyName("country")] - public string? Country { get; set; } - - /// - /// Gets or sets the currency. - /// - /// The currency. - [JsonPropertyName("currency")] - public string? Currency { get; set; } - - /// - /// Gets or sets the release date. - /// - /// The release date. - [JsonPropertyName("releaseDate")] - public string? ReleaseDate { get; set; } - - /// - /// Gets or sets the primary genre name. - /// - /// The primary genre name. - [JsonPropertyName("primaryGenreName")] - public string? PrimaryGenreName { get; set; } - - /// - /// Gets or sets the content advisory rating. - /// - /// The content advisory rating. - [JsonPropertyName("contentAdvisoryRating")] - public string? ContentAdvisoryRating { get; set; } - - /// - /// Gets or sets the amg artist id. - /// - /// The amg artist id. - [JsonPropertyName("amgArtistId")] - public long? AmgArtistId { get; set; } - } -} diff --git a/Jellyfin.Plugin.ITunes/ITunesPlugin.cs b/Jellyfin.Plugin.ITunes/ITunesPlugin.cs index b8a2874..9ccd80f 100644 --- a/Jellyfin.Plugin.ITunes/ITunesPlugin.cs +++ b/Jellyfin.Plugin.ITunes/ITunesPlugin.cs @@ -4,33 +4,32 @@ using MediaBrowser.Common.Plugins; using MediaBrowser.Model.Serialization; -namespace Jellyfin.Plugin.ITunesArt +namespace Jellyfin.Plugin.ITunesArt; + +/// +/// The ITunes art plugin. +/// +public class ITunesPlugin : BasePlugin { /// - /// The ITunes art plugin. + /// Initializes a new instance of the class. /// - public class ITunesPlugin : BasePlugin + /// Instance of the interface. + /// Instance of the interface. + public ITunesPlugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) + : base(applicationPaths, xmlSerializer) { - /// - /// Initializes a new instance of the class. - /// - /// Instance of the interface. - /// Instance of the interface. - public ITunesPlugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) - : base(applicationPaths, xmlSerializer) - { - Instance = this; - } + Instance = this; + } - /// - public override string Name => "iTunes Art"; + /// + public override string Name => "iTunes Art"; - /// - public override Guid Id => Guid.Parse("a9f62a44-fea5-46c3-ac26-55abba29c7c8"); + /// + public override Guid Id => Guid.Parse("a9f62a44-fea5-46c3-ac26-55abba29c7c8"); - /// - /// Gets the plugin instance. - /// - public ITunesPlugin? Instance { get; private set; } - } + /// + /// Gets the plugin instance. + /// + public ITunesPlugin? Instance { get; private set; } } diff --git a/Jellyfin.Plugin.ITunes/Jellyfin.Plugin.ITunes.csproj b/Jellyfin.Plugin.ITunes/Jellyfin.Plugin.ITunes.csproj index 94e3e6f..da51a91 100644 --- a/Jellyfin.Plugin.ITunes/Jellyfin.Plugin.ITunes.csproj +++ b/Jellyfin.Plugin.ITunes/Jellyfin.Plugin.ITunes.csproj @@ -1,10 +1,10 @@ - net7.0 + net8.0 Jellyfin.Plugin.ITunes - 2.0.0.0 - 2.0.0.0 + 3.0.0.0 + 3.0.0.0 true true enable @@ -15,11 +15,11 @@ - - - + + + - + diff --git a/Jellyfin.Plugin.ITunes/Providers/ITunesAlbumImageProvider.cs b/Jellyfin.Plugin.ITunes/Providers/ITunesAlbumImageProvider.cs index a84b9af..45d0a59 100644 --- a/Jellyfin.Plugin.ITunes/Providers/ITunesAlbumImageProvider.cs +++ b/Jellyfin.Plugin.ITunes/Providers/ITunesAlbumImageProvider.cs @@ -13,145 +13,141 @@ using MediaBrowser.Model.Providers; using Microsoft.Extensions.Logging; -namespace Jellyfin.Plugin.ITunesArt.Providers +namespace Jellyfin.Plugin.ITunesArt.Providers; + +/// +/// The iTunes album image provider. +/// +public class ITunesAlbumImageProvider : IRemoteImageProvider, IHasOrder { + private readonly IHttpClientFactory _httpClientFactory; + /// - /// The iTunes album image provider. + /// Initializes a new instance of the class. /// - public class ITunesAlbumImageProvider : IRemoteImageProvider, IHasOrder + /// Instance of the interface. + public ITunesAlbumImageProvider(IHttpClientFactory httpClientFactory) { - private readonly IHttpClientFactory _httpClientFactory; - private readonly ILogger _logger; - - /// - /// Initializes a new instance of the class. - /// - /// Instance of the interface. - /// Instance of the interface. - public ITunesAlbumImageProvider(IHttpClientFactory httpClientFactory, ILogger logger) - { - _httpClientFactory = httpClientFactory; - _logger = logger; - } + _httpClientFactory = httpClientFactory; + } - /// - /// Gets the provider name. - /// - public string Name => "Apple Music"; - - /// - /// Gets the plugin order. - /// - public int Order => 1; // After embedded provider - - /// - /// Gets if is supported. - /// - /// Object of the class. - /// IF is supported. - public bool Supports(BaseItem item) - => item is MusicAlbum; - - /// - /// Gets the supported to a . - /// - /// Object of the class. - /// Supported . - public IEnumerable GetSupportedImages(BaseItem item) - { - return new List - { - ImageType.Primary - }; - } + /// + /// Gets the provider name. + /// + public string Name => "Apple Music"; - /// - /// Gets the image from an URL. - /// - /// The URL. - /// The cancellation token. - /// . - public async Task GetImageResponse(string url, CancellationToken cancellationToken) - { - var httpClient = _httpClientFactory.CreateClient(NamedClient.Default); - return await httpClient.GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false); - } + /// + /// Gets the plugin order. + /// + public int Order => 1; // After embedded provider - /// - /// Adds iTunes images to the current remote images of a . - /// - /// Object of the class. - /// The cancellation token. - /// List of . - public async Task> GetImages(BaseItem item, CancellationToken cancellationToken) - { - var album = (MusicAlbum)item; - var list = new List(); + /// + /// Gets if is supported. + /// + /// Object of the class. + /// IF is supported. + public bool Supports(BaseItem item) + => item is MusicAlbum; - if (!string.IsNullOrEmpty(album.Name)) - { - var searchQuery = album.Name; + /// + /// Gets the supported to a . + /// + /// Object of the class. + /// Supported . + public IEnumerable GetSupportedImages(BaseItem item) + { + return + [ + ImageType.Primary + ]; + } - if (album.AlbumArtists.Count > 0) - { - string[] terms = - { - album.AlbumArtists[0], - album.Name - }; - searchQuery = string.Join(' ', terms); - } + /// + /// Gets the image from an URL. + /// + /// The URL. + /// The cancellation token. + /// . + public async Task GetImageResponse(string url, CancellationToken cancellationToken) + { + var httpClient = _httpClientFactory.CreateClient(NamedClient.Default); + return await httpClient.GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false); + } - var encodedName = Uri.EscapeDataString(searchQuery); - var remoteImages = await GetImagesInternal($"https://itunes.apple.com/search?term={encodedName}&media=music&entity=album&attribute=albumTerm", cancellationToken).ConfigureAwait(false); + /// + /// Adds iTunes images to the current remote images of a . + /// + /// Object of the class. + /// The cancellation token. + /// List of . + public async Task> GetImages(BaseItem item, CancellationToken cancellationToken) + { + var album = (MusicAlbum)item; + var list = new List(); - if (remoteImages is not null) - { - list.AddRange(remoteImages); - } + if (!string.IsNullOrEmpty(album.Name)) + { + var searchQuery = album.Name; + + if (album.AlbumArtists.Count > 0) + { + string[] terms = + [ + album.AlbumArtists[0], + album.Name + ]; + searchQuery = string.Join(' ', terms); } - return list; + var encodedName = Uri.EscapeDataString(searchQuery); + var remoteImages = await GetImagesInternal($"https://itunes.apple.com/search?term={encodedName}&media=music&entity=album&attribute=albumTerm", cancellationToken).ConfigureAwait(false); + + if (remoteImages is not null) + { + list.AddRange(remoteImages); + } } - private async Task> GetImagesInternal(string url, CancellationToken cancellationToken) - { - List list = new List(); + return list; + } - var iTunesArtistDto = await _httpClientFactory - .CreateClient(NamedClient.Default) - .GetFromJsonAsync(new Uri(url), cancellationToken) - .ConfigureAwait(false); + private async Task> GetImagesInternal(string url, CancellationToken cancellationToken) + { + List list = []; + + var iTunesAlbumDto = await _httpClientFactory + .CreateClient(NamedClient.Default) + .GetFromJsonAsync(new Uri(url), cancellationToken) + .ConfigureAwait(false); - if (iTunesArtistDto is not null && iTunesArtistDto.ResultCount > 0) + if (iTunesAlbumDto is not null && iTunesAlbumDto.ResultCount > 0) + { + foreach (AlbumResult album in iTunesAlbumDto.Results) { - foreach (Result result in iTunesArtistDto.Results) + if (!string.IsNullOrEmpty(album.ArtworkUrl100)) { - if (!string.IsNullOrEmpty(result.ArtworkUrl100)) - { - // The artwork size can vary quite a bit, but for our uses, 1400x1400 should be plenty. - // https://artists.apple.com/support/88-artist-image-guidelines - var image1400 = result.ArtworkUrl100.Replace("100x100bb", "1400x1400bb", StringComparison.OrdinalIgnoreCase); - - list.Add( - new RemoteImageInfo - { - ProviderName = Name, - Url = image1400, - Type = ImageType.Primary, - ThumbnailUrl = result.ArtworkUrl100, - Height = 1400, - Width = 1400 - }); - } + // The artwork size can vary quite a bit, but for our uses, 1400x1400 should be plenty. + // https://artists.apple.com/support/88-artist-image-guidelines + var image1400 = album.ArtworkUrl100.Replace("100x100bb", "1400x1400bb", StringComparison.OrdinalIgnoreCase); + + list.Add( + new RemoteImageInfo + { + ProviderName = Name, + Url = image1400, + Type = ImageType.Primary, + ThumbnailUrl = album.ArtworkUrl100, + Height = 1400, + Width = 1400 + }); } } - else - { - return list; - } - + } + else + { return list; } + + return list; } } diff --git a/Jellyfin.Plugin.ITunes/Providers/ITunesArtistImageProvider.cs b/Jellyfin.Plugin.ITunes/Providers/ITunesArtistImageProvider.cs index a18cbd3..ad4a714 100644 --- a/Jellyfin.Plugin.ITunes/Providers/ITunesArtistImageProvider.cs +++ b/Jellyfin.Plugin.ITunes/Providers/ITunesArtistImageProvider.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Net.Http; using System.Net.Http.Json; using System.Threading; @@ -15,108 +14,109 @@ using MediaBrowser.Model.Providers; using Microsoft.Extensions.Logging; -namespace Jellyfin.Plugin.ITunesArt.Providers +namespace Jellyfin.Plugin.ITunesArt.Providers; + +/// +/// The iTunes artist image provider. +/// +public class ITunesArtistImageProvider : IRemoteImageProvider, IHasOrder { + private readonly IHttpClientFactory _httpClientFactory; + private readonly ILogger _logger; + /// - /// The iTunes artist image provider. + /// Initializes a new instance of the class. /// - public class ITunesArtistImageProvider : IRemoteImageProvider, IHasOrder + /// Instance of the interface. + /// Instance of the interface. + public ITunesArtistImageProvider(IHttpClientFactory httpClientFactory, ILogger logger) { - private readonly IHttpClientFactory _httpClientFactory; - private readonly ILogger _logger; - - /// - /// Initializes a new instance of the class. - /// - /// Instance of the interface. - /// Instance of the interface. - public ITunesArtistImageProvider(IHttpClientFactory httpClientFactory, ILogger logger) - { - _httpClientFactory = httpClientFactory; - _logger = logger; - } + _httpClientFactory = httpClientFactory; + _logger = logger; + } - /// - /// Gets the provider name. - /// - public string Name => "Apple Music"; - - /// - /// Gets the provider order. - /// - // After fanart - public int Order => 1; - - /// - /// Gets the supported to a . - /// - /// Object of the class. - /// List of supported . - public IEnumerable GetSupportedImages(BaseItem item) - { - return new List - { - ImageType.Primary - }; - } + /// + /// Gets the provider name. + /// + public string Name => "Apple Music"; - /// - /// Gets the image response from an URL. - /// - /// The URL. - /// The cancellation token. - /// . - public async Task GetImageResponse(string url, CancellationToken cancellationToken) - { - var httpClient = _httpClientFactory.CreateClient(NamedClient.Default); - return await httpClient.GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false); - } + /// + /// Gets the provider order. + /// + // After fanart + public int Order => 1; - /// - /// Adds iTunes images to the current remote images of a . - /// - /// Object of the class. - /// The cancellation token. - /// List of . - public async Task> GetImages(BaseItem item, CancellationToken cancellationToken) - { - var artist = (MusicArtist)item; - var list = new List(); + /// + /// Gets the supported to a . + /// + /// Object of the class. + /// List of supported . + public IEnumerable GetSupportedImages(BaseItem item) + { + return + [ + ImageType.Primary + ]; + } - if (!string.IsNullOrEmpty(artist.Name)) - { - var searchQuery = artist.Name; + /// + /// Gets the image response from an URL. + /// + /// The URL. + /// The cancellation token. + /// . + public async Task GetImageResponse(string url, CancellationToken cancellationToken) + { + var httpClient = _httpClientFactory.CreateClient(NamedClient.Default); + return await httpClient.GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false); + } - var encodedName = Uri.EscapeDataString(searchQuery); + /// + /// Adds iTunes images to the current remote images of a . + /// + /// Object of the class. + /// The cancellation token. + /// List of . + public async Task> GetImages(BaseItem item, CancellationToken cancellationToken) + { + var artist = (MusicArtist)item; + var list = new List(); - var remoteImages = await GetImagesInternal($"https://itunes.apple.com/search?term=${encodedName}&media=music&entity=musicArtist&attribute=artistTerm", cancellationToken).ConfigureAwait(false); + if (!string.IsNullOrEmpty(artist.Name)) + { + var searchQuery = artist.Name; - if (remoteImages is not null) - { - list.AddRange(remoteImages); - } - } + var encodedName = Uri.EscapeDataString(searchQuery); - return list; + var remoteImages = await GetImagesInternal($"https://itunes.apple.com/search?term=${encodedName}&media=music&entity=musicArtist&attribute=artistTerm", cancellationToken).ConfigureAwait(false); + + if (remoteImages is not null) + { + list.AddRange(remoteImages); + } } - private async Task> GetImagesInternal(string url, CancellationToken cancellationToken) - { - List list = new List(); + return list; + } + + private async Task> GetImagesInternal(string url, CancellationToken cancellationToken) + { + List list = []; - var iTunesAlbumDto = await _httpClientFactory - .CreateClient(NamedClient.Default) - .GetFromJsonAsync(new Uri(url), cancellationToken) - .ConfigureAwait(false); + var iTunesArtistDto = await _httpClientFactory + .CreateClient(NamedClient.Default) + .GetFromJsonAsync(new Uri(url), cancellationToken) + .ConfigureAwait(false); - if (iTunesAlbumDto is not null && iTunesAlbumDto.ResultCount > 0) + if (iTunesArtistDto is not null && iTunesArtistDto.ResultCount > 0) + { + foreach (ArtistResult artist in iTunesArtistDto.Results) { - var result = iTunesAlbumDto.Results.First(); - if (result.ArtistLinkUrl is not null) + if (artist.ArtistLinkUrl is not null) { - _logger.LogDebug("URL: {0}", result.ArtistLinkUrl); + _logger.LogDebug("URL: {0}", artist.ArtistLinkUrl); HtmlWeb web = new HtmlWeb(); - var doc = web.Load(new Uri(result.ArtistLinkUrl)); + var doc = web.Load(new Uri(artist.ArtistLinkUrl)); var navigator = (HtmlAgilityPack.HtmlNodeNavigator)doc.CreateNavigator(); var metaOgImage = navigator.SelectSingleNode("/html/head/meta[@property='og:image']/@content"); @@ -141,16 +141,16 @@ private async Task> GetImagesInternal(string url, C } } } - else - { - return list; - } - + } + else + { return list; } - /// - public bool Supports(BaseItem item) - => item is MusicArtist; + return list; } + + /// + public bool Supports(BaseItem item) + => item is MusicArtist; } diff --git a/build.yaml b/build.yaml index ca00b1b..e1a1495 100644 --- a/build.yaml +++ b/build.yaml @@ -1,9 +1,9 @@ --- name: "iTunes" guid: "eb5d7894-8eef-4b36-aa6f-5d124e828ce1" -version: "2.0.0.0" +version: "3.0.0.0" targetAbi: "10.9.0.0" -framework: "net7.0" +framework: "net8.0" overview: "Fetch artist and album images from iTunes." description: > Fetch artist and album images from iTunes @@ -13,6 +13,5 @@ artifacts: - "HtmlAgilityPack.dll" - "Jellyfin.Plugin.ITunes.dll" changelog: > - 1.1.0.0: - * .NET 7 compatiblity - * Don't crash if nothing is found + 3.0.0.0: + * .NET 8 compatiblity