mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Add migration for MusicBrainz settings
This commit is contained in:
parent
6eb35d4fd3
commit
2f4e43b87f
@ -21,7 +21,8 @@ namespace Jellyfin.Server.Migrations
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static readonly Type[] _preStartupMigrationTypes =
|
private static readonly Type[] _preStartupMigrationTypes =
|
||||||
{
|
{
|
||||||
typeof(PreStartupRoutines.CreateNetworkConfiguration)
|
typeof(PreStartupRoutines.CreateNetworkConfiguration),
|
||||||
|
typeof(PreStartupRoutines.MigrateMusicBrainzTimeout)
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -0,0 +1,89 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Xml;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
using Emby.Server.Implementations;
|
||||||
|
using MediaBrowser.Providers.Plugins.MusicBrainz.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace Jellyfin.Server.Migrations.PreStartupRoutines;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public class MigrateMusicBrainzTimeout : IMigrationRoutine
|
||||||
|
{
|
||||||
|
private readonly ServerApplicationPaths _applicationPaths;
|
||||||
|
private readonly ILogger<MigrateMusicBrainzTimeout> _logger;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="MigrateMusicBrainzTimeout"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="applicationPaths">An instance of <see cref="ServerApplicationPaths"/>.</param>
|
||||||
|
/// <param name="loggerFactory">An instance of the <see cref="ILoggerFactory"/> interface.</param>
|
||||||
|
public MigrateMusicBrainzTimeout(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory)
|
||||||
|
{
|
||||||
|
_applicationPaths = applicationPaths;
|
||||||
|
_logger = loggerFactory.CreateLogger<MigrateMusicBrainzTimeout>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Guid Id => Guid.Parse("A6DCACF4-C057-4Ef9-80D3-61CEF9DDB4F0");
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string Name => nameof(MigrateMusicBrainzTimeout);
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool PerformOnNewInstall => false;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Perform()
|
||||||
|
{
|
||||||
|
string path = Path.Combine(_applicationPaths.PluginConfigurationsPath, "Jellyfin.Plugin.MusicBrainz.xml");
|
||||||
|
if (!File.Exists(path))
|
||||||
|
{
|
||||||
|
_logger.LogDebug("No MusicBrainz plugin configuration file found, skipping");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var serverConfigSerializer = new XmlSerializer(typeof(OldMusicBrainzConfiguration), new XmlRootAttribute("PluginConfiguration"));
|
||||||
|
using var xmlReader = XmlReader.Create(path);
|
||||||
|
var oldPluginConfiguration = serverConfigSerializer.Deserialize(xmlReader) as OldMusicBrainzConfiguration;
|
||||||
|
|
||||||
|
if (oldPluginConfiguration is not null)
|
||||||
|
{
|
||||||
|
var newPluginConfiguration = new PluginConfiguration();
|
||||||
|
newPluginConfiguration.Server = oldPluginConfiguration.Server;
|
||||||
|
newPluginConfiguration.ReplaceArtistName = oldPluginConfiguration.ReplaceArtistName;
|
||||||
|
var newRateLimit = oldPluginConfiguration.RateLimit / 1000.0;
|
||||||
|
newPluginConfiguration.RateLimit = newRateLimit < 1.0 ? 1.0 : newRateLimit;
|
||||||
|
|
||||||
|
var pluginConfigurationSerializer = new XmlSerializer(typeof(PluginConfiguration), new XmlRootAttribute("PluginConfiguration"));
|
||||||
|
var xmlWriterSettings = new XmlWriterSettings { Indent = true };
|
||||||
|
using var xmlWriter = XmlWriter.Create(path, xmlWriterSettings);
|
||||||
|
pluginConfigurationSerializer.Serialize(xmlWriter, newPluginConfiguration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma warning disable
|
||||||
|
public sealed class OldMusicBrainzConfiguration
|
||||||
|
{
|
||||||
|
private string _server = string.Empty;
|
||||||
|
|
||||||
|
private long _rateLimit = 0L;
|
||||||
|
|
||||||
|
public string Server
|
||||||
|
{
|
||||||
|
get => _server;
|
||||||
|
set => _server = value.TrimEnd('/');
|
||||||
|
}
|
||||||
|
|
||||||
|
public long RateLimit
|
||||||
|
{
|
||||||
|
get => _rateLimit;
|
||||||
|
set => _rateLimit = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ReplaceArtistName { get; set; }
|
||||||
|
}
|
||||||
|
#pragma warning restore
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,4 @@
|
|||||||
using MediaBrowser.Model.Plugins;
|
using MediaBrowser.Model.Plugins;
|
||||||
using MetaBrainz.MusicBrainz;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Providers.Plugins.MusicBrainz.Configuration;
|
namespace MediaBrowser.Providers.Plugins.MusicBrainz.Configuration;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user