Fix MusicBrainz configuration parsing and update
This commit is contained in:
parent
2f4e43b87f
commit
4baa534679
|
@ -8,8 +8,10 @@ using Jellyfin.Extensions;
|
||||||
using MediaBrowser.Controller.Entities.Audio;
|
using MediaBrowser.Controller.Entities.Audio;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
using MediaBrowser.Model.Plugins;
|
||||||
using MediaBrowser.Model.Providers;
|
using MediaBrowser.Model.Providers;
|
||||||
using MediaBrowser.Providers.Music;
|
using MediaBrowser.Providers.Music;
|
||||||
|
using MediaBrowser.Providers.Plugins.MusicBrainz.Configuration;
|
||||||
using MetaBrainz.MusicBrainz;
|
using MetaBrainz.MusicBrainz;
|
||||||
using MetaBrainz.MusicBrainz.Interfaces.Entities;
|
using MetaBrainz.MusicBrainz.Interfaces.Entities;
|
||||||
using MetaBrainz.MusicBrainz.Interfaces.Searches;
|
using MetaBrainz.MusicBrainz.Interfaces.Searches;
|
||||||
|
@ -23,8 +25,7 @@ namespace MediaBrowser.Providers.Plugins.MusicBrainz;
|
||||||
public class MusicBrainzAlbumProvider : IRemoteMetadataProvider<MusicAlbum, AlbumInfo>, IHasOrder, IDisposable
|
public class MusicBrainzAlbumProvider : IRemoteMetadataProvider<MusicAlbum, AlbumInfo>, IHasOrder, IDisposable
|
||||||
{
|
{
|
||||||
private readonly ILogger<MusicBrainzAlbumProvider> _logger;
|
private readonly ILogger<MusicBrainzAlbumProvider> _logger;
|
||||||
private readonly Query _musicBrainzQuery;
|
private Query _musicBrainzQuery;
|
||||||
private readonly string _musicBrainzDefaultUri = "https://musicbrainz.org";
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="MusicBrainzAlbumProvider"/> class.
|
/// Initializes a new instance of the <see cref="MusicBrainzAlbumProvider"/> class.
|
||||||
|
@ -33,29 +34,9 @@ public class MusicBrainzAlbumProvider : IRemoteMetadataProvider<MusicAlbum, Albu
|
||||||
public MusicBrainzAlbumProvider(ILogger<MusicBrainzAlbumProvider> logger)
|
public MusicBrainzAlbumProvider(ILogger<MusicBrainzAlbumProvider> logger)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
MusicBrainz.Plugin.Instance!.ConfigurationChanged += (_, _) =>
|
|
||||||
{
|
|
||||||
if (Uri.TryCreate(MusicBrainz.Plugin.Instance.Configuration.Server, UriKind.Absolute, out var server))
|
|
||||||
{
|
|
||||||
Query.DefaultServer = server.Host;
|
|
||||||
Query.DefaultPort = server.Port;
|
|
||||||
Query.DefaultUrlScheme = server.Scheme;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Fallback to official server
|
|
||||||
_logger.LogWarning("Invalid MusicBrainz server specified, falling back to official server");
|
|
||||||
var defaultServer = new Uri(_musicBrainzDefaultUri);
|
|
||||||
Query.DefaultServer = defaultServer.Host;
|
|
||||||
Query.DefaultPort = defaultServer.Port;
|
|
||||||
Query.DefaultUrlScheme = defaultServer.Scheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
Query.DelayBetweenRequests = MusicBrainz.Plugin.Instance.Configuration.RateLimit;
|
|
||||||
};
|
|
||||||
|
|
||||||
_musicBrainzQuery = new Query();
|
_musicBrainzQuery = new Query();
|
||||||
|
ReloadConfig(null, MusicBrainz.Plugin.Instance!.Configuration);
|
||||||
|
MusicBrainz.Plugin.Instance!.ConfigurationChanged += ReloadConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@ -64,6 +45,29 @@ public class MusicBrainzAlbumProvider : IRemoteMetadataProvider<MusicAlbum, Albu
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public int Order => 0;
|
public int Order => 0;
|
||||||
|
|
||||||
|
private void ReloadConfig(object? sender, BasePluginConfiguration e)
|
||||||
|
{
|
||||||
|
var configuration = (PluginConfiguration)e;
|
||||||
|
if (Uri.TryCreate(configuration.Server, UriKind.Absolute, out var server))
|
||||||
|
{
|
||||||
|
Query.DefaultServer = server.DnsSafeHost;
|
||||||
|
Query.DefaultPort = server.Port;
|
||||||
|
Query.DefaultUrlScheme = server.Scheme;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Fallback to official server
|
||||||
|
_logger.LogWarning("Invalid MusicBrainz server specified, falling back to official server");
|
||||||
|
var defaultServer = new Uri(configuration.Server);
|
||||||
|
Query.DefaultServer = defaultServer.Host;
|
||||||
|
Query.DefaultPort = defaultServer.Port;
|
||||||
|
Query.DefaultUrlScheme = defaultServer.Scheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
Query.DelayBetweenRequests = configuration.RateLimit;
|
||||||
|
_musicBrainzQuery = new Query();
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(AlbumInfo searchInfo, CancellationToken cancellationToken)
|
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(AlbumInfo searchInfo, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,8 +8,10 @@ using Jellyfin.Extensions;
|
||||||
using MediaBrowser.Controller.Entities.Audio;
|
using MediaBrowser.Controller.Entities.Audio;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
using MediaBrowser.Model.Plugins;
|
||||||
using MediaBrowser.Model.Providers;
|
using MediaBrowser.Model.Providers;
|
||||||
using MediaBrowser.Providers.Music;
|
using MediaBrowser.Providers.Music;
|
||||||
|
using MediaBrowser.Providers.Plugins.MusicBrainz.Configuration;
|
||||||
using MetaBrainz.MusicBrainz;
|
using MetaBrainz.MusicBrainz;
|
||||||
using MetaBrainz.MusicBrainz.Interfaces.Entities;
|
using MetaBrainz.MusicBrainz.Interfaces.Entities;
|
||||||
using MetaBrainz.MusicBrainz.Interfaces.Searches;
|
using MetaBrainz.MusicBrainz.Interfaces.Searches;
|
||||||
|
@ -23,8 +25,7 @@ namespace MediaBrowser.Providers.Plugins.MusicBrainz;
|
||||||
public class MusicBrainzArtistProvider : IRemoteMetadataProvider<MusicArtist, ArtistInfo>, IDisposable
|
public class MusicBrainzArtistProvider : IRemoteMetadataProvider<MusicArtist, ArtistInfo>, IDisposable
|
||||||
{
|
{
|
||||||
private readonly ILogger<MusicBrainzArtistProvider> _logger;
|
private readonly ILogger<MusicBrainzArtistProvider> _logger;
|
||||||
private readonly Query _musicBrainzQuery;
|
private Query _musicBrainzQuery;
|
||||||
private readonly string _musicBrainzDefaultUri = "https://musicbrainz.org";
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="MusicBrainzArtistProvider"/> class.
|
/// Initializes a new instance of the <see cref="MusicBrainzArtistProvider"/> class.
|
||||||
|
@ -33,34 +34,37 @@ public class MusicBrainzArtistProvider : IRemoteMetadataProvider<MusicArtist, Ar
|
||||||
public MusicBrainzArtistProvider(ILogger<MusicBrainzArtistProvider> logger)
|
public MusicBrainzArtistProvider(ILogger<MusicBrainzArtistProvider> logger)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
MusicBrainz.Plugin.Instance!.ConfigurationChanged += (_, _) =>
|
|
||||||
{
|
|
||||||
if (Uri.TryCreate(MusicBrainz.Plugin.Instance.Configuration.Server, UriKind.Absolute, out var server))
|
|
||||||
{
|
|
||||||
Query.DefaultServer = server.Host;
|
|
||||||
Query.DefaultPort = server.Port;
|
|
||||||
Query.DefaultUrlScheme = server.Scheme;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Fallback to official server
|
|
||||||
_logger.LogWarning("Invalid MusicBrainz server specified, falling back to official server");
|
|
||||||
var defaultServer = new Uri(_musicBrainzDefaultUri);
|
|
||||||
Query.DefaultServer = defaultServer.Host;
|
|
||||||
Query.DefaultPort = defaultServer.Port;
|
|
||||||
Query.DefaultUrlScheme = defaultServer.Scheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
Query.DelayBetweenRequests = MusicBrainz.Plugin.Instance.Configuration.RateLimit;
|
|
||||||
};
|
|
||||||
|
|
||||||
_musicBrainzQuery = new Query();
|
_musicBrainzQuery = new Query();
|
||||||
|
ReloadConfig(null, MusicBrainz.Plugin.Instance!.Configuration);
|
||||||
|
MusicBrainz.Plugin.Instance!.ConfigurationChanged += ReloadConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Name => "MusicBrainz";
|
public string Name => "MusicBrainz";
|
||||||
|
|
||||||
|
private void ReloadConfig(object? sender, BasePluginConfiguration e)
|
||||||
|
{
|
||||||
|
var configuration = (PluginConfiguration)e;
|
||||||
|
if (Uri.TryCreate(configuration.Server, UriKind.Absolute, out var server))
|
||||||
|
{
|
||||||
|
Query.DefaultServer = server.DnsSafeHost;
|
||||||
|
Query.DefaultPort = server.Port;
|
||||||
|
Query.DefaultUrlScheme = server.Scheme;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Fallback to official server
|
||||||
|
_logger.LogWarning("Invalid MusicBrainz server specified, falling back to official server");
|
||||||
|
var defaultServer = new Uri(configuration.Server);
|
||||||
|
Query.DefaultServer = defaultServer.Host;
|
||||||
|
Query.DefaultPort = defaultServer.Port;
|
||||||
|
Query.DefaultUrlScheme = defaultServer.Scheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
Query.DelayBetweenRequests = configuration.RateLimit;
|
||||||
|
_musicBrainzQuery = new Query();
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(ArtistInfo searchInfo, CancellationToken cancellationToken)
|
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(ArtistInfo searchInfo, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user