Apply review suggestions
This commit is contained in:
parent
7ad0c9ba24
commit
385f1cc1b8
|
@ -23,11 +23,7 @@ public class PluginConfiguration : BasePluginConfiguration
|
||||||
{
|
{
|
||||||
get => _server;
|
get => _server;
|
||||||
|
|
||||||
set
|
set => _server = value.TrimEnd('/');
|
||||||
{
|
|
||||||
_server = value.TrimEnd('/');
|
|
||||||
Query.DefaultServer = _server;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -46,8 +42,6 @@ public class PluginConfiguration : BasePluginConfiguration
|
||||||
{
|
{
|
||||||
_rateLimit = value;
|
_rateLimit = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Query.DelayBetweenRequests = _rateLimit;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,12 @@ public class MusicBrainzAlbumProvider : IRemoteMetadataProvider<MusicAlbum, Albu
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MusicBrainzAlbumProvider()
|
public MusicBrainzAlbumProvider()
|
||||||
{
|
{
|
||||||
|
MusicBrainz.Plugin.Instance!.ConfigurationChanged += (_, _) =>
|
||||||
|
{
|
||||||
|
Query.DefaultServer = MusicBrainz.Plugin.Instance.Configuration.Server;
|
||||||
|
Query.DelayBetweenRequests = MusicBrainz.Plugin.Instance.Configuration.RateLimit;
|
||||||
|
};
|
||||||
|
|
||||||
_musicBrainzQuery = new Query();
|
_musicBrainzQuery = new Query();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,14 +51,14 @@ public class MusicBrainzAlbumProvider : IRemoteMetadataProvider<MusicAlbum, Albu
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(releaseId))
|
if (!string.IsNullOrEmpty(releaseId))
|
||||||
{
|
{
|
||||||
var releaseResult = await _musicBrainzQuery.LookupReleaseAsync(new Guid(releaseId), Include.Releases, cancellationToken).ConfigureAwait(false);
|
var releaseResult = await _musicBrainzQuery.LookupReleaseAsync(new Guid(releaseId), Include.ReleaseGroups, cancellationToken).ConfigureAwait(false);
|
||||||
return GetResultFromResponse(releaseResult).SingleItemAsEnumerable();
|
return GetReleaseResult(releaseResult).SingleItemAsEnumerable();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(releaseGroupId))
|
if (!string.IsNullOrEmpty(releaseGroupId))
|
||||||
{
|
{
|
||||||
var releaseGroupResult = await _musicBrainzQuery.LookupReleaseGroupAsync(new Guid(releaseGroupId), Include.ReleaseGroups, null, cancellationToken).ConfigureAwait(false);
|
var releaseGroupResult = await _musicBrainzQuery.LookupReleaseGroupAsync(new Guid(releaseGroupId), Include.None, null, cancellationToken).ConfigureAwait(false);
|
||||||
return GetResultsFromResponse(releaseGroupResult.Releases);
|
return GetReleaseGroupResult(releaseGroupResult.Releases);
|
||||||
}
|
}
|
||||||
|
|
||||||
var artistMusicBrainzId = searchInfo.GetMusicBrainzArtistId();
|
var artistMusicBrainzId = searchInfo.GetMusicBrainzArtistId();
|
||||||
|
@ -64,7 +70,7 @@ public class MusicBrainzAlbumProvider : IRemoteMetadataProvider<MusicAlbum, Albu
|
||||||
|
|
||||||
if (releaseSearchResults.Results.Count > 0)
|
if (releaseSearchResults.Results.Count > 0)
|
||||||
{
|
{
|
||||||
return GetResultsFromResponse(releaseSearchResults.Results);
|
return GetReleaseSearchResult(releaseSearchResults.Results);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -77,14 +83,14 @@ public class MusicBrainzAlbumProvider : IRemoteMetadataProvider<MusicAlbum, Albu
|
||||||
|
|
||||||
if (releaseSearchResults.Results.Count > 0)
|
if (releaseSearchResults.Results.Count > 0)
|
||||||
{
|
{
|
||||||
return GetResultsFromResponse(releaseSearchResults.Results);
|
return GetReleaseSearchResult(releaseSearchResults.Results);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Enumerable.Empty<RemoteSearchResult>();
|
return Enumerable.Empty<RemoteSearchResult>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<RemoteSearchResult> GetResultsFromResponse(IEnumerable<ISearchResult<IRelease>>? releaseSearchResults)
|
private IEnumerable<RemoteSearchResult> GetReleaseSearchResult(IEnumerable<ISearchResult<IRelease>>? releaseSearchResults)
|
||||||
{
|
{
|
||||||
if (releaseSearchResults is null)
|
if (releaseSearchResults is null)
|
||||||
{
|
{
|
||||||
|
@ -93,11 +99,11 @@ public class MusicBrainzAlbumProvider : IRemoteMetadataProvider<MusicAlbum, Albu
|
||||||
|
|
||||||
foreach (var result in releaseSearchResults)
|
foreach (var result in releaseSearchResults)
|
||||||
{
|
{
|
||||||
yield return GetResultFromResponse(result.Item);
|
yield return GetReleaseResult(result.Item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<RemoteSearchResult> GetResultsFromResponse(IEnumerable<IRelease>? releaseSearchResults)
|
private IEnumerable<RemoteSearchResult> GetReleaseGroupResult(IEnumerable<IRelease>? releaseSearchResults)
|
||||||
{
|
{
|
||||||
if (releaseSearchResults is null)
|
if (releaseSearchResults is null)
|
||||||
{
|
{
|
||||||
|
@ -106,11 +112,11 @@ public class MusicBrainzAlbumProvider : IRemoteMetadataProvider<MusicAlbum, Albu
|
||||||
|
|
||||||
foreach (var result in releaseSearchResults)
|
foreach (var result in releaseSearchResults)
|
||||||
{
|
{
|
||||||
yield return GetResultFromResponse(result);
|
yield return GetReleaseResult(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private RemoteSearchResult GetResultFromResponse(IRelease releaseSearchResult)
|
private RemoteSearchResult GetReleaseResult(IRelease releaseSearchResult)
|
||||||
{
|
{
|
||||||
var searchResult = new RemoteSearchResult
|
var searchResult = new RemoteSearchResult
|
||||||
{
|
{
|
||||||
|
@ -159,11 +165,14 @@ public class MusicBrainzAlbumProvider : IRemoteMetadataProvider<MusicAlbum, Albu
|
||||||
if (string.IsNullOrWhiteSpace(releaseId) && !string.IsNullOrWhiteSpace(releaseGroupId))
|
if (string.IsNullOrWhiteSpace(releaseId) && !string.IsNullOrWhiteSpace(releaseGroupId))
|
||||||
{
|
{
|
||||||
// TODO: Actually try to match the release. Simply taking the first result is stupid.
|
// TODO: Actually try to match the release. Simply taking the first result is stupid.
|
||||||
var releaseGroup = await _musicBrainzQuery.LookupReleaseGroupAsync(new Guid(releaseGroupId), Include.ReleaseGroups, null, cancellationToken).ConfigureAwait(false);
|
var releaseGroup = await _musicBrainzQuery.LookupReleaseGroupAsync(new Guid(releaseGroupId), Include.None, null, cancellationToken).ConfigureAwait(false);
|
||||||
var release = releaseGroup.Releases?.Count > 0 ? releaseGroup.Releases[0] : null;
|
var release = releaseGroup.Releases?.Count > 0 ? releaseGroup.Releases[0] : null;
|
||||||
releaseId = release?.Id.ToString();
|
if (release != null)
|
||||||
|
{
|
||||||
|
releaseId = release.Id.ToString();
|
||||||
result.HasMetadata = true;
|
result.HasMetadata = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If there is no release ID, lookup a release with the info we have
|
// If there is no release ID, lookup a release with the info we have
|
||||||
if (string.IsNullOrWhiteSpace(releaseId))
|
if (string.IsNullOrWhiteSpace(releaseId))
|
||||||
|
|
|
@ -6,7 +6,7 @@ using MediaBrowser.Model.Providers;
|
||||||
namespace MediaBrowser.Providers.Plugins.MusicBrainz;
|
namespace MediaBrowser.Providers.Plugins.MusicBrainz;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// MusicBrains Artist ExternalId.
|
/// MusicBrainz artist external id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MusicBrainzArtistExternalId : IExternalId
|
public class MusicBrainzArtistExternalId : IExternalId
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,6 +29,12 @@ public class MusicBrainzArtistProvider : IRemoteMetadataProvider<MusicArtist, Ar
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MusicBrainzArtistProvider()
|
public MusicBrainzArtistProvider()
|
||||||
{
|
{
|
||||||
|
MusicBrainz.Plugin.Instance!.ConfigurationChanged += (_, _) =>
|
||||||
|
{
|
||||||
|
Query.DefaultServer = MusicBrainz.Plugin.Instance.Configuration.Server;
|
||||||
|
Query.DelayBetweenRequests = MusicBrainz.Plugin.Instance.Configuration.RateLimit;
|
||||||
|
};
|
||||||
|
|
||||||
_musicBrainzQuery = new Query();
|
_musicBrainzQuery = new Query();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +48,7 @@ public class MusicBrainzArtistProvider : IRemoteMetadataProvider<MusicArtist, Ar
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(artistId))
|
if (!string.IsNullOrWhiteSpace(artistId))
|
||||||
{
|
{
|
||||||
var artistResult = await _musicBrainzQuery.LookupArtistAsync(new Guid(artistId), Include.Artists, null, null, cancellationToken).ConfigureAwait(false);
|
var artistResult = await _musicBrainzQuery.LookupArtistAsync(new Guid(artistId), Include.Aliases, null, null, cancellationToken).ConfigureAwait(false);
|
||||||
return GetResultFromResponse(artistResult).SingleItemAsEnumerable();
|
return GetResultFromResponse(artistResult).SingleItemAsEnumerable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,19 +86,6 @@ public class MusicBrainzArtistProvider : IRemoteMetadataProvider<MusicArtist, Ar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<RemoteSearchResult> GetResultsFromResponse(IEnumerable<IArtist>? releaseSearchResults)
|
|
||||||
{
|
|
||||||
if (releaseSearchResults is null)
|
|
||||||
{
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var result in releaseSearchResults)
|
|
||||||
{
|
|
||||||
yield return GetResultFromResponse(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private RemoteSearchResult GetResultFromResponse(IArtist artist)
|
private RemoteSearchResult GetResultFromResponse(IArtist artist)
|
||||||
{
|
{
|
||||||
var searchResult = new RemoteSearchResult
|
var searchResult = new RemoteSearchResult
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Reflection;
|
using MediaBrowser.Common;
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Common.Plugins;
|
using MediaBrowser.Common.Plugins;
|
||||||
using MediaBrowser.Model.Plugins;
|
using MediaBrowser.Model.Plugins;
|
||||||
|
@ -21,14 +21,15 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="applicationPaths">Instance of the <see cref="IApplicationPaths"/> interface.</param>
|
/// <param name="applicationPaths">Instance of the <see cref="IApplicationPaths"/> interface.</param>
|
||||||
/// <param name="xmlSerializer">Instance of the <see cref="IXmlSerializer"/> interface.</param>
|
/// <param name="xmlSerializer">Instance of the <see cref="IXmlSerializer"/> interface.</param>
|
||||||
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
|
/// <param name="applicationHost">Instance of the <see cref="IApplicationHost"/> interface.</param>
|
||||||
|
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, IApplicationHost applicationHost)
|
||||||
: base(applicationPaths, xmlSerializer)
|
: base(applicationPaths, xmlSerializer)
|
||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
|
|
||||||
// TODO: Change this to "JellyfinMusicBrainzPlugin" once we take it out of the server repo.
|
// TODO: Change this to "JellyfinMusicBrainzPlugin" once we take it out of the server repo.
|
||||||
Query.DefaultUserAgent.Add(new ProductInfoHeaderValue("Jellyfin", Assembly.GetExecutingAssembly().GetName().Version?.ToString(3)));
|
Query.DefaultUserAgent.Add(new ProductInfoHeaderValue(applicationHost.Name.Replace(' ', '-'), applicationHost.ApplicationVersionString));
|
||||||
Query.DefaultUserAgent.Add(new ProductInfoHeaderValue("(apps@jellyfin.org)"));
|
Query.DefaultUserAgent.Add(new ProductInfoHeaderValue($"({applicationHost.ApplicationUserAgentAddress})"));
|
||||||
Query.DelayBetweenRequests = Instance.Configuration.RateLimit;
|
Query.DelayBetweenRequests = Instance.Configuration.RateLimit;
|
||||||
Query.DefaultServer = Instance.Configuration.Server;
|
Query.DefaultServer = Instance.Configuration.Server;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user