| | | 1 | | using System.Threading; |
| | | 2 | | using System.Threading.Tasks; |
| | | 3 | | using MediaBrowser.Controller.Configuration; |
| | | 4 | | using MediaBrowser.Controller.Entities; |
| | | 5 | | using MediaBrowser.Controller.Entities.Movies; |
| | | 6 | | using MediaBrowser.Controller.Entities.TV; |
| | | 7 | | using MediaBrowser.Controller.Library; |
| | | 8 | | using MediaBrowser.Controller.Providers; |
| | | 9 | | using MediaBrowser.Controller.Trickplay; |
| | | 10 | | using MediaBrowser.Model.Configuration; |
| | | 11 | | |
| | | 12 | | namespace MediaBrowser.Providers.Trickplay; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Class TrickplayProvider. Provides images and metadata for trickplay |
| | | 16 | | /// scrubbing previews. |
| | | 17 | | /// </summary> |
| | | 18 | | public 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 | | { |
| | 21 | 42 | | _config = config; |
| | 21 | 43 | | _trickplayManager = trickplayManager; |
| | 21 | 44 | | _libraryManager = libraryManager; |
| | 21 | 45 | | } |
| | | 46 | | |
| | | 47 | | /// <inheritdoc /> |
| | 0 | 48 | | public string Name => "Trickplay Provider"; |
| | | 49 | | |
| | | 50 | | /// <inheritdoc /> |
| | 0 | 51 | | public int Order => 100; |
| | | 52 | | |
| | | 53 | | /// <inheritdoc /> |
| | | 54 | | public bool HasChanged(BaseItem item, IDirectoryService directoryService) |
| | | 55 | | { |
| | 0 | 56 | | if (item.IsFileProtocol) |
| | | 57 | | { |
| | 0 | 58 | | var file = directoryService.GetFile(item.Path); |
| | 0 | 59 | | if (file is not null && item.HasChanged(file.LastWriteTimeUtc)) |
| | | 60 | | { |
| | 0 | 61 | | return true; |
| | | 62 | | } |
| | | 63 | | } |
| | | 64 | | |
| | 0 | 65 | | return false; |
| | | 66 | | } |
| | | 67 | | |
| | | 68 | | /// <inheritdoc /> |
| | | 69 | | public Task<ItemUpdateType> FetchAsync(Episode item, MetadataRefreshOptions options, CancellationToken cancellationT |
| | | 70 | | { |
| | 0 | 71 | | return FetchInternal(item, options, cancellationToken); |
| | | 72 | | } |
| | | 73 | | |
| | | 74 | | /// <inheritdoc /> |
| | | 75 | | public Task<ItemUpdateType> FetchAsync(MusicVideo item, MetadataRefreshOptions options, CancellationToken cancellati |
| | | 76 | | { |
| | 0 | 77 | | return FetchInternal(item, options, cancellationToken); |
| | | 78 | | } |
| | | 79 | | |
| | | 80 | | /// <inheritdoc /> |
| | | 81 | | public Task<ItemUpdateType> FetchAsync(Movie item, MetadataRefreshOptions options, CancellationToken cancellationTok |
| | | 82 | | { |
| | 0 | 83 | | return FetchInternal(item, options, cancellationToken); |
| | | 84 | | } |
| | | 85 | | |
| | | 86 | | /// <inheritdoc /> |
| | | 87 | | public Task<ItemUpdateType> FetchAsync(Trailer item, MetadataRefreshOptions options, CancellationToken cancellationT |
| | | 88 | | { |
| | 0 | 89 | | return FetchInternal(item, options, cancellationToken); |
| | | 90 | | } |
| | | 91 | | |
| | | 92 | | /// <inheritdoc /> |
| | | 93 | | public Task<ItemUpdateType> FetchAsync(Video item, MetadataRefreshOptions options, CancellationToken cancellationTok |
| | | 94 | | { |
| | 0 | 95 | | 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 (libraryOptions is null || !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 | | } |