< 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: 94
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 5/31/2026 - 12:15:44 AM Line coverage: 0% (0/32) Branch coverage: 0% (0/6) Total lines: 9211/13/2026 - 12:19:51 AM Line coverage: 0% (0/32) Branch coverage: 0% (0/6) Total lines: 94 5/31/2026 - 12:15:44 AM Line coverage: 0% (0/32) Branch coverage: 0% (0/6) Total lines: 9211/13/2026 - 12:19:51 AM Line coverage: 0% (0/32) Branch coverage: 0% (0/6) Total lines: 94

Coverage delta

Coverage delta 1 -1

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
PerformAsync(...)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.Threading;
 4using System.Threading.Tasks;
 5using System.Xml;
 6using System.Xml.Serialization;
 7using Emby.Server.Implementations;
 8using MediaBrowser.Providers.Plugins.MusicBrainz.Configuration;
 9using Microsoft.Extensions.Logging;
 10
 11namespace Jellyfin.Server.Migrations.PreStartupRoutines;
 12
 13/// <inheritdoc />
 14[JellyfinMigration("2025-04-20T02:00:00", nameof(MigrateMusicBrainzTimeout), "A6DCACF4-C057-4Ef9-80D3-61CEF9DDB4F0", Sta
 15public class MigrateMusicBrainzTimeout : IAsyncMigrationRoutine
 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 Task PerformAsync(CancellationToken cancellationToken)
 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 Task.CompletedTask;
 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        }
 54
 055        return Task.CompletedTask;
 56    }
 57
 58    private OldMusicBrainzConfiguration? ReadOld(string path)
 59    {
 060        using var xmlReader = XmlReader.Create(path);
 061        var serverConfigSerializer = new XmlSerializer(typeof(OldMusicBrainzConfiguration), new XmlRootAttribute("Plugin
 062        return serverConfigSerializer.Deserialize(xmlReader) as OldMusicBrainzConfiguration;
 063    }
 64
 65    private void WriteNew(string path, PluginConfiguration newPluginConfiguration)
 66    {
 067        var pluginConfigurationSerializer = new XmlSerializer(typeof(PluginConfiguration), new XmlRootAttribute("PluginC
 068        var xmlWriterSettings = new XmlWriterSettings { Indent = true };
 069        using var xmlWriter = XmlWriter.Create(path, xmlWriterSettings);
 070        pluginConfigurationSerializer.Serialize(xmlWriter, newPluginConfiguration);
 071    }
 72
 73#pragma warning disable
 74    public sealed class OldMusicBrainzConfiguration
 75    {
 076        private string _server = string.Empty;
 77
 78        private long _rateLimit = 0L;
 79
 80        public string Server
 81        {
 082            get => _server;
 083            set => _server = value.TrimEnd('/');
 84        }
 85
 86        public long RateLimit
 87        {
 088            get => _rateLimit;
 089            set => _rateLimit = value;
 90        }
 91
 92        public bool ReplaceArtistName { get; set; }
 93    }
 94}