< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.Library.Validators.MusicGenresValidator
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/Library/Validators/MusicGenresValidator.cs
Line coverage
100%
Covered lines: 4
Uncovered lines: 0
Coverable lines: 4
Total lines: 80
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
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%11100%

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/Library/Validators/MusicGenresValidator.cs

#LineLine coverage
 1using System;
 2using System.Threading;
 3using System.Threading.Tasks;
 4using MediaBrowser.Controller.Library;
 5using MediaBrowser.Controller.Persistence;
 6using Microsoft.Extensions.Logging;
 7
 8namespace Emby.Server.Implementations.Library.Validators;
 9
 10/// <summary>
 11/// Class MusicGenresValidator.
 12/// </summary>
 13public class MusicGenresValidator
 14{
 15    /// <summary>
 16    /// The library manager.
 17    /// </summary>
 18    private readonly ILibraryManager _libraryManager;
 19
 20    /// <summary>
 21    /// The logger.
 22    /// </summary>
 23    private readonly ILogger<MusicGenresValidator> _logger;
 24    private readonly IItemRepository _itemRepo;
 25
 26    /// <summary>
 27    /// Initializes a new instance of the <see cref="MusicGenresValidator" /> class.
 28    /// </summary>
 29    /// <param name="libraryManager">The library manager.</param>
 30    /// <param name="logger">The logger.</param>
 31    /// <param name="itemRepo">The item repository.</param>
 32    public MusicGenresValidator(ILibraryManager libraryManager, ILogger<MusicGenresValidator> logger, IItemRepository it
 33    {
 934        _libraryManager = libraryManager;
 935        _logger = logger;
 936        _itemRepo = itemRepo;
 937    }
 38
 39    /// <summary>
 40    /// Runs the specified progress.
 41    /// </summary>
 42    /// <param name="progress">The progress.</param>
 43    /// <param name="cancellationToken">The cancellation token.</param>
 44    /// <returns>Task.</returns>
 45    public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
 46    {
 47        var names = _itemRepo.GetMusicGenreNames();
 48
 49        var numComplete = 0;
 50        var count = names.Count;
 51
 52        foreach (var name in names)
 53        {
 54            try
 55            {
 56                var item = _libraryManager.GetMusicGenre(name);
 57
 58                await item.RefreshMetadata(cancellationToken).ConfigureAwait(false);
 59            }
 60            catch (OperationCanceledException)
 61            {
 62                // Don't clutter the log
 63                throw;
 64            }
 65            catch (Exception ex)
 66            {
 67                _logger.LogError(ex, "Error refreshing {GenreName}", name);
 68            }
 69
 70            numComplete++;
 71            double percent = numComplete;
 72            percent /= count;
 73            percent *= 100;
 74
 75            progress.Report(percent);
 76        }
 77
 78        progress.Report(100);
 79    }
 80}