jellyfin-server/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs

203 lines
7.5 KiB
C#
Raw Normal View History

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