2015-02-01 14:01:21 -05:00
|
|
|
|
using MediaBrowser.Common.Configuration;
|
2014-06-09 15:16:14 -04:00
|
|
|
|
using MediaBrowser.Controller.Chapters;
|
2014-05-06 22:28:19 -04:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2014-02-09 16:11:11 -05:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-02-05 23:39:16 -05:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2014-02-04 15:19:29 -05:00
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.LiveTv;
|
2014-02-20 11:37:41 -05:00
|
|
|
|
using MediaBrowser.Controller.MediaEncoding;
|
2014-02-04 15:19:29 -05:00
|
|
|
|
using MediaBrowser.Controller.Persistence;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2014-05-06 22:28:19 -04:00
|
|
|
|
using MediaBrowser.Controller.Subtitles;
|
2014-02-04 15:19:29 -05:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.IO;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using MediaBrowser.Model.MediaInfo;
|
2014-02-10 13:39:41 -05:00
|
|
|
|
using MediaBrowser.Model.Serialization;
|
2014-02-04 15:19:29 -05:00
|
|
|
|
using System;
|
2014-05-06 22:28:19 -04:00
|
|
|
|
using System.Linq;
|
2014-02-04 15:19:29 -05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-10-23 22:45:23 -04:00
|
|
|
|
using MediaBrowser.Model.Globalization;
|
2018-09-12 13:26:21 -04:00
|
|
|
|
using MediaBrowser.Controller.Channels;
|
2014-02-04 15:19:29 -05:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.MediaInfo
|
|
|
|
|
{
|
|
|
|
|
public class FFProbeProvider : ICustomMetadataProvider<Episode>,
|
2014-02-05 23:39:16 -05:00
|
|
|
|
ICustomMetadataProvider<MusicVideo>,
|
|
|
|
|
ICustomMetadataProvider<Movie>,
|
2016-05-07 17:01:21 -04:00
|
|
|
|
ICustomMetadataProvider<Trailer>,
|
2014-02-05 23:39:16 -05:00
|
|
|
|
ICustomMetadataProvider<Video>,
|
|
|
|
|
ICustomMetadataProvider<Audio>,
|
2017-01-07 15:52:56 -05:00
|
|
|
|
ICustomMetadataProvider<AudioBook>,
|
2014-02-19 00:21:03 -05:00
|
|
|
|
IHasOrder,
|
2015-03-05 01:34:36 -05:00
|
|
|
|
IForcedProvider,
|
2018-09-12 13:26:21 -04:00
|
|
|
|
IPreRefreshProvider,
|
|
|
|
|
IHasItemChangeMonitor
|
2014-02-04 15:19:29 -05:00
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IIsoManager _isoManager;
|
|
|
|
|
private readonly IMediaEncoder _mediaEncoder;
|
|
|
|
|
private readonly IItemRepository _itemRepo;
|
|
|
|
|
private readonly IBlurayExaminer _blurayExaminer;
|
|
|
|
|
private readonly ILocalizationManager _localization;
|
2014-02-09 16:11:11 -05:00
|
|
|
|
private readonly IApplicationPaths _appPaths;
|
|
|
|
|
private readonly IJsonSerializer _json;
|
2014-02-20 11:37:41 -05:00
|
|
|
|
private readonly IEncodingManager _encodingManager;
|
2014-04-24 22:45:06 -04:00
|
|
|
|
private readonly IFileSystem _fileSystem;
|
2014-05-06 22:28:19 -04:00
|
|
|
|
private readonly IServerConfigurationManager _config;
|
|
|
|
|
private readonly ISubtitleManager _subtitleManager;
|
2014-06-09 15:16:14 -04:00
|
|
|
|
private readonly IChapterManager _chapterManager;
|
2015-06-28 21:10:45 -04:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2018-09-12 13:26:21 -04:00
|
|
|
|
private readonly IChannelManager _channelManager;
|
|
|
|
|
private readonly IMediaSourceManager _mediaSourceManager;
|
2014-02-05 23:39:16 -05:00
|
|
|
|
|
2014-02-04 15:19:29 -05:00
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "ffprobe"; }
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
|
public bool HasChanged(BaseItem item, IDirectoryService directoryService)
|
2014-02-04 15:19:29 -05:00
|
|
|
|
{
|
2018-09-12 13:26:21 -04:00
|
|
|
|
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;
|
2014-02-04 15:19:29 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
|
public Task<ItemUpdateType> FetchAsync(Episode item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-04 15:19:29 -05:00
|
|
|
|
{
|
2014-06-09 15:16:14 -04:00
|
|
|
|
return FetchVideoInfo(item, options, cancellationToken);
|
2014-02-04 15:19:29 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
|
public Task<ItemUpdateType> FetchAsync(MusicVideo item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-04 15:19:29 -05:00
|
|
|
|
{
|
2014-06-09 15:16:14 -04:00
|
|
|
|
return FetchVideoInfo(item, options, cancellationToken);
|
2014-02-04 15:19:29 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
|
public Task<ItemUpdateType> FetchAsync(Movie item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-04 15:19:29 -05:00
|
|
|
|
{
|
2014-06-09 15:16:14 -04:00
|
|
|
|
return FetchVideoInfo(item, options, cancellationToken);
|
2014-02-04 15:19:29 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-07 17:01:21 -04:00
|
|
|
|
public Task<ItemUpdateType> FetchAsync(Trailer item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
return FetchVideoInfo(item, options, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-09 15:16:14 -04:00
|
|
|
|
public Task<ItemUpdateType> FetchAsync(Video item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-05 23:39:16 -05:00
|
|
|
|
{
|
2014-06-09 15:16:14 -04:00
|
|
|
|
return FetchVideoInfo(item, options, cancellationToken);
|
2014-02-05 23:39:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-09 15:16:14 -04:00
|
|
|
|
public Task<ItemUpdateType> FetchAsync(Audio item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-05 23:39:16 -05:00
|
|
|
|
{
|
2018-09-12 13:26:21 -04:00
|
|
|
|
return FetchAudioInfo(item, options, cancellationToken);
|
2017-01-07 15:52:56 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<ItemUpdateType> FetchAsync(AudioBook item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-05 23:39:16 -05:00
|
|
|
|
{
|
2018-09-12 13:26:21 -04:00
|
|
|
|
return FetchAudioInfo(item, options, cancellationToken);
|
2014-02-05 23:39:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
|
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)
|
2014-02-04 15:19:29 -05:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_isoManager = isoManager;
|
|
|
|
|
_mediaEncoder = mediaEncoder;
|
|
|
|
|
_itemRepo = itemRepo;
|
|
|
|
|
_blurayExaminer = blurayExaminer;
|
|
|
|
|
_localization = localization;
|
2014-02-09 16:11:11 -05:00
|
|
|
|
_appPaths = appPaths;
|
|
|
|
|
_json = json;
|
2014-02-23 01:14:48 -05:00
|
|
|
|
_encodingManager = encodingManager;
|
2014-04-24 22:45:06 -04:00
|
|
|
|
_fileSystem = fileSystem;
|
2014-05-06 22:28:19 -04:00
|
|
|
|
_config = config;
|
|
|
|
|
_subtitleManager = subtitleManager;
|
2014-06-09 15:16:14 -04:00
|
|
|
|
_chapterManager = chapterManager;
|
2015-06-28 21:10:45 -04:00
|
|
|
|
_libraryManager = libraryManager;
|
2018-09-12 13:26:21 -04:00
|
|
|
|
_channelManager = channelManager;
|
|
|
|
|
_mediaSourceManager = mediaSourceManager;
|
|
|
|
|
|
|
|
|
|
_subtitleResolver = new SubtitleResolver(BaseItem.LocalizationManager, fileSystem);
|
2014-02-04 15:19:29 -05:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-10 13:39:41 -05:00
|
|
|
|
private readonly Task<ItemUpdateType> _cachedTask = Task.FromResult(ItemUpdateType.None);
|
2014-06-09 15:16:14 -04:00
|
|
|
|
public Task<ItemUpdateType> FetchVideoInfo<T>(T item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-04 15:19:29 -05:00
|
|
|
|
where T : Video
|
|
|
|
|
{
|
2018-09-12 13:26:21 -04:00
|
|
|
|
if (item.VideoType == VideoType.Iso)
|
2014-02-04 15:19:29 -05:00
|
|
|
|
{
|
|
|
|
|
return _cachedTask;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
|
if (item.IsPlaceHolder)
|
2014-02-04 15:19:29 -05:00
|
|
|
|
{
|
|
|
|
|
return _cachedTask;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
|
if (!item.IsCompleteMedia)
|
2014-03-03 00:11:03 -05:00
|
|
|
|
{
|
|
|
|
|
return _cachedTask;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
|
if (item.IsVirtualItem)
|
|
|
|
|
{
|
|
|
|
|
return _cachedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!options.EnableRemoteContentProbe && !item.IsFileProtocol)
|
2017-09-18 12:52:22 -04:00
|
|
|
|
{
|
|
|
|
|
return _cachedTask;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-14 20:05:09 -04:00
|
|
|
|
if (item.IsShortcut)
|
|
|
|
|
{
|
|
|
|
|
FetchShortcutInfo(item);
|
|
|
|
|
}
|
2015-06-28 21:10:45 -04:00
|
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
|
var prober = new FFProbeVideoInfo(_logger, _mediaSourceManager, _isoManager, _mediaEncoder, _itemRepo, _blurayExaminer, _localization, _appPaths, _json, _encodingManager, _fileSystem, _config, _subtitleManager, _chapterManager, _libraryManager);
|
2014-02-04 15:19:29 -05:00
|
|
|
|
|
2014-06-09 15:16:14 -04:00
|
|
|
|
return prober.ProbeVideo(item, options, cancellationToken);
|
2014-02-04 15:19:29 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
|
private string NormalizeStrmLine(string line)
|
2014-10-14 20:05:09 -04:00
|
|
|
|
{
|
2018-09-12 13:26:21 -04:00
|
|
|
|
return line.Replace("\t", string.Empty)
|
2017-11-01 15:50:16 -04:00
|
|
|
|
.Replace("\r", string.Empty)
|
|
|
|
|
.Replace("\n", string.Empty)
|
|
|
|
|
.Trim();
|
2014-10-14 20:05:09 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
|
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)
|
2014-02-05 23:39:16 -05:00
|
|
|
|
where T : Audio
|
|
|
|
|
{
|
2018-09-12 13:26:21 -04:00
|
|
|
|
if (item.IsVirtualItem)
|
|
|
|
|
{
|
|
|
|
|
return _cachedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!options.EnableRemoteContentProbe && !item.IsFileProtocol)
|
2014-02-05 23:39:16 -05:00
|
|
|
|
{
|
|
|
|
|
return _cachedTask;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
|
if (item.IsShortcut)
|
|
|
|
|
{
|
|
|
|
|
FetchShortcutInfo(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var prober = new FFProbeAudioInfo(_mediaSourceManager, _mediaEncoder, _itemRepo, _appPaths, _json, _libraryManager);
|
2014-02-05 23:39:16 -05:00
|
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
|
return prober.Probe(item, options, cancellationToken);
|
2014-02-05 23:39:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-08 18:44:49 -05:00
|
|
|
|
public int Order
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
// Run last
|
|
|
|
|
return 100;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-04 15:19:29 -05:00
|
|
|
|
}
|
|
|
|
|
}
|