2021-10-26 13:49:01 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2020-06-19 18:24:13 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 20:03:10 +00:00
|
|
|
using System;
|
2019-01-26 21:31:59 +00:00
|
|
|
using System.IO;
|
2019-01-13 19:26:31 +00:00
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2021-11-27 11:10:57 +00:00
|
|
|
using Emby.Naming.Common;
|
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;
|
2014-02-06 04:39:16 +00:00
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2014-02-04 20:19:29 +00:00
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
using MediaBrowser.Controller.Library;
|
2014-02-20 16:37:41 +00:00
|
|
|
using MediaBrowser.Controller.MediaEncoding;
|
2014-02-04 20:19:29 +00:00
|
|
|
using MediaBrowser.Controller.Persistence;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2014-05-07 02:28:19 +00:00
|
|
|
using MediaBrowser.Controller.Subtitles;
|
2014-02-04 20:19:29 +00:00
|
|
|
using MediaBrowser.Model.Entities;
|
2019-01-13 19:26:31 +00:00
|
|
|
using MediaBrowser.Model.Globalization;
|
2014-02-04 20:19:29 +00:00
|
|
|
using MediaBrowser.Model.MediaInfo;
|
2019-01-13 19:26:31 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
2014-02-04 20:19:29 +00:00
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.MediaInfo
|
|
|
|
{
|
|
|
|
public class FFProbeProvider : ICustomMetadataProvider<Episode>,
|
2014-02-06 04:39:16 +00:00
|
|
|
ICustomMetadataProvider<MusicVideo>,
|
|
|
|
ICustomMetadataProvider<Movie>,
|
2016-05-07 21:01:21 +00:00
|
|
|
ICustomMetadataProvider<Trailer>,
|
2014-02-06 04:39:16 +00:00
|
|
|
ICustomMetadataProvider<Video>,
|
|
|
|
ICustomMetadataProvider<Audio>,
|
2017-01-07 20:52:56 +00:00
|
|
|
ICustomMetadataProvider<AudioBook>,
|
2014-02-19 05:21:03 +00:00
|
|
|
IHasOrder,
|
2015-03-05 06:34:36 +00:00
|
|
|
IForcedProvider,
|
2018-09-12 17:26:21 +00:00
|
|
|
IPreRefreshProvider,
|
|
|
|
IHasItemChangeMonitor
|
2014-02-04 20:19:29 +00:00
|
|
|
{
|
2020-06-06 00:15:56 +00:00
|
|
|
private readonly ILogger<FFProbeProvider> _logger;
|
2020-09-07 11:20:39 +00:00
|
|
|
private readonly SubtitleResolver _subtitleResolver;
|
2021-12-07 19:16:32 +00:00
|
|
|
private readonly AudioResolver _audioResolver;
|
2021-12-02 10:21:59 +00:00
|
|
|
private readonly FFProbeVideoInfo _videoProber;
|
|
|
|
private readonly FFProbeAudioInfo _audioProber;
|
2020-09-07 11:20:39 +00:00
|
|
|
|
|
|
|
private readonly Task<ItemUpdateType> _cachedTask = Task.FromResult(ItemUpdateType.None);
|
2021-11-27 11:10:57 +00:00
|
|
|
|
2020-09-07 11:20:39 +00:00
|
|
|
public FFProbeProvider(
|
|
|
|
ILogger<FFProbeProvider> logger,
|
|
|
|
IMediaSourceManager mediaSourceManager,
|
|
|
|
IMediaEncoder mediaEncoder,
|
|
|
|
IItemRepository itemRepo,
|
|
|
|
IBlurayExaminer blurayExaminer,
|
|
|
|
ILocalizationManager localization,
|
|
|
|
IEncodingManager encodingManager,
|
|
|
|
IServerConfigurationManager config,
|
|
|
|
ISubtitleManager subtitleManager,
|
|
|
|
IChapterManager chapterManager,
|
2021-11-27 11:10:57 +00:00
|
|
|
ILibraryManager libraryManager,
|
|
|
|
NamingOptions namingOptions)
|
2020-09-07 11:20:39 +00:00
|
|
|
{
|
|
|
|
_logger = logger;
|
2021-12-07 19:16:32 +00:00
|
|
|
_audioResolver = new AudioResolver(localization, mediaEncoder, namingOptions);
|
2020-09-07 11:20:39 +00:00
|
|
|
_subtitleResolver = new SubtitleResolver(BaseItem.LocalizationManager);
|
2021-12-02 10:21:59 +00:00
|
|
|
_videoProber = new FFProbeVideoInfo(
|
|
|
|
_logger,
|
|
|
|
mediaSourceManager,
|
|
|
|
mediaEncoder,
|
|
|
|
itemRepo,
|
|
|
|
blurayExaminer,
|
|
|
|
localization,
|
|
|
|
encodingManager,
|
|
|
|
config,
|
|
|
|
subtitleManager,
|
|
|
|
chapterManager,
|
|
|
|
libraryManager);
|
|
|
|
_audioProber = new FFProbeAudioInfo(mediaSourceManager, mediaEncoder, itemRepo, libraryManager);
|
2020-09-07 11:20:39 +00:00
|
|
|
}
|
2014-02-06 04:39:16 +00:00
|
|
|
|
2019-01-13 20:31:14 +00:00
|
|
|
public string Name => "ffprobe";
|
2014-02-04 20:19:29 +00:00
|
|
|
|
2020-09-07 11:20:39 +00:00
|
|
|
// Run last
|
|
|
|
public int Order => 100;
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
public bool HasChanged(BaseItem item, IDirectoryService directoryService)
|
2014-02-04 20:19:29 +00:00
|
|
|
{
|
2018-09-12 17:26:21 +00: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)
|
|
|
|
{
|
2021-11-28 13:03:52 +00:00
|
|
|
_logger.LogDebug("Refreshing {ItemPath} due to date modified timestamp change.", path);
|
2018-09-12 17:26:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-27 09:20:05 +00:00
|
|
|
if (item.SupportsLocalMetadata && video != null && !video.IsPlaceHolder
|
|
|
|
&& !video.SubtitleFiles.SequenceEqual(
|
|
|
|
_subtitleResolver.GetExternalSubtitleFiles(video, directoryService, false), StringComparer.Ordinal))
|
2018-09-12 17:26:21 +00:00
|
|
|
{
|
2021-11-28 13:03:52 +00:00
|
|
|
_logger.LogDebug("Refreshing {ItemPath} due to external subtitles change.", item.Path);
|
2019-01-27 09:20:05 +00:00
|
|
|
return true;
|
2021-11-22 20:47:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (item.SupportsLocalMetadata && video != null && !video.IsPlaceHolder
|
|
|
|
&& !video.AudioFiles.SequenceEqual(
|
2021-11-28 13:03:52 +00:00
|
|
|
_audioResolver.GetExternalAudioFiles(video, directoryService, false), StringComparer.Ordinal))
|
2021-11-22 20:47:52 +00:00
|
|
|
{
|
2021-11-28 13:03:52 +00:00
|
|
|
_logger.LogDebug("Refreshing {ItemPath} due to external audio change.", item.Path);
|
2021-11-22 20:47:52 +00:00
|
|
|
return true;
|
2018-09-12 17:26:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2014-02-04 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
public Task<ItemUpdateType> FetchAsync(Episode item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-04 20:19:29 +00:00
|
|
|
{
|
2014-06-09 19:16:14 +00:00
|
|
|
return FetchVideoInfo(item, options, cancellationToken);
|
2014-02-04 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
public Task<ItemUpdateType> FetchAsync(MusicVideo item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-04 20:19:29 +00:00
|
|
|
{
|
2014-06-09 19:16:14 +00:00
|
|
|
return FetchVideoInfo(item, options, cancellationToken);
|
2014-02-04 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
public Task<ItemUpdateType> FetchAsync(Movie item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-04 20:19:29 +00:00
|
|
|
{
|
2014-06-09 19:16:14 +00:00
|
|
|
return FetchVideoInfo(item, options, cancellationToken);
|
2014-02-04 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2016-05-07 21:01:21 +00:00
|
|
|
public Task<ItemUpdateType> FetchAsync(Trailer item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
return FetchVideoInfo(item, options, cancellationToken);
|
|
|
|
}
|
|
|
|
|
2014-06-09 19:16:14 +00:00
|
|
|
public Task<ItemUpdateType> FetchAsync(Video item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-06 04:39:16 +00:00
|
|
|
{
|
2014-06-09 19:16:14 +00:00
|
|
|
return FetchVideoInfo(item, options, cancellationToken);
|
2014-02-06 04:39:16 +00:00
|
|
|
}
|
|
|
|
|
2014-06-09 19:16:14 +00:00
|
|
|
public Task<ItemUpdateType> FetchAsync(Audio item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-06 04:39:16 +00:00
|
|
|
{
|
2018-09-12 17:26:21 +00:00
|
|
|
return FetchAudioInfo(item, options, cancellationToken);
|
2017-01-07 20:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Task<ItemUpdateType> FetchAsync(AudioBook item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-06 04:39:16 +00:00
|
|
|
{
|
2018-09-12 17:26:21 +00:00
|
|
|
return FetchAudioInfo(item, options, cancellationToken);
|
2014-02-06 04:39:16 +00:00
|
|
|
}
|
|
|
|
|
2014-06-09 19:16:14 +00:00
|
|
|
public Task<ItemUpdateType> FetchVideoInfo<T>(T item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-04 20:19:29 +00:00
|
|
|
where T : Video
|
|
|
|
{
|
2018-09-12 17:26:21 +00:00
|
|
|
if (item.IsPlaceHolder)
|
2014-02-04 20:19:29 +00:00
|
|
|
{
|
|
|
|
return _cachedTask;
|
|
|
|
}
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
if (!item.IsCompleteMedia)
|
2014-03-03 05:11:03 +00:00
|
|
|
{
|
|
|
|
return _cachedTask;
|
|
|
|
}
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
if (item.IsVirtualItem)
|
|
|
|
{
|
|
|
|
return _cachedTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!options.EnableRemoteContentProbe && !item.IsFileProtocol)
|
2017-09-18 16:52:22 +00:00
|
|
|
{
|
|
|
|
return _cachedTask;
|
|
|
|
}
|
|
|
|
|
2014-10-15 00:05:09 +00:00
|
|
|
if (item.IsShortcut)
|
|
|
|
{
|
|
|
|
FetchShortcutInfo(item);
|
|
|
|
}
|
2015-06-29 01:10:45 +00:00
|
|
|
|
2021-12-02 10:21:59 +00:00
|
|
|
return _videoProber.ProbeVideo(item, options, cancellationToken);
|
2014-02-04 20:19:29 +00:00
|
|
|
}
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
private string NormalizeStrmLine(string line)
|
2014-10-15 00:05:09 +00:00
|
|
|
{
|
2020-08-07 17:26:28 +00:00
|
|
|
return line.Replace("\t", string.Empty, StringComparison.Ordinal)
|
|
|
|
.Replace("\r", string.Empty, StringComparison.Ordinal)
|
|
|
|
.Replace("\n", string.Empty, StringComparison.Ordinal)
|
2017-11-01 19:50:16 +00:00
|
|
|
.Trim();
|
2014-10-15 00:05:09 +00:00
|
|
|
}
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
private void FetchShortcutInfo(BaseItem item)
|
|
|
|
{
|
2019-01-26 21:31:59 +00:00
|
|
|
item.ShortcutPath = File.ReadAllLines(item.Path)
|
2018-09-12 17:26:21 +00:00
|
|
|
.Select(NormalizeStrmLine)
|
2020-12-02 14:38:52 +00:00
|
|
|
.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i) && !i.StartsWith('#'));
|
2018-09-12 17:26:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Task<ItemUpdateType> FetchAudioInfo<T>(T item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
2014-02-06 04:39:16 +00:00
|
|
|
where T : Audio
|
|
|
|
{
|
2018-09-12 17:26:21 +00:00
|
|
|
if (item.IsVirtualItem)
|
|
|
|
{
|
|
|
|
return _cachedTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!options.EnableRemoteContentProbe && !item.IsFileProtocol)
|
2014-02-06 04:39:16 +00:00
|
|
|
{
|
|
|
|
return _cachedTask;
|
|
|
|
}
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
if (item.IsShortcut)
|
|
|
|
{
|
|
|
|
FetchShortcutInfo(item);
|
|
|
|
}
|
|
|
|
|
2021-12-02 10:21:59 +00:00
|
|
|
return _audioProber.Probe(item, options, cancellationToken);
|
2014-02-06 04:39:16 +00:00
|
|
|
}
|
2014-02-04 20:19:29 +00:00
|
|
|
}
|
|
|
|
}
|