forked from heyhippari/jellyfin-plugin-itunes
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8090317
commit 7f5ed3e
Showing
9 changed files
with
311 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...late/Configuration/PluginConfiguration.cs → ...unes/Configuration/PluginConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Jellyfin.Plugin.ITunes.Dtos | ||
{ | ||
public partial class ITunesAlbumDto | ||
{ | ||
[JsonPropertyName("resultCount")] | ||
public long ResultCount { get; set; } | ||
|
||
[JsonPropertyName("results")] | ||
public Result[] Results { get; set; } | ||
} | ||
|
||
public partial class Result | ||
{ | ||
[JsonPropertyName("wrapperType")] | ||
public string WrapperType { get; set; } | ||
|
||
[JsonPropertyName("collectionType")] | ||
public string CollectionType { get; set; } | ||
|
||
[JsonPropertyName("artistId")] | ||
public long ArtistId { get; set; } | ||
|
||
[JsonPropertyName("collectionId")] | ||
public long CollectionId { get; set; } | ||
|
||
[JsonPropertyName("artistName")] | ||
public string ArtistName { get; set; } | ||
|
||
[JsonPropertyName("collectionName")] | ||
public string CollectionName { get; set; } | ||
|
||
[JsonPropertyName("collectionCensoredName")] | ||
public string CollectionCensoredName { get; set; } | ||
|
||
[JsonPropertyName("artistViewUrl")] | ||
public string ArtistViewUrl { get; set; } | ||
|
||
[JsonPropertyName("collectionViewUrl")] | ||
public string CollectionViewUrl { get; set; } | ||
|
||
[JsonPropertyName("artworkUrl60")] | ||
public string ArtworkUrl60 { get; set; } | ||
|
||
[JsonPropertyName("artworkUrl100")] | ||
public string ArtworkUrl100 { get; set; } | ||
|
||
[JsonPropertyName("collectionPrice")] | ||
public double CollectionPrice { get; set; } | ||
|
||
[JsonPropertyName("collectionExplicitness")] | ||
public string CollectionExplicitness { get; set; } | ||
|
||
[JsonPropertyName("trackCount")] | ||
public long TrackCount { get; set; } | ||
|
||
[JsonPropertyName("copyright")] | ||
public string Copyright { get; set; } | ||
|
||
[JsonPropertyName("country")] | ||
public string Country { get; set; } | ||
|
||
[JsonPropertyName("currency")] | ||
public string Currency { get; set; } | ||
|
||
[JsonPropertyName("releaseDate")] | ||
public string ReleaseDate { get; set; } | ||
|
||
[JsonPropertyName("primaryGenreName")] | ||
public string PrimaryGenreName { get; set; } | ||
|
||
[JsonPropertyName("contentAdvisoryRating")] | ||
public string ContentAdvisoryRating { get; set; } | ||
|
||
[JsonPropertyName("amgArtistId")] | ||
public long? AmgArtistId { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<RootNamespace>Jellyfin.Plugin.ITunes</RootNamespace> | ||
<AssemblyVersion>1.0.0.0</AssemblyVersion> | ||
<FileVersion>1.0.0.0</FileVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="Configuration\configPage.html" /> | ||
<EmbeddedResource Include="Configuration\configPage.html" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Jellyfin.Controller" Version="10.*-*" /> | ||
<PackageReference Include="Jellyfin.Model" Version="10.*-*" /> | ||
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8" PrivateAssets="All" /> | ||
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" /> | ||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" /> | ||
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<CodeAnalysisRuleSet>../jellyfin.ruleset</CodeAnalysisRuleSet> | ||
</PropertyGroup> | ||
|
||
</Project> |
8 changes: 4 additions & 4 deletions
8
Jellyfin.Plugin.Template/Plugin.cs → Jellyfin.Plugin.ITunes/Plugin.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
Jellyfin.Plugin.ITunes/Providers/ItunesAlbumProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Net.Http.Json; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MediaBrowser.Common.Net; | ||
using MediaBrowser.Controller.Entities; | ||
using MediaBrowser.Controller.Entities.Audio; | ||
using MediaBrowser.Controller.Providers; | ||
using MediaBrowser.Model.Dto; | ||
using MediaBrowser.Model.Entities; | ||
using MediaBrowser.Model.Providers; | ||
using Microsoft.Extensions.Logging; | ||
using Jellyfin.Plugin.ITunes.Dtos; | ||
|
||
namespace Jellyfin.Plugin.ITunes.Providers | ||
{ | ||
public class ITunesAlbumProvider : IRemoteImageProvider, IHasOrder | ||
{ | ||
private readonly IHttpClientFactory _httpClientFactory; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ITunesAlbumProvider"/> class. | ||
/// </summary> | ||
/// <param name="httpClientFactory">Instance of the <see cref="IHttpClientFactory"/> interface.</param> | ||
/// <param name="logger">Instance of the <see cref="ILogger{CoverArtArchiveImageProvider}"/> interface.</param> | ||
public ITunesAlbumProvider(IHttpClientFactory httpClientFactory) | ||
{ | ||
_httpClientFactory = httpClientFactory; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public string Name => "iTunes"; | ||
|
||
/// <inheritdoc /> | ||
public int Order => 1; // After embedded provider | ||
|
||
/// <inheritdoc /> | ||
public bool Supports(BaseItem item) | ||
=> item is MusicAlbum; | ||
|
||
/// <inheritdoc /> | ||
public IEnumerable<ImageType> GetSupportedImages(BaseItem item) | ||
{ | ||
return new List<ImageType> | ||
{ | ||
ImageType.Primary | ||
}; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken) | ||
{ | ||
var httpClient = _httpClientFactory.CreateClient(NamedClient.Default); | ||
return await httpClient.GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken) | ||
{ | ||
var album = (MusicAlbum)item; | ||
var list = new List<RemoteImageInfo>(); | ||
|
||
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); | ||
} | ||
|
||
var encodedName = Uri.EscapeUriString(searchQuery); | ||
|
||
list.AddRange(await GetImagesInternal($"https://itunes.apple.com/search?term={encodedName}&media=music&entity=album", cancellationToken) | ||
.ConfigureAwait(false)); | ||
} | ||
|
||
return list; | ||
} | ||
|
||
private async Task<IEnumerable<RemoteImageInfo>> GetImagesInternal(string url, CancellationToken cancellationToken) | ||
{ | ||
List<RemoteImageInfo> list = new List<RemoteImageInfo>(); | ||
|
||
var iTunesAlbumDto = await _httpClientFactory | ||
.CreateClient(NamedClient.Default) | ||
.GetFromJsonAsync<ITunesAlbumDto>(new Uri(url)) | ||
.ConfigureAwait(false);; | ||
|
||
if (iTunesAlbumDto != null) | ||
{ | ||
foreach (Result result in iTunesAlbumDto.Results) | ||
{ | ||
// The max artwork size is 3000x3000. Some might return less, but we can't predict that. | ||
var image1400 = result.ArtworkUrl100.Replace("100x100bb","3000x3000bb"); | ||
|
||
list.Add( | ||
new RemoteImageInfo | ||
{ | ||
ProviderName = Name, | ||
Url = image1400, | ||
Type = ImageType.Primary, | ||
ThumbnailUrl = result.ArtworkUrl100, | ||
RatingType = RatingType.Score, | ||
} | ||
); | ||
} | ||
} | ||
else | ||
{ | ||
return Array.Empty<RemoteImageInfo>(); | ||
} | ||
|
||
return list; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RuleSet Name="Rules for Jellyfin.Server" Description="Code analysis rules for Jellyfin.Server.csproj" ToolsVersion="14.0"> | ||
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers"> | ||
<!-- disable warning SA1202: 'public' members must come before 'private' members --> | ||
<Rule Id="SA1202" Action="Info" /> | ||
<!-- disable warning SA1204: Static members must appear before non-static members --> | ||
<Rule Id="SA1204" Action="Info" /> | ||
<!-- disable warning SA1404: Code analysis suppression should have justification --> | ||
<Rule Id="SA1404" Action="Info" /> | ||
|
||
<!-- disable warning SA1009: Closing parenthesis should be followed by a space. --> | ||
<Rule Id="SA1009" Action="None" /> | ||
<!-- disable warning SA1101: Prefix local calls with 'this.' --> | ||
<Rule Id="SA1101" Action="None" /> | ||
<!-- disable warning SA1108: Block statements should not contain embedded comments --> | ||
<Rule Id="SA1108" Action="None" /> | ||
<!-- disable warning SA1128:: Put constructor initializers on their own line --> | ||
<Rule Id="SA1128" Action="None" /> | ||
<!-- disable warning SA1130: Use lambda syntax --> | ||
<Rule Id="SA1130" Action="None" /> | ||
<!-- disable warning SA1200: 'using' directive must appear within a namespace declaration --> | ||
<Rule Id="SA1200" Action="None" /> | ||
<!-- disable warning SA1309: Fields must not begin with an underscore --> | ||
<Rule Id="SA1309" Action="None" /> | ||
<!-- disable warning SA1413: Use trailing comma in multi-line initializers --> | ||
<Rule Id="SA1413" Action="None" /> | ||
<!-- disable warning SA1512: Single-line comments must not be followed by blank line --> | ||
<Rule Id="SA1512" Action="None" /> | ||
<!-- disable warning SA1515: Single-line comment should be preceded by blank line --> | ||
<Rule Id="SA1515" Action="None" /> | ||
<!-- disable warning SA1600: Elements should be documented --> | ||
<Rule Id="SA1600" Action="None" /> | ||
<!-- disable warning SA1633: The file header is missing or not located at the top of the file --> | ||
<Rule Id="SA1633" Action="None" /> | ||
</Rules> | ||
|
||
<Rules AnalyzerId="Microsoft.CodeAnalysis.FxCopAnalyzers" RuleNamespace="Microsoft.Design"> | ||
<!-- disable warning CA1031: Do not catch general exception types --> | ||
<Rule Id="CA1031" Action="Info" /> | ||
<!-- disable warning CA1032: Implement standard exception constructors --> | ||
<Rule Id="CA1032" Action="Info" /> | ||
<!-- disable warning CA1062: Validate arguments of public methods --> | ||
<Rule Id="CA1062" Action="Info" /> | ||
<!-- disable warning CA1716: Identifiers should not match keywords --> | ||
<Rule Id="CA1716" Action="Info" /> | ||
<!-- disable warning CA1720: Identifiers should not contain type names --> | ||
<Rule Id="CA1720" Action="Info" /> | ||
<!-- disable warning CA1812: internal class that is apparently never instantiated. | ||
If so, remove the code from the assembly. | ||
If this class is intended to contain only static members, make it static --> | ||
<Rule Id="CA1812" Action="Info" /> | ||
<!-- disable warning CA1822: Member does not access instance data and can be marked as static --> | ||
<Rule Id="CA1822" Action="Info" /> | ||
<!-- disable warning CA2000: Dispose objects before losing scope --> | ||
<Rule Id="CA2000" Action="Info" /> | ||
|
||
<!-- disable warning CA1054: Change the type of parameter url from string to System.Uri --> | ||
<Rule Id="CA1054" Action="None" /> | ||
<!-- disable warning CA1055: URI return values should not be strings --> | ||
<Rule Id="CA1055" Action="None" /> | ||
<!-- disable warning CA1056: URI properties should not be strings --> | ||
<Rule Id="CA1056" Action="None" /> | ||
<!-- disable warning CA1303: Do not pass literals as localized parameters --> | ||
<Rule Id="CA1303" Action="None" /> | ||
<!-- disable warning CA1308: Normalize strings to uppercase --> | ||
<Rule Id="CA1308" Action="None" /> | ||
</Rules> | ||
</RuleSet> |