< Summary - Jellyfin

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

#LineLine coverage
 1using System;
 2using System.Globalization;
 3using System.Threading;
 4using System.Threading.Tasks;
 5using Jellyfin.Data.Enums;
 6using MediaBrowser.Controller.Entities;
 7using MediaBrowser.Controller.Library;
 8using MediaBrowser.Controller.Persistence;
 9using Microsoft.Extensions.Logging;
 10
 11namespace Emby.Server.Implementations.Library.Validators
 12{
 13    /// <summary>
 14    /// Class StudiosValidator.
 15    /// </summary>
 16    public class StudiosValidator
 17    {
 18        /// <summary>
 19        /// The library manager.
 20        /// </summary>
 21        private readonly ILibraryManager _libraryManager;
 22
 23        private readonly IItemRepository _itemRepo;
 24
 25        /// <summary>
 26        /// The logger.
 27        /// </summary>
 28        private readonly ILogger<StudiosValidator> _logger;
 29
 30        /// <summary>
 31        /// Initializes a new instance of the <see cref="StudiosValidator" /> class.
 32        /// </summary>
 33        /// <param name="libraryManager">The library manager.</param>
 34        /// <param name="logger">The logger.</param>
 35        /// <param name="itemRepo">The item repository.</param>
 36        public StudiosValidator(ILibraryManager libraryManager, ILogger<StudiosValidator> logger, IItemRepository itemRe
 37        {
 1938            _libraryManager = libraryManager;
 1939            _logger = logger;
 1940            _itemRepo = itemRepo;
 1941        }
 42
 43        /// <summary>
 44        /// Runs the specified progress.
 45        /// </summary>
 46        /// <param name="progress">The progress.</param>
 47        /// <param name="cancellationToken">The cancellation token.</param>
 48        /// <returns>Task.</returns>
 49        public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
 50        {
 51            var names = _itemRepo.GetStudioNames();
 52
 53            var numComplete = 0;
 54            var count = names.Count;
 55
 56            foreach (var name in names)
 57            {
 58                try
 59                {
 60                    var item = _libraryManager.GetStudio(name);
 61
 62                    await item.RefreshMetadata(cancellationToken).ConfigureAwait(false);
 63                }
 64                catch (OperationCanceledException)
 65                {
 66                    // Don't clutter the log
 67                    throw;
 68                }
 69                catch (Exception ex)
 70                {
 71                    _logger.LogError(ex, "Error refreshing {StudioName}", name);
 72                }
 73
 74                numComplete++;
 75                double percent = numComplete;
 76                percent /= count;
 77                percent *= 100;
 78
 79                progress.Report(percent);
 80            }
 81
 82            var deadEntities = _libraryManager.GetItemList(new InternalItemsQuery
 83            {
 84                IncludeItemTypes = new[] { BaseItemKind.Studio },
 85                IsDeadStudio = true,
 86                IsLocked = false
 87            });
 88
 89            foreach (var item in deadEntities)
 90            {
 91                _logger.LogInformation("Deleting dead {ItemType} {ItemId} {ItemName}", item.GetType().Name, item.Id.ToSt
 92
 93                _libraryManager.DeleteItem(
 94                    item,
 95                    new DeleteOptions
 96                    {
 97                        DeleteFileLocation = false
 98                    },
 99                    false);
 100            }
 101
 102            progress.Report(100);
 103        }
 104    }
 105}