< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.ScheduledTasks.Tasks.MediaSegmentExtractionTask
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/ScheduledTasks/Tasks/MediaSegmentExtractionTask.cs
Line coverage
22%
Covered lines: 11
Uncovered lines: 37
Coverable lines: 48
Total lines: 119
Line coverage: 22.9%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 1/23/2026 - 12:11:06 AM Line coverage: 55.5% (5/9) Total lines: 1194/19/2026 - 12:14:27 AM Line coverage: 22.9% (11/48) Branch coverage: 0% (0/8) Total lines: 119 4/19/2026 - 12:14:27 AM Line coverage: 22.9% (11/48) Branch coverage: 0% (0/8) Total lines: 119

Coverage delta

Coverage delta 33 -33

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%210%
.ctor(...)100%11100%
get_Name()100%11100%
get_Description()100%210%
get_Category()100%210%
get_Key()100%210%
ExecuteAsync()0%7280%
GetDefaultTriggers()100%11100%

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/ScheduledTasks/Tasks/MediaSegmentExtractionTask.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.IO;
 4using System.Threading;
 5using System.Threading.Tasks;
 6using Jellyfin.Data.Enums;
 7using MediaBrowser.Controller.Dto;
 8using MediaBrowser.Controller.Entities;
 9using MediaBrowser.Controller.Library;
 10using MediaBrowser.Controller.MediaSegments;
 11using MediaBrowser.Model.Globalization;
 12using MediaBrowser.Model.Tasks;
 13
 14namespace Emby.Server.Implementations.ScheduledTasks.Tasks;
 15
 16/// <summary>
 17/// Task to obtain media segments.
 18/// </summary>
 19public class MediaSegmentExtractionTask : IScheduledTask
 20{
 21    /// <summary>
 22    /// The library manager.
 23    /// </summary>
 24    private readonly ILibraryManager _libraryManager;
 25    private readonly ILocalizationManager _localization;
 26    private readonly IMediaSegmentManager _mediaSegmentManager;
 027    private static readonly BaseItemKind[] _itemTypes = [BaseItemKind.Episode, BaseItemKind.Movie, BaseItemKind.Audio, B
 28
 29    /// <summary>
 30    /// Initializes a new instance of the <see cref="MediaSegmentExtractionTask" /> class.
 31    /// </summary>
 32    /// <param name="libraryManager">The library manager.</param>
 33    /// <param name="localization">The localization manager.</param>
 34    /// <param name="mediaSegmentManager">The segment manager.</param>
 35    public MediaSegmentExtractionTask(ILibraryManager libraryManager, ILocalizationManager localization, IMediaSegmentMa
 36    {
 2137        _libraryManager = libraryManager;
 2138        _localization = localization;
 2139        _mediaSegmentManager = mediaSegmentManager;
 2140    }
 41
 42    /// <inheritdoc/>
 2143    public string Name => _localization.GetLocalizedString("TaskExtractMediaSegments");
 44
 45    /// <inheritdoc/>
 046    public string Description => _localization.GetLocalizedString("TaskExtractMediaSegmentsDescription");
 47
 48    /// <inheritdoc/>
 049    public string Category => _localization.GetLocalizedString("TasksLibraryCategory");
 50
 51    /// <inheritdoc/>
 052    public string Key => "TaskExtractMediaSegments";
 53
 54    /// <inheritdoc/>
 55    public async Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
 56    {
 057        cancellationToken.ThrowIfCancellationRequested();
 58
 059        progress.Report(0);
 60
 061        var pagesize = 100;
 62
 063        var query = new InternalItemsQuery
 064        {
 065            MediaTypes = [MediaType.Video, MediaType.Audio],
 066            IsVirtualItem = false,
 067            IncludeItemTypes = _itemTypes,
 068            DtoOptions = new DtoOptions(true),
 069            SourceTypes = [SourceType.Library],
 070            Recursive = true,
 071            Limit = pagesize
 072        };
 73
 074        var numberOfVideos = _libraryManager.GetCount(query);
 75
 076        var startIndex = 0;
 077        var numComplete = 0;
 78
 079        while (startIndex < numberOfVideos)
 80        {
 081            query.StartIndex = startIndex;
 82
 083            var baseItems = _libraryManager.GetItemList(query);
 084            var currentPageCount = baseItems.Count;
 85            // TODO parallelize with Parallel.ForEach?
 086            for (var i = 0; i < currentPageCount; i++)
 87            {
 088                cancellationToken.ThrowIfCancellationRequested();
 89
 090                var item = baseItems[i];
 91                // Only local files supported
 092                if (item.IsFileProtocol && File.Exists(item.Path))
 93                {
 094                    var libraryOptions = _libraryManager.GetLibraryOptions(item);
 095                    await _mediaSegmentManager.RunSegmentPluginProviders(item, libraryOptions, false, cancellationToken)
 96                }
 97
 98                // Update progress
 099                numComplete++;
 0100                double percent = (double)numComplete / numberOfVideos;
 0101                progress.Report(100 * percent);
 102            }
 103
 0104            startIndex += pagesize;
 0105        }
 106
 0107        progress.Report(100);
 0108    }
 109
 110    /// <inheritdoc/>
 111    public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
 112    {
 21113        yield return new TaskTriggerInfo
 21114        {
 21115            Type = TaskTriggerInfoType.IntervalTrigger,
 21116            IntervalTicks = TimeSpan.FromHours(12).Ticks
 21117        };
 21118    }
 119}