2015-02-01 12:01:21 -07:00
|
|
|
|
using MediaBrowser.Common.Configuration;
|
2014-06-09 12:16:14 -07:00
|
|
|
|
using MediaBrowser.Controller.Chapters;
|
2014-05-06 19:28:19 -07:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2014-02-09 14:11:11 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-02-05 21:39:16 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2014-02-04 13:19:29 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.LiveTv;
|
2014-02-20 09:37:41 -07:00
|
|
|
|
using MediaBrowser.Controller.MediaEncoding;
|
2014-02-04 13:19:29 -07:00
|
|
|
|
using MediaBrowser.Controller.Persistence;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2014-05-06 19:28:19 -07:00
|
|
|
|
using MediaBrowser.Controller.Subtitles;
|
2014-02-04 13:19:29 -07:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.IO;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using MediaBrowser.Model.MediaInfo;
|
2014-02-10 11:39:41 -07:00
|
|
|
|
using MediaBrowser.Model.Serialization;
|
2014-02-04 13:19:29 -07:00
|
|
|
|
using System;
|
2014-05-06 19:28:19 -07:00
|
|
|
|
using System.Linq;
|
2014-02-04 13:19:29 -07:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-10-23 19:45:23 -07:00
|
|
|
|
using MediaBrowser.Model.Globalization;
|
2014-02-04 13:19:29 -07:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.MediaInfo
|
|
|
|
|
{
|
|
|
|
|
public class FFProbeProvider : ICustomMetadataProvider<Episode>,
|
2014-02-05 21:39:16 -07:00
|
|
|
|
ICustomMetadataProvider<MusicVideo>,
|
|
|
|
|
ICustomMetadataProvider<Movie>,
|
|
|
|
|
ICustomMetadataProvider<LiveTvVideoRecording>,
|
|
|
|
|
ICustomMetadataProvider<LiveTvAudioRecording>,
|
2016-05-07 14:01:21 -07:00
|
|
|
|
ICustomMetadataProvider<Trailer>,
|
2014-02-05 21:39:16 -07:00
|
|
|
|
ICustomMetadataProvider<Video>,
|
|
|
|
|
ICustomMetadataProvider<Audio>,
|
2017-01-07 13:52:56 -07:00
|
|
|
|
ICustomMetadataProvider<AudioPodcast>,
|
|
|
|
|
ICustomMetadataProvider<AudioBook>,
|
2014-09-10 18:57:11 -07:00
|
|
|
|
IHasItemChangeMonitor,
|
2014-02-18 22:21:03 -07:00
|
|
|
|
IHasOrder,
|
2015-03-04 23:34:36 -07:00
|
|
|
|
IForcedProvider,
|
|
|
|
|
IPreRefreshProvider
|
2014-02-04 13:19:29 -07: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 14:11:11 -07:00
|
|
|
|
private readonly IApplicationPaths _appPaths;
|
|
|
|
|
private readonly IJsonSerializer _json;
|
2014-02-20 09:37:41 -07:00
|
|
|
|
private readonly IEncodingManager _encodingManager;
|
2014-04-24 19:45:06 -07:00
|
|
|
|
private readonly IFileSystem _fileSystem;
|
2014-05-06 19:28:19 -07:00
|
|
|
|
private readonly IServerConfigurationManager _config;
|
|
|
|
|
private readonly ISubtitleManager _subtitleManager;
|
2014-06-09 12:16:14 -07:00
|
|
|
|
private readonly IChapterManager _chapterManager;
|
2015-06-28 18:10:45 -07:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2014-02-05 21:39:16 -07:00
|
|
|
|
|
2014-02-04 13:19:29 -07:00
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "ffprobe"; }
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-09 12:16:14 -07:00
|
|
|
|
public Task<ItemUpdateType> FetchAsync(Episode item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-04 13:19:29 -07:00
|
|
|
|
{
|
2014-06-09 12:16:14 -07:00
|
|
|
|
return FetchVideoInfo(item, options, cancellationToken);
|
2014-02-04 13:19:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-09 12:16:14 -07:00
|
|
|
|
public Task<ItemUpdateType> FetchAsync(MusicVideo item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-04 13:19:29 -07:00
|
|
|
|
{
|
2014-06-09 12:16:14 -07:00
|
|
|
|
return FetchVideoInfo(item, options, cancellationToken);
|
2014-02-04 13:19:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-09 12:16:14 -07:00
|
|
|
|
public Task<ItemUpdateType> FetchAsync(Movie item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-04 13:19:29 -07:00
|
|
|
|
{
|
2014-06-09 12:16:14 -07:00
|
|
|
|
return FetchVideoInfo(item, options, cancellationToken);
|
2014-02-04 13:19:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-09 12:16:14 -07:00
|
|
|
|
public Task<ItemUpdateType> FetchAsync(LiveTvVideoRecording item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-04 13:19:29 -07:00
|
|
|
|
{
|
2014-06-09 12:16:14 -07:00
|
|
|
|
return FetchVideoInfo(item, options, cancellationToken);
|
2014-02-04 13:19:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-07 14:01:21 -07:00
|
|
|
|
public Task<ItemUpdateType> FetchAsync(Trailer item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
return FetchVideoInfo(item, options, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-09 12:16:14 -07:00
|
|
|
|
public Task<ItemUpdateType> FetchAsync(Video item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-05 21:39:16 -07:00
|
|
|
|
{
|
2014-06-09 12:16:14 -07:00
|
|
|
|
return FetchVideoInfo(item, options, cancellationToken);
|
2014-02-05 21:39:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-09 12:16:14 -07:00
|
|
|
|
public Task<ItemUpdateType> FetchAsync(Audio item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-05 21:39:16 -07:00
|
|
|
|
{
|
|
|
|
|
return FetchAudioInfo(item, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-09 12:16:14 -07:00
|
|
|
|
public Task<ItemUpdateType> FetchAsync(LiveTvAudioRecording item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2017-01-07 13:52:56 -07:00
|
|
|
|
{
|
|
|
|
|
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)
|
2014-02-05 21:39:16 -07:00
|
|
|
|
{
|
|
|
|
|
return FetchAudioInfo(item, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-28 18:10:45 -07:00
|
|
|
|
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)
|
2014-02-04 13:19:29 -07:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_isoManager = isoManager;
|
|
|
|
|
_mediaEncoder = mediaEncoder;
|
|
|
|
|
_itemRepo = itemRepo;
|
|
|
|
|
_blurayExaminer = blurayExaminer;
|
|
|
|
|
_localization = localization;
|
2014-02-09 14:11:11 -07:00
|
|
|
|
_appPaths = appPaths;
|
|
|
|
|
_json = json;
|
2014-02-22 23:14:48 -07:00
|
|
|
|
_encodingManager = encodingManager;
|
2014-04-24 19:45:06 -07:00
|
|
|
|
_fileSystem = fileSystem;
|
2014-05-06 19:28:19 -07:00
|
|
|
|
_config = config;
|
|
|
|
|
_subtitleManager = subtitleManager;
|
2014-06-09 12:16:14 -07:00
|
|
|
|
_chapterManager = chapterManager;
|
2015-06-28 18:10:45 -07:00
|
|
|
|
_libraryManager = libraryManager;
|
2014-02-04 13:19:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-10 11:39:41 -07:00
|
|
|
|
private readonly Task<ItemUpdateType> _cachedTask = Task.FromResult(ItemUpdateType.None);
|
2014-06-09 12:16:14 -07:00
|
|
|
|
public Task<ItemUpdateType> FetchVideoInfo<T>(T item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-04 13:19:29 -07:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-14 17:05:09 -07:00
|
|
|
|
if (item.IsPlaceHolder)
|
2014-03-02 22:11:03 -07:00
|
|
|
|
{
|
|
|
|
|
return _cachedTask;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-14 17:05:09 -07:00
|
|
|
|
if (item.IsShortcut)
|
|
|
|
|
{
|
|
|
|
|
FetchShortcutInfo(item);
|
2015-07-13 14:26:11 -07:00
|
|
|
|
return Task.FromResult(ItemUpdateType.MetadataImport);
|
2014-10-14 17:05:09 -07:00
|
|
|
|
}
|
2015-06-28 18:10:45 -07:00
|
|
|
|
|
|
|
|
|
var prober = new FFProbeVideoInfo(_logger, _isoManager, _mediaEncoder, _itemRepo, _blurayExaminer, _localization, _appPaths, _json, _encodingManager, _fileSystem, _config, _subtitleManager, _chapterManager, _libraryManager);
|
2014-02-04 13:19:29 -07:00
|
|
|
|
|
2014-06-09 12:16:14 -07:00
|
|
|
|
return prober.ProbeVideo(item, options, cancellationToken);
|
2014-02-04 13:19:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-14 17:05:09 -07:00
|
|
|
|
private void FetchShortcutInfo(Video video)
|
|
|
|
|
{
|
2015-09-13 14:32:02 -07:00
|
|
|
|
video.ShortcutPath = _fileSystem.ReadAllText(video.Path);
|
2014-10-14 17:05:09 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-05 21:39:16 -07:00
|
|
|
|
public Task<ItemUpdateType> FetchAudioInfo<T>(T item, CancellationToken cancellationToken)
|
|
|
|
|
where T : Audio
|
|
|
|
|
{
|
|
|
|
|
if (item.LocationType != LocationType.FileSystem)
|
|
|
|
|
{
|
|
|
|
|
return _cachedTask;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-28 18:10:45 -07:00
|
|
|
|
var prober = new FFProbeAudioInfo(_mediaEncoder, _itemRepo, _appPaths, _json, _libraryManager);
|
2014-02-05 21:39:16 -07:00
|
|
|
|
|
|
|
|
|
return prober.Probe(item, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-08 11:32:38 -07:00
|
|
|
|
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService)
|
2014-02-04 13:19:29 -07:00
|
|
|
|
{
|
2016-08-23 23:13:15 -07:00
|
|
|
|
if (item.EnableRefreshOnDateModifiedChange && !string.IsNullOrWhiteSpace(item.Path) && item.LocationType == LocationType.FileSystem)
|
2014-02-10 11:39:41 -07:00
|
|
|
|
{
|
2016-08-10 20:56:14 -07:00
|
|
|
|
var file = directoryService.GetFile(item.Path);
|
|
|
|
|
if (file != null && file.LastWriteTimeUtc != item.DateModified)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-08-28 17:49:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-10 13:11:46 -07:00
|
|
|
|
if (item.SupportsLocalMetadata)
|
2014-02-10 11:39:41 -07:00
|
|
|
|
{
|
|
|
|
|
var video = item as Video;
|
|
|
|
|
|
2014-03-02 22:11:03 -07:00
|
|
|
|
if (video != null && !video.IsPlaceHolder)
|
2014-02-10 11:39:41 -07:00
|
|
|
|
{
|
2014-06-09 12:16:14 -07:00
|
|
|
|
return !video.SubtitleFiles
|
2014-07-26 10:30:15 -07:00
|
|
|
|
.SequenceEqual(SubtitleResolver.GetSubtitleFiles(video, directoryService, _fileSystem, false)
|
2014-06-09 12:16:14 -07:00
|
|
|
|
.OrderBy(i => i), StringComparer.OrdinalIgnoreCase);
|
2014-02-10 11:39:41 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2014-02-04 13:19:29 -07:00
|
|
|
|
}
|
2014-02-08 16:44:49 -07:00
|
|
|
|
|
|
|
|
|
public int Order
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
// Run last
|
|
|
|
|
return 100;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-04 13:19:29 -07:00
|
|
|
|
}
|
|
|
|
|
}
|