< Summary - Jellyfin

Information
Class: MediaBrowser.Providers.Trickplay.TrickplayProvider
Assembly: MediaBrowser.Providers
File(s): /srv/git/jellyfin/MediaBrowser.Providers/Trickplay/TrickplayProvider.cs
Line coverage
25%
Covered lines: 4
Uncovered lines: 12
Coverable lines: 16
Total lines: 121
Line coverage: 25%
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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Name()100%210%
get_Order()100%210%
HasChanged(...)0%4260%
FetchAsync(...)100%210%
FetchAsync(...)100%210%
FetchAsync(...)100%210%
FetchAsync(...)100%210%
FetchAsync(...)100%210%

File(s)

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

#LineLine coverage
 1using System.Threading;
 2using System.Threading.Tasks;
 3using MediaBrowser.Controller.Configuration;
 4using MediaBrowser.Controller.Entities;
 5using MediaBrowser.Controller.Entities.Movies;
 6using MediaBrowser.Controller.Entities.TV;
 7using MediaBrowser.Controller.Library;
 8using MediaBrowser.Controller.Providers;
 9using MediaBrowser.Controller.Trickplay;
 10using MediaBrowser.Model.Configuration;
 11
 12namespace MediaBrowser.Providers.Trickplay;
 13
 14/// <summary>
 15/// Class TrickplayProvider. Provides images and metadata for trickplay
 16/// scrubbing previews.
 17/// </summary>
 18public class TrickplayProvider : ICustomMetadataProvider<Episode>,
 19    ICustomMetadataProvider<MusicVideo>,
 20    ICustomMetadataProvider<Movie>,
 21    ICustomMetadataProvider<Trailer>,
 22    ICustomMetadataProvider<Video>,
 23    IHasItemChangeMonitor,
 24    IHasOrder,
 25    IForcedProvider
 26{
 27    private readonly IServerConfigurationManager _config;
 28    private readonly ITrickplayManager _trickplayManager;
 29    private readonly ILibraryManager _libraryManager;
 30
 31    /// <summary>
 32    /// Initializes a new instance of the <see cref="TrickplayProvider"/> class.
 33    /// </summary>
 34    /// <param name="config">The configuration manager.</param>
 35    /// <param name="trickplayManager">The trickplay manager.</param>
 36    /// <param name="libraryManager">The library manager.</param>
 37    public TrickplayProvider(
 38        IServerConfigurationManager config,
 39        ITrickplayManager trickplayManager,
 40        ILibraryManager libraryManager)
 41    {
 2242        _config = config;
 2243        _trickplayManager = trickplayManager;
 2244        _libraryManager = libraryManager;
 2245    }
 46
 47    /// <inheritdoc />
 048    public string Name => "Trickplay Provider";
 49
 50    /// <inheritdoc />
 051    public int Order => 100;
 52
 53    /// <inheritdoc />
 54    public bool HasChanged(BaseItem item, IDirectoryService directoryService)
 55    {
 056        if (item.IsFileProtocol)
 57        {
 058            var file = directoryService.GetFile(item.Path);
 059            if (file is not null && item.DateModified != file.LastWriteTimeUtc)
 60            {
 061                return true;
 62            }
 63        }
 64
 065        return false;
 66    }
 67
 68    /// <inheritdoc />
 69    public Task<ItemUpdateType> FetchAsync(Episode item, MetadataRefreshOptions options, CancellationToken cancellationT
 70    {
 071        return FetchInternal(item, options, cancellationToken);
 72    }
 73
 74    /// <inheritdoc />
 75    public Task<ItemUpdateType> FetchAsync(MusicVideo item, MetadataRefreshOptions options, CancellationToken cancellati
 76    {
 077        return FetchInternal(item, options, cancellationToken);
 78    }
 79
 80    /// <inheritdoc />
 81    public Task<ItemUpdateType> FetchAsync(Movie item, MetadataRefreshOptions options, CancellationToken cancellationTok
 82    {
 083        return FetchInternal(item, options, cancellationToken);
 84    }
 85
 86    /// <inheritdoc />
 87    public Task<ItemUpdateType> FetchAsync(Trailer item, MetadataRefreshOptions options, CancellationToken cancellationT
 88    {
 089        return FetchInternal(item, options, cancellationToken);
 90    }
 91
 92    /// <inheritdoc />
 93    public Task<ItemUpdateType> FetchAsync(Video item, MetadataRefreshOptions options, CancellationToken cancellationTok
 94    {
 095        return FetchInternal(item, options, cancellationToken);
 96    }
 97
 98    private async Task<ItemUpdateType> FetchInternal(Video video, MetadataRefreshOptions options, CancellationToken canc
 99    {
 100        var libraryOptions = _libraryManager.GetLibraryOptions(video);
 101        bool? enableDuringScan = libraryOptions?.ExtractTrickplayImagesDuringLibraryScan;
 102        bool replace = options.RegenerateTrickplay && options.MetadataRefreshMode > MetadataRefreshMode.Default;
 103
 104        if (!enableDuringScan.GetValueOrDefault(false))
 105        {
 106            return ItemUpdateType.None;
 107        }
 108
 109        if (_config.Configuration.TrickplayOptions.ScanBehavior == TrickplayScanBehavior.Blocking)
 110        {
 111            await _trickplayManager.RefreshTrickplayDataAsync(video, replace, libraryOptions, cancellationToken).Configu
 112        }
 113        else
 114        {
 115            _ = _trickplayManager.RefreshTrickplayDataAsync(video, replace, libraryOptions, cancellationToken).Configure
 116        }
 117
 118        // The core doesn't need to trigger any save operations over this
 119        return ItemUpdateType.None;
 120    }
 121}