Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadowghost committed Feb 13, 2023
1 parent 56feef0 commit fee7afa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
5 changes: 2 additions & 3 deletions Jellyfin.Plugin.ITunes/Dtos/ITunesAlbumDto.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CA1819

using System;
using System.Text.Json.Serialization;

namespace Jellyfin.Plugin.ITunes.Dtos
Expand All @@ -21,6 +20,6 @@ public class ITunesAlbumDto
/// </summary>
/// <value>The results.</value>
[JsonPropertyName("results")]
public Result[]? Results { get; set; }
public Result[] Results { get; set; } = Array.Empty<Result>();
}
}
5 changes: 2 additions & 3 deletions Jellyfin.Plugin.ITunes/Dtos/ITunesArtistDto.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CA1819

using System;
using System.Text.Json.Serialization;

namespace Jellyfin.Plugin.ITunes.Dtos
Expand All @@ -21,6 +20,6 @@ public class ITunesArtistDto
/// </summary>
/// <value>The results.</value>
[JsonPropertyName("results")]
public ArtistResult[]? Results { get; set; }
public ArtistResult[] Results { get; set; } = Array.Empty<ArtistResult>();
}
}
2 changes: 1 addition & 1 deletion Jellyfin.Plugin.ITunes/ITunesPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ITunesPlugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerial
}

/// <inheritdoc />
public override string Name => "ITunes Art";
public override string Name => "iTunes Art";

/// <inheritdoc />
public override Guid Id => Guid.Parse("a9f62a44-fea5-46c3-ac26-55abba29c7c8");
Expand Down
20 changes: 10 additions & 10 deletions Jellyfin.Plugin.ITunes/Providers/ITunesAlbumImageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace Jellyfin.Plugin.ITunesArt.Providers
{
/// <summary>
/// The ITunes album image provider.
/// The iTunes album image provider.
/// </summary>
public class ITunesAlbumImageProvider : IRemoteImageProvider, IHasOrder
{
Expand Down Expand Up @@ -78,7 +78,7 @@ public async Task<HttpResponseMessage> GetImageResponse(string url, Cancellation
}

/// <summary>
/// Adds ITunes images to the current remote images of a <see cref="BaseItem"/>.
/// Adds iTunes images to the current remote images of a <see cref="BaseItem"/>.
/// </summary>
/// <param name="item">Object of the <see cref="BaseItem"/> class.</param>
/// <param name="cancellationToken">The cancellation token.</param>
Expand All @@ -103,9 +103,9 @@ public async Task<IEnumerable<RemoteImageInfo>> 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);
}
Expand All @@ -118,16 +118,16 @@ private async Task<IEnumerable<RemoteImageInfo>> GetImagesInternal(string url, C
{
List<RemoteImageInfo> list = new List<RemoteImageInfo>();

var iTunesAlbumDto = await _httpClientFactory
var iTunesArtistDto = await _httpClientFactory
.CreateClient(NamedClient.Default)
.GetFromJsonAsync<ITunesAlbumDto>(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
Expand All @@ -139,7 +139,7 @@ private async Task<IEnumerable<RemoteImageInfo>> GetImagesInternal(string url, C
ProviderName = Name,
Url = image1400,
Type = ImageType.Primary,
ThumbnailUrl = result?.ArtworkUrl100,
ThumbnailUrl = result.ArtworkUrl100,
Height = 1400,
Width = 1400
});
Expand All @@ -148,7 +148,7 @@ private async Task<IEnumerable<RemoteImageInfo>> GetImagesInternal(string url, C
}
else
{
return Array.Empty<RemoteImageInfo>();
return list;
}

return list;
Expand Down
17 changes: 9 additions & 8 deletions Jellyfin.Plugin.ITunes/Providers/ITunesArtistImageProvider.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,7 +18,7 @@
namespace Jellyfin.Plugin.ITunesArt.Providers
{
/// <summary>
/// The ITunes artist image provider.
/// The iTunes artist image provider.
/// </summary>
public class ITunesArtistImageProvider : IRemoteImageProvider, IHasOrder
{
Expand Down Expand Up @@ -72,7 +73,7 @@ public async Task<HttpResponseMessage> GetImageResponse(string url, Cancellation
}

/// <summary>
/// Adds ITunes images to the current remote images of a <see cref="BaseItem"/>.
/// Adds iTunes images to the current remote images of a <see cref="BaseItem"/>.
/// </summary>
/// <param name="item">Object of the <see cref="BaseItem"/> class.</param>
/// <param name="cancellationToken">The cancellation token.</param>
Expand All @@ -88,9 +89,9 @@ public async Task<IEnumerable<RemoteImageInfo>> 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);
}
Expand All @@ -108,10 +109,10 @@ private async Task<IEnumerable<RemoteImageInfo>> GetImagesInternal(string url, C
.GetFromJsonAsync<ITunesArtistDto>(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();
Expand Down Expand Up @@ -142,7 +143,7 @@ private async Task<IEnumerable<RemoteImageInfo>> GetImagesInternal(string url, C
}
else
{
return Array.Empty<RemoteImageInfo>();
return list;
}

return list;
Expand Down

0 comments on commit fee7afa

Please sign in to comment.