diff --git a/Jellyfin.Plugin.ITunes/Dtos/ITunesAlbumDto.cs b/Jellyfin.Plugin.ITunes/Dtos/ITunesAlbumDto.cs index c0cfcb6..968cc74 100644 --- a/Jellyfin.Plugin.ITunes/Dtos/ITunesAlbumDto.cs +++ b/Jellyfin.Plugin.ITunes/Dtos/ITunesAlbumDto.cs @@ -1,5 +1,4 @@ -#pragma warning disable CA1819 - +using System; using System.Text.Json.Serialization; namespace Jellyfin.Plugin.ITunes.Dtos @@ -21,6 +20,6 @@ public class ITunesAlbumDto /// /// The results. [JsonPropertyName("results")] - public Result[]? Results { get; set; } + public Result[] Results { get; set; } = Array.Empty(); } } diff --git a/Jellyfin.Plugin.ITunes/Dtos/ITunesArtistDto.cs b/Jellyfin.Plugin.ITunes/Dtos/ITunesArtistDto.cs index b943b44..0a6c4f2 100644 --- a/Jellyfin.Plugin.ITunes/Dtos/ITunesArtistDto.cs +++ b/Jellyfin.Plugin.ITunes/Dtos/ITunesArtistDto.cs @@ -1,5 +1,4 @@ -#pragma warning disable CA1819 - +using System; using System.Text.Json.Serialization; namespace Jellyfin.Plugin.ITunes.Dtos @@ -21,6 +20,6 @@ public class ITunesArtistDto /// /// The results. [JsonPropertyName("results")] - public ArtistResult[]? Results { get; set; } + public ArtistResult[] Results { get; set; } = Array.Empty(); } } diff --git a/Jellyfin.Plugin.ITunes/ITunesPlugin.cs b/Jellyfin.Plugin.ITunes/ITunesPlugin.cs index eece251..b8a2874 100644 --- a/Jellyfin.Plugin.ITunes/ITunesPlugin.cs +++ b/Jellyfin.Plugin.ITunes/ITunesPlugin.cs @@ -23,7 +23,7 @@ public ITunesPlugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerial } /// - public override string Name => "ITunes Art"; + public override string Name => "iTunes Art"; /// public override Guid Id => Guid.Parse("a9f62a44-fea5-46c3-ac26-55abba29c7c8"); diff --git a/Jellyfin.Plugin.ITunes/Providers/ITunesAlbumImageProvider.cs b/Jellyfin.Plugin.ITunes/Providers/ITunesAlbumImageProvider.cs index 9ce9e5a..a84b9af 100644 --- a/Jellyfin.Plugin.ITunes/Providers/ITunesAlbumImageProvider.cs +++ b/Jellyfin.Plugin.ITunes/Providers/ITunesAlbumImageProvider.cs @@ -16,7 +16,7 @@ namespace Jellyfin.Plugin.ITunesArt.Providers { /// - /// The ITunes album image provider. + /// The iTunes album image provider. /// public class ITunesAlbumImageProvider : IRemoteImageProvider, IHasOrder { @@ -78,7 +78,7 @@ public async Task GetImageResponse(string url, Cancellation } /// - /// Adds ITunes images to the current remote images of a . + /// Adds iTunes images to the current remote images of a . /// /// Object of the class. /// The cancellation token. @@ -103,9 +103,9 @@ public async Task> GetImages(BaseItem item, Cancell } var encodedName = Uri.EscapeDataString(searchQuery); - var remoteImages = await GetImagesInternal($"https://itunes.apple.com/search?term={encodedName}&media=music&entity=album", cancellationToken).ConfigureAwait(false); + var remoteImages = await GetImagesInternal($"https://itunes.apple.com/search?term={encodedName}&media=music&entity=album&attribute=albumTerm", cancellationToken).ConfigureAwait(false); - if (remoteImages != null) + if (remoteImages is not null) { list.AddRange(remoteImages); } @@ -118,16 +118,16 @@ private async Task> GetImagesInternal(string url, C { List list = new List(); - var iTunesAlbumDto = await _httpClientFactory + var iTunesArtistDto = await _httpClientFactory .CreateClient(NamedClient.Default) .GetFromJsonAsync(new Uri(url), cancellationToken) .ConfigureAwait(false); - if (iTunesAlbumDto != null && iTunesAlbumDto.Results != null) + if (iTunesArtistDto is not null && iTunesArtistDto.ResultCount > 0) { - foreach (Result result in iTunesAlbumDto.Results) + foreach (Result result in iTunesArtistDto.Results) { - if (result.ArtworkUrl100 != null) + 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 @@ -139,7 +139,7 @@ private async Task> GetImagesInternal(string url, C ProviderName = Name, Url = image1400, Type = ImageType.Primary, - ThumbnailUrl = result?.ArtworkUrl100, + ThumbnailUrl = result.ArtworkUrl100, Height = 1400, Width = 1400 }); @@ -148,7 +148,7 @@ private async Task> GetImagesInternal(string url, C } else { - return Array.Empty(); + return list; } return list; diff --git a/Jellyfin.Plugin.ITunes/Providers/ITunesArtistImageProvider.cs b/Jellyfin.Plugin.ITunes/Providers/ITunesArtistImageProvider.cs index 3c64c93..a18cbd3 100644 --- a/Jellyfin.Plugin.ITunes/Providers/ITunesArtistImageProvider.cs +++ b/Jellyfin.Plugin.ITunes/Providers/ITunesArtistImageProvider.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Net.Http; using System.Net.Http.Json; using System.Threading; @@ -17,7 +18,7 @@ namespace Jellyfin.Plugin.ITunesArt.Providers { /// - /// The ITunes artist image provider. + /// The iTunes artist image provider. /// public class ITunesArtistImageProvider : IRemoteImageProvider, IHasOrder { @@ -72,7 +73,7 @@ public async Task GetImageResponse(string url, Cancellation } /// - /// Adds ITunes images to the current remote images of a . + /// Adds iTunes images to the current remote images of a . /// /// Object of the class. /// The cancellation token. @@ -88,9 +89,9 @@ public async Task> GetImages(BaseItem item, Cancell var encodedName = Uri.EscapeDataString(searchQuery); - var remoteImages = await GetImagesInternal($"https://itunes.apple.com/search?term=${encodedName}&media=music&entity=musicArtist", cancellationToken).ConfigureAwait(false); + var remoteImages = await GetImagesInternal($"https://itunes.apple.com/search?term=${encodedName}&media=music&entity=musicArtist&attribute=artistTerm", cancellationToken).ConfigureAwait(false); - if (remoteImages != null) + if (remoteImages is not null) { list.AddRange(remoteImages); } @@ -108,10 +109,10 @@ private async Task> GetImagesInternal(string url, C .GetFromJsonAsync(new Uri(url), cancellationToken) .ConfigureAwait(false); - if (iTunesAlbumDto != null && iTunesAlbumDto.Results != null) + if (iTunesAlbumDto is not null && iTunesAlbumDto.ResultCount > 0) { - var result = iTunesAlbumDto.Results[0]; - if (result.ArtistLinkUrl != null) + var result = iTunesAlbumDto.Results.First(); + if (result.ArtistLinkUrl is not null) { _logger.LogDebug("URL: {0}", result.ArtistLinkUrl); HtmlWeb web = new HtmlWeb(); @@ -142,7 +143,7 @@ private async Task> GetImagesInternal(string url, C } else { - return Array.Empty(); + return list; } return list;