diff options
Diffstat (limited to 'MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs')
| -rw-r--r-- | MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs | 114 |
1 files changed, 80 insertions, 34 deletions
diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs b/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs index 6a2677b43..f7cbf7211 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs @@ -21,22 +21,21 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Model.Globalization; +using MediaBrowser.Controller.Channels; 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>, IHasOrder, IForcedProvider, - IPreRefreshProvider + IPreRefreshProvider, + IHasItemChangeMonitor { private readonly ILogger _logger; private readonly IIsoManager _isoManager; @@ -52,28 +51,59 @@ namespace MediaBrowser.Providers.MediaInfo private readonly ISubtitleManager _subtitleManager; private readonly IChapterManager _chapterManager; private readonly ILibraryManager _libraryManager; + private readonly IChannelManager _channelManager; + private readonly IMediaSourceManager _mediaSourceManager; public string Name { get { return "ffprobe"; } } - public Task<ItemUpdateType> FetchAsync(Episode item, MetadataRefreshOptions options, CancellationToken cancellationToken) + public bool HasChanged(BaseItem item, IDirectoryService directoryService) { - return FetchVideoInfo(item, options, cancellationToken); + var video = item as Video; + if (video == null || video.VideoType == VideoType.VideoFile || video.VideoType == VideoType.Iso) + { + var path = item.Path; + + if (!string.IsNullOrWhiteSpace(path) && item.IsFileProtocol) + { + var file = directoryService.GetFile(path); + if (file != null && file.LastWriteTimeUtc != item.DateModified) + { + _logger.Debug("Refreshing {0} due to date modified timestamp change.", path); + return true; + } + } + } + + if (item.SupportsLocalMetadata) + { + if (video != null && !video.IsPlaceHolder) + { + if (!video.SubtitleFiles + .SequenceEqual(_subtitleResolver.GetExternalSubtitleFiles(video, directoryService, false), StringComparer.Ordinal)) + { + _logger.Debug("Refreshing {0} due to external subtitles change.", item.Path); + return true; + } + } + } + + return false; } - public Task<ItemUpdateType> FetchAsync(MusicVideo item, MetadataRefreshOptions options, CancellationToken cancellationToken) + public Task<ItemUpdateType> FetchAsync(Episode item, MetadataRefreshOptions options, CancellationToken cancellationToken) { return FetchVideoInfo(item, options, cancellationToken); } - public Task<ItemUpdateType> FetchAsync(Movie item, MetadataRefreshOptions options, CancellationToken cancellationToken) + public Task<ItemUpdateType> FetchAsync(MusicVideo item, MetadataRefreshOptions options, CancellationToken cancellationToken) { return FetchVideoInfo(item, options, cancellationToken); } - public Task<ItemUpdateType> FetchAsync(LiveTvVideoRecording item, MetadataRefreshOptions options, CancellationToken cancellationToken) + public Task<ItemUpdateType> FetchAsync(Movie item, MetadataRefreshOptions options, CancellationToken cancellationToken) { return FetchVideoInfo(item, options, cancellationToken); } @@ -90,25 +120,16 @@ namespace MediaBrowser.Providers.MediaInfo 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); + return FetchAudioInfo(item, options, cancellationToken); } public Task<ItemUpdateType> FetchAsync(AudioBook item, MetadataRefreshOptions options, CancellationToken cancellationToken) { - return FetchAudioInfo(item, cancellationToken); + return FetchAudioInfo(item, options, 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) + private SubtitleResolver _subtitleResolver; + public FFProbeProvider(ILogger logger, IMediaSourceManager mediaSourceManager, IChannelManager channelManager, 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; @@ -124,28 +145,37 @@ namespace MediaBrowser.Providers.MediaInfo _subtitleManager = subtitleManager; _chapterManager = chapterManager; _libraryManager = libraryManager; + _channelManager = channelManager; + _mediaSourceManager = mediaSourceManager; + + _subtitleResolver = new SubtitleResolver(BaseItem.LocalizationManager, fileSystem); } 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) + if (item.VideoType == VideoType.Iso) { return _cachedTask; } - if (item.VideoType == VideoType.Iso && !_isoManager.CanMount(item.Path)) + if (item.IsPlaceHolder) { return _cachedTask; } - if (item.IsPlaceHolder) + if (!item.IsCompleteMedia) { return _cachedTask; } - if (!item.IsCompleteMedia) + if (item.IsVirtualItem) + { + return _cachedTask; + } + + if (!options.EnableRemoteContentProbe && !item.IsFileProtocol) { return _cachedTask; } @@ -155,31 +185,47 @@ namespace MediaBrowser.Providers.MediaInfo FetchShortcutInfo(item); } - var prober = new FFProbeVideoInfo(_logger, _isoManager, _mediaEncoder, _itemRepo, _blurayExaminer, _localization, _appPaths, _json, _encodingManager, _fileSystem, _config, _subtitleManager, _chapterManager, _libraryManager); + var prober = new FFProbeVideoInfo(_logger, _mediaSourceManager, _isoManager, _mediaEncoder, _itemRepo, _blurayExaminer, _localization, _appPaths, _json, _encodingManager, _fileSystem, _config, _subtitleManager, _chapterManager, _libraryManager); return prober.ProbeVideo(item, options, cancellationToken); } - private void FetchShortcutInfo(Video video) + private string NormalizeStrmLine(string line) { - video.ShortcutPath = _fileSystem.ReadAllText(video.Path) - .Replace("\t", string.Empty) + return line.Replace("\t", string.Empty) .Replace("\r", string.Empty) .Replace("\n", string.Empty) .Trim(); } - public Task<ItemUpdateType> FetchAudioInfo<T>(T item, CancellationToken cancellationToken) + private void FetchShortcutInfo(BaseItem item) + { + item.ShortcutPath = _fileSystem.ReadAllLines(item.Path) + .Select(NormalizeStrmLine) + .FirstOrDefault(i => !string.IsNullOrWhiteSpace(i) && !i.StartsWith("#", StringComparison.OrdinalIgnoreCase)); + } + + public Task<ItemUpdateType> FetchAudioInfo<T>(T item, MetadataRefreshOptions options, CancellationToken cancellationToken) where T : Audio { - if (item.LocationType != LocationType.FileSystem) + if (item.IsVirtualItem) + { + return _cachedTask; + } + + if (!options.EnableRemoteContentProbe && !item.IsFileProtocol) { return _cachedTask; } - var prober = new FFProbeAudioInfo(_mediaEncoder, _itemRepo, _appPaths, _json, _libraryManager); + if (item.IsShortcut) + { + FetchShortcutInfo(item); + } + + var prober = new FFProbeAudioInfo(_mediaSourceManager, _mediaEncoder, _itemRepo, _appPaths, _json, _libraryManager); - return prober.Probe(item, cancellationToken); + return prober.Probe(item, options, cancellationToken); } public int Order |
