< Summary - Jellyfin

Information
Class: MediaBrowser.Providers.Trickplay.TrickplayMoveImagesTask
Assembly: MediaBrowser.Providers
File(s): /srv/git/jellyfin/MediaBrowser.Providers/Trickplay/TrickplayMoveImagesTask.cs
Line coverage
60%
Covered lines: 6
Uncovered lines: 4
Coverable lines: 10
Total lines: 119
Line coverage: 60%
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%
get_Name()100%210%
get_Description()100%210%
get_Key()100%210%
get_Category()100%210%
GetDefaultTriggers()100%11100%

File(s)

/srv/git/jellyfin/MediaBrowser.Providers/Trickplay/TrickplayMoveImagesTask.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Threading;
 5using System.Threading.Tasks;
 6using Jellyfin.Data.Enums;
 7using MediaBrowser.Controller.Entities;
 8using MediaBrowser.Controller.Library;
 9using MediaBrowser.Controller.Trickplay;
 10using MediaBrowser.Model.Globalization;
 11using MediaBrowser.Model.Tasks;
 12using Microsoft.Extensions.Logging;
 13
 14namespace MediaBrowser.Providers.Trickplay;
 15
 16/// <summary>
 17/// Class TrickplayMoveImagesTask.
 18/// </summary>
 19public class TrickplayMoveImagesTask : IScheduledTask
 20{
 21    private readonly ILogger<TrickplayMoveImagesTask> _logger;
 22    private readonly ILibraryManager _libraryManager;
 23    private readonly ILocalizationManager _localization;
 24    private readonly ITrickplayManager _trickplayManager;
 25
 26    /// <summary>
 27    /// Initializes a new instance of the <see cref="TrickplayMoveImagesTask"/> class.
 28    /// </summary>
 29    /// <param name="logger">The logger.</param>
 30    /// <param name="libraryManager">The library manager.</param>
 31    /// <param name="localization">The localization manager.</param>
 32    /// <param name="trickplayManager">The trickplay manager.</param>
 33    public TrickplayMoveImagesTask(
 34        ILogger<TrickplayMoveImagesTask> logger,
 35        ILibraryManager libraryManager,
 36        ILocalizationManager localization,
 37        ITrickplayManager trickplayManager)
 38    {
 2139        _libraryManager = libraryManager;
 2140        _logger = logger;
 2141        _localization = localization;
 2142        _trickplayManager = trickplayManager;
 2143    }
 44
 45    /// <inheritdoc />
 046    public string Name => _localization.GetLocalizedString("TaskMoveTrickplayImages");
 47
 48    /// <inheritdoc />
 049    public string Description => _localization.GetLocalizedString("TaskMoveTrickplayImagesDescription");
 50
 51    /// <inheritdoc />
 052    public string Key => "MoveTrickplayImages";
 53
 54    /// <inheritdoc />
 055    public string Category => _localization.GetLocalizedString("TasksMaintenanceCategory");
 56
 57    /// <inheritdoc />
 2158    public IEnumerable<TaskTriggerInfo> GetDefaultTriggers() => [];
 59
 60    /// <inheritdoc />
 61    public async Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
 62    {
 63        const int Limit = 100;
 64        int itemCount = 0, offset = 0, previousCount;
 65
 66        // This count may not be accurate, but just get something to show progress on the dashboard.
 67        var totalVideoCount = _libraryManager.GetCount(new InternalItemsQuery
 68        {
 69            MediaTypes = [MediaType.Video],
 70            SourceTypes = [SourceType.Library],
 71            IsVirtualItem = false,
 72            IsFolder = false,
 73            Recursive = true
 74        });
 75
 76        var trickplayQuery = new InternalItemsQuery
 77        {
 78            MediaTypes = [MediaType.Video],
 79            SourceTypes = [SourceType.Library],
 80            IsVirtualItem = false,
 81            IsFolder = false
 82        };
 83
 84        do
 85        {
 86            var trickplayInfos = await _trickplayManager.GetTrickplayItemsAsync(Limit, offset).ConfigureAwait(false);
 87            previousCount = trickplayInfos.Count;
 88            offset += Limit;
 89
 90            trickplayQuery.ItemIds = trickplayInfos.Select(i => i.ItemId).Distinct().ToArray();
 91            var items = _libraryManager.GetItemList(trickplayQuery);
 92            foreach (var trickplayInfo in trickplayInfos)
 93            {
 94                cancellationToken.ThrowIfCancellationRequested();
 95
 96                var video = items.OfType<Video>().FirstOrDefault(i => i.Id.Equals(trickplayInfo.ItemId));
 97                if (video is null)
 98                {
 99                    continue;
 100                }
 101
 102                itemCount++;
 103                try
 104                {
 105                    var libraryOptions = _libraryManager.GetLibraryOptions(video);
 106                    await _trickplayManager.MoveGeneratedTrickplayDataAsync(video, libraryOptions, cancellationToken).Co
 107                }
 108                catch (Exception ex)
 109                {
 110                    _logger.LogError(ex, "Error moving trickplay files for {ItemName}", video.Name);
 111                }
 112            }
 113
 114            progress.Report(100d * itemCount / totalVideoCount);
 115        } while (previousCount == Limit);
 116
 117        progress.Report(100);
 118    }
 119}