< Summary - Jellyfin

Information
Class: Jellyfin.Server.Migrations.PreStartupRoutines.MigrateMusicBrainzTimeout
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateMusicBrainzTimeout.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 32
Coverable lines: 32
Total lines: 92
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
Perform()0%4260%
ReadOld(...)100%210%
WriteNew(...)100%210%
.ctor()100%210%
get_Server()100%210%
set_Server(...)100%210%
get_RateLimit()100%210%
set_RateLimit(...)100%210%

File(s)

/srv/git/jellyfin/Jellyfin.Server/Migrations/PreStartupRoutines/MigrateMusicBrainzTimeout.cs

#LineLine coverage
 1using System;
 2using System.IO;
 3using System.Xml;
 4using System.Xml.Serialization;
 5using Emby.Server.Implementations;
 6using MediaBrowser.Providers.Plugins.MusicBrainz.Configuration;
 7using Microsoft.Extensions.Logging;
 8
 9namespace Jellyfin.Server.Migrations.PreStartupRoutines;
 10
 11/// <inheritdoc />
 12#pragma warning disable CS0618 // Type or member is obsolete
 13[JellyfinMigration("2025-04-20T02:00:00", nameof(MigrateMusicBrainzTimeout), "A6DCACF4-C057-4Ef9-80D3-61CEF9DDB4F0", Sta
 14public class MigrateMusicBrainzTimeout : IMigrationRoutine
 15#pragma warning restore CS0618 // Type or member is obsolete
 16{
 17    private readonly ServerApplicationPaths _applicationPaths;
 18    private readonly ILogger<MigrateMusicBrainzTimeout> _logger;
 19
 20    /// <summary>
 21    /// Initializes a new instance of the <see cref="MigrateMusicBrainzTimeout"/> class.
 22    /// </summary>
 23    /// <param name="applicationPaths">An instance of <see cref="ServerApplicationPaths"/>.</param>
 24    /// <param name="loggerFactory">An instance of the <see cref="ILoggerFactory"/> interface.</param>
 25    public MigrateMusicBrainzTimeout(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory)
 26    {
 027        _applicationPaths = applicationPaths;
 028        _logger = loggerFactory.CreateLogger<MigrateMusicBrainzTimeout>();
 029    }
 30
 31    /// <inheritdoc />
 32    public void Perform()
 33    {
 034        string path = Path.Combine(_applicationPaths.PluginConfigurationsPath, "Jellyfin.Plugin.MusicBrainz.xml");
 035        if (!File.Exists(path))
 36        {
 037            _logger.LogDebug("No MusicBrainz plugin configuration file found, skipping");
 038            return;
 39        }
 40
 041        var oldPluginConfiguration = ReadOld(path);
 42
 043        if (oldPluginConfiguration is not null)
 44        {
 045            var newPluginConfiguration = new PluginConfiguration
 046            {
 047                Server = oldPluginConfiguration.Server,
 048                ReplaceArtistName = oldPluginConfiguration.ReplaceArtistName
 049            };
 050            var newRateLimit = oldPluginConfiguration.RateLimit / 1000.0;
 051            newPluginConfiguration.RateLimit = newRateLimit < 1.0 ? 1.0 : newRateLimit;
 052            WriteNew(path, newPluginConfiguration);
 53        }
 054    }
 55
 56    private OldMusicBrainzConfiguration? ReadOld(string path)
 57    {
 058        using var xmlReader = XmlReader.Create(path);
 059        var serverConfigSerializer = new XmlSerializer(typeof(OldMusicBrainzConfiguration), new XmlRootAttribute("Plugin
 060        return serverConfigSerializer.Deserialize(xmlReader) as OldMusicBrainzConfiguration;
 061    }
 62
 63    private void WriteNew(string path, PluginConfiguration newPluginConfiguration)
 64    {
 065        var pluginConfigurationSerializer = new XmlSerializer(typeof(PluginConfiguration), new XmlRootAttribute("PluginC
 066        var xmlWriterSettings = new XmlWriterSettings { Indent = true };
 067        using var xmlWriter = XmlWriter.Create(path, xmlWriterSettings);
 068        pluginConfigurationSerializer.Serialize(xmlWriter, newPluginConfiguration);
 069    }
 70
 71#pragma warning disable
 72    public sealed class OldMusicBrainzConfiguration
 73    {
 074        private string _server = string.Empty;
 75
 76        private long _rateLimit = 0L;
 77
 78        public string Server
 79        {
 080            get => _server;
 081            set => _server = value.TrimEnd('/');
 82        }
 83
 84        public long RateLimit
 85        {
 086            get => _rateLimit;
 087            set => _rateLimit = value;
 88        }
 89
 90        public bool ReplaceArtistName { get; set; }
 91    }
 92}