Clean up folder structure, remove warnings

This commit is contained in:
Cody Robibero 2022-03-19 09:57:50 -06:00
parent ce29d72fa8
commit 7c6692c8b1
38 changed files with 837 additions and 624 deletions

View File

@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>1.2.0.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Jellyfin.Controller" Version="10.*-*"/>
<PackageReference Include="Jellyfin.Model" Version="10.*-*"/>
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
</ItemGroup>
</Project>

16
Jellyfin.Plugin.Vgmdb.sln Normal file
View File

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfin.Plugin.Vgmdb", "Jellyfin.Plugin.Vgmdb\Jellyfin.Plugin.Vgmdb.csproj", "{AEE55B5F-1B35-4155-AFBF-D7586DC39F04}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AEE55B5F-1B35-4155-AFBF-D7586DC39F04}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AEE55B5F-1B35-4155-AFBF-D7586DC39F04}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AEE55B5F-1B35-4155-AFBF-D7586DC39F04}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AEE55B5F-1B35-4155-AFBF-D7586DC39F04}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,23 @@
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
namespace Jellyfin.Plugin.Vgmdb.ExternalIds;
/// <inheritdoc />
// ReSharper disable once ClassNeverInstantiated.Global
public class VgmdbAlbumExternalId : IExternalId
{
public const string ExternalId = "VGMdbAlbum";
public string ProviderName => "VGMdb Album";
public string Key => ExternalId;
public ExternalIdMediaType? Type => ExternalIdMediaType.Album;
public string UrlFormatString => "https://vgmdb.net/album/{0}";
public bool Supports(IHasProviderIds item) => item is MusicAlbum;
}

View File

@ -0,0 +1,23 @@
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
namespace Jellyfin.Plugin.Vgmdb.ExternalIds;
/// <inheritdoc />
// ReSharper disable once ClassNeverInstantiated.Global
public class VgmdbArtistExternalId : IExternalId
{
public const string ExternalId = "VGMdbArtist";
public string ProviderName => "VGMdb Artist";
public string Key => ExternalId;
public ExternalIdMediaType? Type => ExternalIdMediaType.Album;
public string UrlFormatString => "https://vgmdb.net/artist/{0}";
public bool Supports(IHasProviderIds item) => item is MusicArtist;
}

View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>1.0.0.0</Version>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<Nullable>disable</Nullable>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<CodeAnalysisRuleSet>../jellyfin.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Jellyfin.Controller" Version="10.*-*" />
<PackageReference Include="Jellyfin.Model" Version="10.*-*" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.376" PrivateAssets="All" />
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.Json.Serialization;
namespace Jellyfin.Plugin.Vgmdb.Models;
public class AlbumResponse
{
[JsonPropertyName("names")]
public LocalizedString Names { get; set; }
[JsonPropertyName("picture_full")]
public string PictureFull { get; set; }
[JsonPropertyName("picture_small")]
public string PictureSmall { get; set; }
[JsonPropertyName("picture_thumb")]
public string PictureThumb { get; set; }
[JsonPropertyName("link")]
public string Link { get; set; }
[JsonPropertyName("notes")]
public string Notes { get; set; }
[JsonPropertyName("release_date")]
public string ReleaseDate { get; set; }
[JsonPropertyName("categories")]
public IReadOnlyList<string> Categories { get; set; } = Array.Empty<string>();
[JsonPropertyName("organizations")]
public IReadOnlyList<Organization> Organizations { get; set; } = Array.Empty<Organization>();
public int Id => int.Parse(Link.Replace("album/", string.Empty, StringComparison.OrdinalIgnoreCase), CultureInfo.InvariantCulture);
}

View File

@ -0,0 +1,25 @@
using System;
using System.Globalization;
using System.Text.Json.Serialization;
namespace Jellyfin.Plugin.Vgmdb.Models;
public class ArtistResponse
{
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("picture_full")]
public string PictureFull { get; set; }
[JsonPropertyName("picture_small")]
public string PictureSmall { get; set; }
[JsonPropertyName("link")]
public string Link { get; set; }
[JsonPropertyName("notes")]
public string Notes { get; set; }
public int Id => int.Parse(Link.Replace("artist/", string.Empty, StringComparison.OrdinalIgnoreCase), CultureInfo.InvariantCulture);
}

View File

@ -0,0 +1,20 @@
using System.Text.Json.Serialization;
namespace Jellyfin.Plugin.Vgmdb.Models;
public class LocalizedString
{
[JsonPropertyName("en")]
public string En { get; set; }
[JsonPropertyName("ja")]
public string Ja { get; set; }
[JsonPropertyName("jaLatn")]
public string JaLatn { get; set; }
public string GetPreferred()
{
return JaLatn ?? En ?? Ja;
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Globalization;
using System.Text.Json.Serialization;
namespace Jellyfin.Plugin.Vgmdb.Models;
public class Organization
{
[JsonPropertyName("link")]
public string Link { get; set; }
[JsonPropertyName("names")]
public LocalizedString Names { get; set; }
[JsonPropertyName("role")]
public string Role { get; set; }
public int Id => int.Parse(Link.Replace("org/", string.Empty, StringComparison.OrdinalIgnoreCase), CultureInfo.InvariantCulture);
}

View File

@ -0,0 +1,9 @@
using System.Text.Json.Serialization;
namespace Jellyfin.Plugin.Vgmdb.Models;
public class SearchResponse
{
[JsonPropertyName("results")]
public SearchResponseResults Results { get; set; }
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
namespace Jellyfin.Plugin.Vgmdb.Models;
public class SearchResponseResults
{
[JsonPropertyName("albums")]
public IReadOnlyList<SearchResponseResultsAlbum> Albums { get; set; } = Array.Empty<SearchResponseResultsAlbum>();
[JsonPropertyName("artists")]
public IReadOnlyList<SearchResponseResultsArtist> Artists { get; set; } = Array.Empty<SearchResponseResultsArtist>();
}

View File

@ -0,0 +1,22 @@
using System;
using System.Globalization;
using System.Text.Json.Serialization;
namespace Jellyfin.Plugin.Vgmdb.Models;
public class SearchResponseResultsAlbum
{
[JsonPropertyName("catalog")]
public string Catalog { get; set; }
[JsonPropertyName("link")]
public string Link { get; set; }
[JsonPropertyName("release_date")]
public string ReleaseDate { get; set; }
[JsonPropertyName("titles")]
public LocalizedString Titles { get; set; }
public int Id => int.Parse(Link.Replace("album/", string.Empty, StringComparison.OrdinalIgnoreCase), CultureInfo.InvariantCulture);
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.Json.Serialization;
namespace Jellyfin.Plugin.Vgmdb.Models;
public class SearchResponseResultsArtist
{
[JsonPropertyName("aliases")]
public IReadOnlyList<string> Aliases { get; set; } = Array.Empty<string>();
[JsonPropertyName("link")]
public string Link { get; set; }
[JsonPropertyName("names")]
public LocalizedString Names { get; set; }
public int Id => int.Parse(Link.Replace("artist/", string.Empty, StringComparison.OrdinalIgnoreCase), CultureInfo.InvariantCulture);
}

View File

@ -0,0 +1,8 @@
using MediaBrowser.Model.Plugins;
namespace Jellyfin.Plugin.Vgmdb;
/// <inheritdoc />
public class PluginConfiguration : BasePluginConfiguration
{
}

View File

@ -0,0 +1,66 @@
using System.Collections.Generic;
using System.Globalization;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Plugin.Vgmdb.ExternalIds;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
namespace Jellyfin.Plugin.Vgmdb.Providers.Images;
public class VgmdbAlbumImageProvider : IRemoteImageProvider
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly VgmdbApi _api;
public VgmdbAlbumImageProvider(IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory;
_api = new VgmdbApi(httpClientFactory);
}
public string Name => "VGMdb";
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
}
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
var images = new List<RemoteImageInfo>();
var id = item.GetProviderId(VgmdbAlbumExternalId.ExternalId);
// todo use a search to find id
if (id == null)
{
return images;
}
var album = await _api.GetAlbumById(int.Parse(id, CultureInfo.InvariantCulture), cancellationToken).ConfigureAwait(false);
images.Add(new RemoteImageInfo
{
Url = album.PictureFull,
ThumbnailUrl = album.PictureSmall
});
return images;
}
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
{
return new List<ImageType>
{
ImageType.Primary
};
}
public bool Supports(BaseItem item) => item is MusicAlbum;
}

View File

@ -0,0 +1,66 @@
using System.Collections.Generic;
using System.Globalization;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Plugin.Vgmdb.ExternalIds;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
namespace Jellyfin.Plugin.Vgmdb.Providers.Images;
public class VgmdbArtistImageProvider : IRemoteImageProvider
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly VgmdbApi _api;
public VgmdbArtistImageProvider(IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory;
_api = new VgmdbApi(httpClientFactory);
}
public string Name => "VGMdb";
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
}
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
var images = new List<RemoteImageInfo>();
var id = item.GetProviderId(VgmdbArtistExternalId.ExternalId);
// todo use a search to find id
if (id == null)
{
return images;
}
var artist = await _api.GetArtistByIdAsync(int.Parse(id, CultureInfo.InvariantCulture), cancellationToken).ConfigureAwait(false);
images.Add(new RemoteImageInfo
{
Url = artist.PictureFull,
ThumbnailUrl = artist.PictureSmall
});
return images;
}
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
{
return new List<ImageType>
{
ImageType.Primary
};
}
public bool Supports(BaseItem item) => item is MusicArtist;
}

View File

@ -0,0 +1,151 @@
using System.Collections.Generic;
using System.Globalization;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Plugin.Vgmdb.ExternalIds;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
namespace Jellyfin.Plugin.Vgmdb.Providers.Info;
public class VgmdbAlbumProvider : IRemoteMetadataProvider<MusicAlbum, AlbumInfo>
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly VgmdbApi _api;
public VgmdbAlbumProvider(IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory;
_api = new VgmdbApi(httpClientFactory);
}
public string Name => "VGMdb";
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
}
public async Task<MusicAlbum> GetAlbumByIdAsync(int id, CancellationToken cancellationToken)
{
var response = await _api.GetAlbumById(id, cancellationToken).ConfigureAwait(false);
if (response == null)
{
return null;
}
var album = new MusicAlbum
{
ProviderIds =
{
[VgmdbAlbumExternalId.ExternalId] = response.Id.ToString(CultureInfo.InvariantCulture)
},
Name = response.Names.GetPreferred()
};
// todo better date parsing
_ = int.TryParse(response.ReleaseDate.Split('-')[0], out var productionYear);
if (productionYear > 0)
{
album.ProductionYear = productionYear;
}
var image = new ItemImageInfo
{
Path = response.PictureFull,
Type = ImageType.Primary
};
album.SetImage(image, 0);
album.Overview = response.Notes;
if (response.Categories != null)
{
foreach (var category in response.Categories)
{
album.AddGenre(category);
}
}
if (response.Organizations != null)
{
foreach (var organisation in response.Organizations)
{
album.AddStudio(organisation.Names.GetPreferred());
}
}
return album;
}
public async Task<int?> GetIdAsync(AlbumInfo info, CancellationToken cancellationToken)
{
var providedId = info.GetProviderId(VgmdbAlbumExternalId.ExternalId);
if (providedId != null)
{
return int.Parse(providedId, CultureInfo.InvariantCulture);
}
var searchResults = await GetSearchResults(info, cancellationToken).ConfigureAwait(false);
foreach (var result in searchResults)
{
var id = result.GetProviderId(VgmdbAlbumExternalId.ExternalId);
if (id != null)
{
return int.Parse(id, CultureInfo.InvariantCulture);
}
}
return null;
}
public async Task<MetadataResult<MusicAlbum>> GetMetadata(AlbumInfo info, CancellationToken cancellationToken)
{
var id = await GetIdAsync(info, cancellationToken).ConfigureAwait(false);
if (id != null)
{
return new MetadataResult<MusicAlbum>
{
Item = await GetAlbumByIdAsync(id.Value, cancellationToken).ConfigureAwait(false)
};
}
return new MetadataResult<MusicAlbum>();
}
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(AlbumInfo searchInfo, CancellationToken cancellationToken)
{
var response = await _api.GetSearchResultsAsync(searchInfo.Name, cancellationToken).ConfigureAwait(false);
var searchResults = new List<RemoteSearchResult>();
if (response == null)
{
return null;
}
foreach (var albumEntry in response.Results.Albums)
{
var album = await GetAlbumByIdAsync(albumEntry.Id, cancellationToken).ConfigureAwait(false);
var result = new RemoteSearchResult
{
ProviderIds = album.ProviderIds,
Name = album.Name,
ProductionYear = album.ProductionYear,
ImageUrl = album.PrimaryImagePath
};
searchResults.Add(result);
}
return searchResults;
}
}

View File

@ -0,0 +1,127 @@
using System.Collections.Generic;
using System.Globalization;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Plugin.Vgmdb.ExternalIds;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
namespace Jellyfin.Plugin.Vgmdb.Providers.Info;
public class VgmdbArtistProvider : IRemoteMetadataProvider<MusicArtist, ArtistInfo>
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly VgmdbApi _api;
public VgmdbArtistProvider(IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory;
_api = new VgmdbApi(httpClientFactory);
}
public string Name => "VGMdb";
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
}
public async Task<MusicArtist> GetArtistByIdAsync(int id, CancellationToken cancellationToken)
{
var response = await _api.GetArtistByIdAsync(id, cancellationToken).ConfigureAwait(false);
if (response == null)
{
return null;
}
var artist = new MusicArtist
{
ProviderIds =
{
[VgmdbArtistExternalId.ExternalId] = response.Id.ToString(CultureInfo.InvariantCulture)
},
Name = response.Name
};
var image = new ItemImageInfo
{
Path = response.PictureFull,
Type = ImageType.Primary
};
artist.SetImage(image, 0);
artist.Overview = response.Notes;
return artist;
}
public async Task<int?> GetIdAsync(ArtistInfo info, CancellationToken cancellationToken)
{
var providedId = info.GetProviderId(VgmdbArtistExternalId.ExternalId);
if (providedId != null)
{
return int.Parse(providedId, CultureInfo.InvariantCulture);
}
var searchResults = await GetSearchResults(info, cancellationToken).ConfigureAwait(false);
foreach (var result in searchResults)
{
var id = result.GetProviderId(VgmdbArtistExternalId.ExternalId);
if (id != null)
{
return int.Parse(id, CultureInfo.InvariantCulture);
}
}
return null;
}
public async Task<MetadataResult<MusicArtist>> GetMetadata(ArtistInfo info, CancellationToken cancellationToken)
{
var id = await GetIdAsync(info, cancellationToken).ConfigureAwait(false);
if (id != null)
{
return new MetadataResult<MusicArtist>
{
Item = await GetArtistByIdAsync(id.Value, cancellationToken).ConfigureAwait(false)
};
}
return new MetadataResult<MusicArtist>();
}
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(ArtistInfo searchInfo, CancellationToken cancellationToken)
{
var response = await _api.GetSearchResultsAsync(searchInfo.Name, cancellationToken).ConfigureAwait(false);
if (response == null)
{
return null;
}
var searchResults = new List<RemoteSearchResult>();
foreach (var artistEntry in response.Results.Artists)
{
var artist = await GetArtistByIdAsync(artistEntry.Id, cancellationToken).ConfigureAwait(false);
var result = new RemoteSearchResult
{
ProviderIds = artist.ProviderIds,
Name = artist.Name,
ImageUrl = artist.PrimaryImagePath
};
searchResults.Add(result);
}
return searchResults;
}
}

View File

@ -0,0 +1,41 @@
using System.Net;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Plugin.Vgmdb.Models;
using MediaBrowser.Common.Net;
namespace Jellyfin.Plugin.Vgmdb;
public class VgmdbApi
{
private const string RootUrl = @"https://vgmdb.info/";
private readonly IHttpClientFactory _httpClientFactory;
public VgmdbApi(IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory;
}
public async Task<ArtistResponse> GetArtistByIdAsync(int id, CancellationToken cancellationToken)
{
var httpClient = _httpClientFactory.CreateClient(NamedClient.Default);
using var response = await httpClient.GetAsync(RootUrl + "/artist/" + id + "?format=json", cancellationToken).ConfigureAwait(false);
return await response.Content.ReadFromJsonAsync<ArtistResponse>(cancellationToken: cancellationToken).ConfigureAwait(false);
}
public async Task<AlbumResponse> GetAlbumById(int id, CancellationToken cancellationToken)
{
var httpClient = _httpClientFactory.CreateClient(NamedClient.Default);
using var response = await httpClient.GetAsync(RootUrl + "/album/" + id + "?format=json", cancellationToken).ConfigureAwait(false);
return await response.Content.ReadFromJsonAsync<AlbumResponse>(cancellationToken: cancellationToken).ConfigureAwait(false);
}
public async Task<SearchResponse> GetSearchResultsAsync(string name, CancellationToken cancellationToken)
{
var httpClient = _httpClientFactory.CreateClient(NamedClient.Default);
using var response = await httpClient.GetAsync(RootUrl + "/search?format=json&q=" + WebUtility.UrlEncode(name), cancellationToken).ConfigureAwait(false);
return await response.Content.ReadFromJsonAsync<SearchResponse>(cancellationToken: cancellationToken).ConfigureAwait(false);
}
}

View File

@ -0,0 +1,21 @@
using System;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Serialization;
namespace Jellyfin.Plugin.Vgmdb;
/// <inheritdoc />
public class VgmdbPlugin : BasePlugin<PluginConfiguration>
{
public VgmdbPlugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
: base(applicationPaths, xmlSerializer)
{
}
/// <inheritdoc />
public override string Name => "VGMdb";
/// <inheritdoc />
public override Guid Id => Guid.Parse("44616595-5798-47ad-8658-3c09f3030505");
}

108
jellyfin.ruleset Normal file
View File

@ -0,0 +1,108 @@
<?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 SA1009: Closing parenthesis should be followed by a space. -->
<Rule Id="SA1009" Action="None" />
<!-- disable warning SA1011: Closing square bracket should be followed by a space. -->
<Rule Id="SA1011" 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 SA1118: Parameter must not span multiple lines. -->
<Rule Id="SA1118" 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 SA1202: 'public' members must come before 'private' members -->
<Rule Id="SA1202" Action="None" />
<!-- disable warning SA1204: Static members must appear before non-static members -->
<Rule Id="SA1204" 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 SA1602: Enumeration items should be documented -->
<Rule Id="SA1602" 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.NetAnalyzers" RuleNamespace="Microsoft.Design">
<!-- error on CA1305: Specify IFormatProvider -->
<Rule Id="CA1305" Action="Error" />
<!-- error on CA1725: Parameter names should match base declaration -->
<Rule Id="CA1725" Action="Error" />
<!-- error on CA1725: Call async methods when in an async method -->
<Rule Id="CA1727" Action="Error" />
<!-- error on CA1843: Do not use 'WaitAll' with a single task -->
<Rule Id="CA1843" Action="Error" />
<!-- error on CA2016: Forward the CancellationToken parameter to methods that take one
or pass in 'CancellationToken.None' explicitly to indicate intentionally not propagating the token -->
<Rule Id="CA2016" Action="Error" />
<!-- error on CA2254: Template should be a static expression -->
<Rule Id="CA2254" Action="Error" />
<!-- disable warning CA1014: Mark assemblies with CLSCompliantAttribute -->
<Rule Id="CA1014" Action="Info" />
<!-- disable warning CA1024: Use properties where appropriate -->
<Rule Id="CA1024" Action="Info" />
<!-- 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 CA1040: Avoid empty interfaces -->
<Rule Id="CA1040" Action="Info" />
<!-- disable warning CA1062: Validate arguments of public methods -->
<Rule Id="CA1062" Action="Info" />
<!-- TODO: enable when false positives are fixed -->
<!-- disable warning CA1508: Avoid dead conditional code -->
<Rule Id="CA1508" 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 CA1724: Type names should not match namespaces -->
<Rule Id="CA1724" Action="Info" />
<!-- disable warning CA1805: Do not initialize unnecessarily -->
<Rule Id="CA1805" 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 CA2253: Named placeholders should not be numeric values -->
<Rule Id="CA2253" Action="Info" />
<!-- disable warning CA5394: Do not use insecure randomness -->
<Rule Id="CA5394" 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" />
<!-- disable warning CA1848: Use the LoggerMessage delegates -->
<Rule Id="CA1848" Action="None" />
<!-- disable warning CA2101: Specify marshaling for P/Invoke string arguments -->
<Rule Id="CA2101" Action="None" />
<!-- disable warning CA2234: Pass System.Uri objects instead of strings -->
<Rule Id="CA2234" Action="None" />
</Rules>
</RuleSet>

View File

@ -1,24 +0,0 @@
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
namespace Jellyfin.Plugin.Vgmdb.ExternalIds
{
/// <inheritdoc />
// ReSharper disable once ClassNeverInstantiated.Global
public class VgmdbAlbumExternalId : IExternalId
{
public const string ExternalId = "VGMdbAlbum";
public string ProviderName => "VGMdb Album";
public string Key => ExternalId;
public ExternalIdMediaType? Type => ExternalIdMediaType.Album;
public string UrlFormatString => "https://vgmdb.net/album/{0}";
public bool Supports(IHasProviderIds item) => item is MusicAlbum;
}
}

View File

@ -1,24 +0,0 @@
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
namespace Jellyfin.Plugin.Vgmdb.ExternalIds
{
/// <inheritdoc />
// ReSharper disable once ClassNeverInstantiated.Global
public class VgmdbArtistExternalId : IExternalId
{
public const string ExternalId = "VGMdbArtist";
public string ProviderName => "VGMdb Artist";
public string Key => ExternalId;
public ExternalIdMediaType? Type => ExternalIdMediaType.Album;
public string UrlFormatString => "https://vgmdb.net/artist/{0}";
public bool Supports(IHasProviderIds item) => item is MusicArtist;
}
}

View File

@ -1,21 +0,0 @@
using System.Collections.Generic;
namespace Jellyfin.Plugin.Vgmdb.Models
{
public class AlbumResponse
{
public LocalizedString names { get; set; }
public string picture_full { get; set; }
public string picture_small { get; set; }
public string picture_thumb { get; set; }
public string link { get; set; }
public string notes { get; set; }
public string release_date { get; set; }
public List<string> categories { get; set; }
public List<Organisation> organizations { get; set; }
public int Id => int.Parse(link.Replace("album/", ""));
}
}

View File

@ -1,13 +0,0 @@
namespace Jellyfin.Plugin.Vgmdb.Models
{
public class ArtistResponse
{
public string name { get; set; }
public string picture_full { get; set; }
public string picture_small { get; set; }
public string link { get; set; }
public string notes { get; set; }
public int Id => int.Parse(link.Replace("artist/", ""));
}
}

View File

@ -1,14 +0,0 @@
namespace Jellyfin.Plugin.Vgmdb.Models
{
public class LocalizedString
{
public string en { get; set; }
public string ja { get; set; }
public string jaLatn { get; set; }
public string GetPreferred()
{
return jaLatn ?? en ?? ja;
}
}
}

View File

@ -1,11 +0,0 @@
namespace Jellyfin.Plugin.Vgmdb.Models
{
public class Organisation
{
public string link { get; set; }
public LocalizedString names { get; set; }
public string role { get; set; }
public int Id => int.Parse(link.Replace("org/", ""));
}
}

View File

@ -1,7 +0,0 @@
namespace Jellyfin.Plugin.Vgmdb.Models
{
public class SearchResponse
{
public SearchResponseResults results { get; set; }
}
}

View File

@ -1,10 +0,0 @@
using System.Collections.Generic;
namespace Jellyfin.Plugin.Vgmdb.Models
{
public class SearchResponseResults
{
public List<SearchResponseResultsAlbum> albums { get; set; }
public List<SearchResponseResultsArtist> artists { get; set; }
}
}

View File

@ -1,12 +0,0 @@
namespace Jellyfin.Plugin.Vgmdb.Models
{
public class SearchResponseResultsAlbum
{
public string catalog { get; set; }
public string link { get; set; }
public string release_date { get; set; }
public LocalizedString titles { get; set; }
public int Id => int.Parse(link.Replace("album/", ""));
}
}

View File

@ -1,13 +0,0 @@
using System.Collections.Generic;
namespace Jellyfin.Plugin.Vgmdb.Models
{
public class SearchResponseResultsArtist
{
public List<string> aliases { get; set; }
public string link { get; set; }
public LocalizedString names { get; set; }
public int Id => int.Parse(link.Replace("artist/", ""));
}
}

View File

@ -1,19 +0,0 @@
using System;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Serialization;
namespace Jellyfin.Plugin.Vgmdb
{
/// <inheritdoc />
// ReSharper disable once UnusedMember.Global
public class Plugin : BasePlugin<PluginConfiguration>
{
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) : base(applicationPaths, xmlSerializer)
{
}
public override string Name => "VGMdb";
public override Guid Id => Guid.Parse("44616595-5798-47ad-8658-3c09f3030505");
}
}

View File

@ -1,10 +0,0 @@
using MediaBrowser.Model.Plugins;
namespace Jellyfin.Plugin.Vgmdb
{
/// <inheritdoc />
// ReSharper disable once ClassNeverInstantiated.Global
public class PluginConfiguration : BasePluginConfiguration
{
}
}

View File

@ -1,63 +0,0 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Plugin.Vgmdb.ExternalIds;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
namespace Jellyfin.Plugin.Vgmdb.Providers.Images
{
public class VgmdbAlbumImageProvider : IRemoteImageProvider
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly VgmdbApi _api;
public VgmdbAlbumImageProvider(IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory;
_api = new VgmdbApi(httpClientFactory);
}
public string Name => "VGMdb";
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
}
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
var images = new List<RemoteImageInfo>();
var id = item.GetProviderId(VgmdbAlbumExternalId.ExternalId);
//todo use a search to find id
if (id == null) return images;
var album = await _api.GetAlbumById(int.Parse(id), cancellationToken);
images.Add(new RemoteImageInfo
{
Url = album.picture_full,
ThumbnailUrl = album.picture_small
});
return images;
}
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
{
return new List<ImageType>
{
ImageType.Primary
};
}
public bool Supports(BaseItem item) => item is MusicAlbum;
}
}

View File

@ -1,64 +0,0 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Plugin.Vgmdb.ExternalIds;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
namespace Jellyfin.Plugin.Vgmdb.Providers.Images
{
public class VgmdbArtistImageProvider : IRemoteImageProvider
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly VgmdbApi _api;
public VgmdbArtistImageProvider(IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory;
_api = new VgmdbApi(httpClientFactory);
}
public string Name => "VGMdb";
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url);
}
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
var images = new List<RemoteImageInfo>();
var id = item.GetProviderId(VgmdbArtistExternalId.ExternalId);
//todo use a search to find id
if (id == null) return images;
var artist = await _api.GetArtistById(int.Parse(id), cancellationToken);
images.Add(new RemoteImageInfo
{
Url = artist.picture_full,
ThumbnailUrl = artist.picture_small
});
return images;
}
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
{
return new List<ImageType>
{
ImageType.Primary
};
}
public bool Supports(BaseItem item) => item is MusicArtist;
}
}

View File

@ -1,138 +0,0 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Plugin.Vgmdb.ExternalIds;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
namespace Jellyfin.Plugin.Vgmdb.Providers.Info
{
// todo: implement IHasOrder, but find out what it does first
public class VgmdbAlbumProvider : IRemoteMetadataProvider<MusicAlbum, AlbumInfo>
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly VgmdbApi _api;
public VgmdbAlbumProvider(IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory;
_api = new VgmdbApi(httpClientFactory);
}
public string Name => "VGMdb";
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url);
}
public async Task<MusicAlbum> GetAlbumById(int id, CancellationToken cancellationToken)
{
var response = await _api.GetAlbumById(id, cancellationToken);
if (response == null) return null;
var album = new MusicAlbum
{
ProviderIds =
{
[VgmdbAlbumExternalId.ExternalId] = response.Id.ToString()
},
Name = response.names.GetPreferred()
};
//todo better date parsing
int.TryParse(response.release_date.Split('-')[0], out var productionYear);
if (productionYear > 0) album.ProductionYear = productionYear;
var image = new ItemImageInfo
{
Path = response.picture_full,
Type = ImageType.Primary
};
album.SetImage(image, 0);
album.Overview = response.notes;
if (response.categories != null)
{
foreach (var category in response.categories)
{
album.AddGenre(category);
}
}
if (response.organizations != null)
{
foreach (var organisation in response.organizations)
{
album.AddStudio(organisation.names.GetPreferred());
}
}
return album;
}
public async Task<int?> GetId(AlbumInfo info, CancellationToken cancellationToken)
{
var providedId = info.GetProviderId(VgmdbAlbumExternalId.ExternalId);
if (providedId != null) return int.Parse(providedId);
var searchResults = await GetSearchResults(info, cancellationToken);
foreach (var result in searchResults)
{
var id = result.GetProviderId(VgmdbAlbumExternalId.ExternalId);
if (id != null) return int.Parse(id);
}
return null;
}
public async Task<MetadataResult<MusicAlbum>> GetMetadata(AlbumInfo info, CancellationToken cancellationToken)
{
var id = await GetId(info, cancellationToken);
if (id != null)
{
return new MetadataResult<MusicAlbum>
{
Item = await GetAlbumById((int) id, cancellationToken)
};
}
return new MetadataResult<MusicAlbum>();
}
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(AlbumInfo searchInfo, CancellationToken cancellationToken)
{
var response = await _api.GetSearchResults(searchInfo.Name, cancellationToken);
var searchResults = new List<RemoteSearchResult>();
if (response == null) return null;
foreach (var albumEntry in response.results.albums)
{
var album = await GetAlbumById(albumEntry.Id, cancellationToken);
var result = new RemoteSearchResult
{
ProviderIds = album.ProviderIds,
Name = album.Name,
ProductionYear = album.ProductionYear,
ImageUrl = album.PrimaryImagePath
};
searchResults.Add(result);
}
return searchResults;
}
}
}

View File

@ -1,117 +0,0 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Plugin.Vgmdb.ExternalIds;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
namespace Jellyfin.Plugin.Vgmdb.Providers.Info
{
// todo: implement IHasOrder, but find out what it does first
public class VgmdbArtistProvider : IRemoteMetadataProvider<MusicArtist, ArtistInfo>
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly VgmdbApi _api;
public VgmdbArtistProvider(IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory;
_api = new VgmdbApi(httpClientFactory);
}
public string Name => "VGMdb";
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url);
}
public async Task<MusicArtist> GetArtistById(int id, CancellationToken cancellationToken)
{
var response = await _api.GetArtistById(id, cancellationToken);
if (response == null) return null;
var artist = new MusicArtist
{
ProviderIds =
{
[VgmdbArtistExternalId.ExternalId] = response.Id.ToString()
},
Name = response.name
};
var image = new ItemImageInfo
{
Path = response.picture_full,
Type = ImageType.Primary
};
artist.SetImage(image, 0);
artist.Overview = response.notes;
return artist;
}
public async Task<int?> GetId(ArtistInfo info, CancellationToken cancellationToken)
{
var providedId = info.GetProviderId(VgmdbArtistExternalId.ExternalId);
if (providedId != null) return int.Parse(providedId);
var searchResults = await GetSearchResults(info, cancellationToken);
foreach (var result in searchResults)
{
var id = result.GetProviderId(VgmdbArtistExternalId.ExternalId);
if (id != null) return int.Parse(id);
}
return null;
}
public async Task<MetadataResult<MusicArtist>> GetMetadata(ArtistInfo info, CancellationToken cancellationToken)
{
var id = await GetId(info, cancellationToken);
if (id != null)
{
return new MetadataResult<MusicArtist>
{
Item = await GetArtistById((int) id, cancellationToken)
};
}
return new MetadataResult<MusicArtist>();
}
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(ArtistInfo searchInfo, CancellationToken cancellationToken)
{
var response = await _api.GetSearchResults(searchInfo.Name, cancellationToken);
var searchResults = new List<RemoteSearchResult>();
if (response == null) return null;
foreach (var artistEntry in response.results.artists)
{
var artist = await GetArtistById(artistEntry.Id, cancellationToken);
var result = new RemoteSearchResult
{
ProviderIds = artist.ProviderIds,
Name = artist.Name,
ImageUrl = artist.PrimaryImagePath
};
searchResults.Add(result);
}
return searchResults;
}
}
}

View File

@ -1,52 +0,0 @@
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Plugin.Vgmdb.Models;
using MediaBrowser.Common.Net;
using MediaBrowser.Model.Serialization;
namespace Jellyfin.Plugin.Vgmdb
{
public class VgmdbApi
{
private readonly IHttpClientFactory _httpClientFactory;
private const string RootUrl = @"https://vgmdb.info/";
public VgmdbApi(IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory;
}
public async Task<ArtistResponse> GetArtistById(int id, CancellationToken cancellationToken)
{
var httpClient = _httpClientFactory.CreateClient(NamedClient.Default);
using (var response = await httpClient.GetAsync(RootUrl + "/artist/" + id + "?format=json", cancellationToken).ConfigureAwait(false))
{
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializer.DeserializeAsync<ArtistResponse>(stream).ConfigureAwait(false);
}
}
public async Task<AlbumResponse> GetAlbumById(int id, CancellationToken cancellationToken)
{
var httpClient = _httpClientFactory.CreateClient(NamedClient.Default);
using (var response = await httpClient.GetAsync(RootUrl + "/album/" + id + "?format=json", cancellationToken).ConfigureAwait(false))
{
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializer.DeserializeAsync<AlbumResponse>(stream).ConfigureAwait(false);
}
}
public async Task<SearchResponse> GetSearchResults(string name, CancellationToken cancellationToken)
{
var httpClient = _httpClientFactory.CreateClient(NamedClient.Default);
using (var response = await httpClient.GetAsync(RootUrl + "/search?format=json&q=" + WebUtility.UrlEncode(name), cancellationToken).ConfigureAwait(false))
{
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializer.DeserializeAsync<SearchResponse>(stream).ConfigureAwait(false);
}
}
}
}