123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- using MediaBrowser.Common.Configuration;
- using MediaBrowser.Controller.Chapters;
- using MediaBrowser.Controller.Configuration;
- using MediaBrowser.Controller.Entities;
- using MediaBrowser.Controller.Entities.Audio;
- using MediaBrowser.Controller.Entities.Movies;
- using MediaBrowser.Controller.Entities.TV;
- using MediaBrowser.Controller.Library;
- using MediaBrowser.Controller.LiveTv;
- using MediaBrowser.Controller.MediaEncoding;
- using MediaBrowser.Controller.Persistence;
- using MediaBrowser.Controller.Providers;
- using MediaBrowser.Controller.Subtitles;
- using MediaBrowser.Model.Entities;
- using MediaBrowser.Model.IO;
- using MediaBrowser.Model.Logging;
- using MediaBrowser.Model.MediaInfo;
- using MediaBrowser.Model.Serialization;
- using System;
- using System.Linq;
- using System.Threading;
- using System.Threading.Tasks;
- using MediaBrowser.Model.Globalization;
- namespace MediaBrowser.Providers.MediaInfo
- {
- public class FFProbeProvider : ICustomMetadataProvider<Episode>,
- ICustomMetadataProvider<MusicVideo>,
- ICustomMetadataProvider<Movie>,
- ICustomMetadataProvider<LiveTvVideoRecording>,
- ICustomMetadataProvider<LiveTvAudioRecording>,
- ICustomMetadataProvider<Trailer>,
- ICustomMetadataProvider<Video>,
- ICustomMetadataProvider<Audio>,
- ICustomMetadataProvider<AudioPodcast>,
- ICustomMetadataProvider<AudioBook>,
- IHasItemChangeMonitor,
- IHasOrder,
- IForcedProvider,
- IPreRefreshProvider
- {
- private readonly ILogger _logger;
- private readonly IIsoManager _isoManager;
- private readonly IMediaEncoder _mediaEncoder;
- private readonly IItemRepository _itemRepo;
- private readonly IBlurayExaminer _blurayExaminer;
- private readonly ILocalizationManager _localization;
- private readonly IApplicationPaths _appPaths;
- private readonly IJsonSerializer _json;
- private readonly IEncodingManager _encodingManager;
- private readonly IFileSystem _fileSystem;
- private readonly IServerConfigurationManager _config;
- private readonly ISubtitleManager _subtitleManager;
- private readonly IChapterManager _chapterManager;
- private readonly ILibraryManager _libraryManager;
- public string Name
- {
- get { return "ffprobe"; }
- }
- public Task<ItemUpdateType> FetchAsync(Episode item, MetadataRefreshOptions options, CancellationToken cancellationToken)
- {
- return FetchVideoInfo(item, options, cancellationToken);
- }
- public Task<ItemUpdateType> FetchAsync(MusicVideo item, MetadataRefreshOptions options, CancellationToken cancellationToken)
- {
- return FetchVideoInfo(item, options, cancellationToken);
- }
- public Task<ItemUpdateType> FetchAsync(Movie item, MetadataRefreshOptions options, CancellationToken cancellationToken)
- {
- return FetchVideoInfo(item, options, cancellationToken);
- }
- public Task<ItemUpdateType> FetchAsync(LiveTvVideoRecording item, MetadataRefreshOptions options, CancellationToken cancellationToken)
- {
- return FetchVideoInfo(item, options, cancellationToken);
- }
- public Task<ItemUpdateType> FetchAsync(Trailer item, MetadataRefreshOptions options, CancellationToken cancellationToken)
- {
- return FetchVideoInfo(item, options, cancellationToken);
- }
- public Task<ItemUpdateType> FetchAsync(Video item, MetadataRefreshOptions options, CancellationToken cancellationToken)
- {
- return FetchVideoInfo(item, options, cancellationToken);
- }
- public Task<ItemUpdateType> FetchAsync(Audio item, MetadataRefreshOptions options, CancellationToken cancellationToken)
- {
- return FetchAudioInfo(item, cancellationToken);
- }
- public Task<ItemUpdateType> FetchAsync(LiveTvAudioRecording item, MetadataRefreshOptions options, CancellationToken cancellationToken)
- {
- return FetchAudioInfo(item, cancellationToken);
- }
- public Task<ItemUpdateType> FetchAsync(AudioPodcast item, MetadataRefreshOptions options, CancellationToken cancellationToken)
- {
- return FetchAudioInfo(item, cancellationToken);
- }
- public Task<ItemUpdateType> FetchAsync(AudioBook item, MetadataRefreshOptions options, CancellationToken cancellationToken)
- {
- return FetchAudioInfo(item, cancellationToken);
- }
- public FFProbeProvider(ILogger logger, IIsoManager isoManager, IMediaEncoder mediaEncoder, IItemRepository itemRepo, IBlurayExaminer blurayExaminer, ILocalizationManager localization, IApplicationPaths appPaths, IJsonSerializer json, IEncodingManager encodingManager, IFileSystem fileSystem, IServerConfigurationManager config, ISubtitleManager subtitleManager, IChapterManager chapterManager, ILibraryManager libraryManager)
- {
- _logger = logger;
- _isoManager = isoManager;
- _mediaEncoder = mediaEncoder;
- _itemRepo = itemRepo;
- _blurayExaminer = blurayExaminer;
- _localization = localization;
- _appPaths = appPaths;
- _json = json;
- _encodingManager = encodingManager;
- _fileSystem = fileSystem;
- _config = config;
- _subtitleManager = subtitleManager;
- _chapterManager = chapterManager;
- _libraryManager = libraryManager;
- }
- private readonly Task<ItemUpdateType> _cachedTask = Task.FromResult(ItemUpdateType.None);
- public Task<ItemUpdateType> FetchVideoInfo<T>(T item, MetadataRefreshOptions options, CancellationToken cancellationToken)
- where T : Video
- {
- if (item.LocationType != LocationType.FileSystem)
- {
- return _cachedTask;
- }
- if (item.VideoType == VideoType.Iso && !_isoManager.CanMount(item.Path))
- {
- return _cachedTask;
- }
- if (item.VideoType == VideoType.HdDvd)
- {
- return _cachedTask;
- }
- if (item.IsPlaceHolder)
- {
- return _cachedTask;
- }
- if (item.IsShortcut)
- {
- FetchShortcutInfo(item);
- return Task.FromResult(ItemUpdateType.MetadataImport);
- }
- var prober = new FFProbeVideoInfo(_logger, _isoManager, _mediaEncoder, _itemRepo, _blurayExaminer, _localization, _appPaths, _json, _encodingManager, _fileSystem, _config, _subtitleManager, _chapterManager, _libraryManager);
- return prober.ProbeVideo(item, options, cancellationToken);
- }
- private void FetchShortcutInfo(Video video)
- {
- video.ShortcutPath = _fileSystem.ReadAllText(video.Path);
- }
- public Task<ItemUpdateType> FetchAudioInfo<T>(T item, CancellationToken cancellationToken)
- where T : Audio
- {
- if (item.LocationType != LocationType.FileSystem)
- {
- return _cachedTask;
- }
- var prober = new FFProbeAudioInfo(_mediaEncoder, _itemRepo, _appPaths, _json, _libraryManager);
- return prober.Probe(item, cancellationToken);
- }
- public bool HasChanged(IHasMetadata item, IDirectoryService directoryService)
- {
- if (item.EnableRefreshOnDateModifiedChange && !string.IsNullOrWhiteSpace(item.Path) && item.LocationType == LocationType.FileSystem)
- {
- var file = directoryService.GetFile(item.Path);
- if (file != null && file.LastWriteTimeUtc != item.DateModified)
- {
- return true;
- }
- }
- if (item.SupportsLocalMetadata)
- {
- var video = item as Video;
- if (video != null && !video.IsPlaceHolder)
- {
- return !video.SubtitleFiles
- .SequenceEqual(SubtitleResolver.GetSubtitleFiles(video, directoryService, _fileSystem, false)
- .OrderBy(i => i), StringComparer.OrdinalIgnoreCase);
- }
- }
- return false;
- }
- public int Order
- {
- get
- {
- // Run last
- return 100;
- }
- }
- }
- }
|