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-13 19:26:31 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2013-02-21 01:33:05 +00:00
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2014-02-06 04:39:16 +00:00
|
|
|
using MediaBrowser.Controller.Library;
|
2014-02-20 16:37:41 +00:00
|
|
|
using MediaBrowser.Controller.MediaEncoding;
|
2013-12-06 03:39:44 +00:00
|
|
|
using MediaBrowser.Controller.Persistence;
|
2019-01-13 19:26:31 +00:00
|
|
|
using MediaBrowser.Controller.Providers;
|
2015-04-05 15:01:57 +00:00
|
|
|
using MediaBrowser.Model.Dlna;
|
2019-01-13 19:26:31 +00:00
|
|
|
using MediaBrowser.Model.Dto;
|
2013-02-21 01:33:05 +00:00
|
|
|
using MediaBrowser.Model.Entities;
|
2014-06-17 01:56:23 +00:00
|
|
|
using MediaBrowser.Model.MediaInfo;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2013-06-09 16:47:28 +00:00
|
|
|
namespace MediaBrowser.Providers.MediaInfo
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2020-06-19 18:24:13 +00:00
|
|
|
public class FFProbeAudioInfo
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2014-02-06 04:39:16 +00:00
|
|
|
private readonly IMediaEncoder _mediaEncoder;
|
2013-12-06 03:39:44 +00:00
|
|
|
private readonly IItemRepository _itemRepo;
|
2015-06-28 17:00:36 +00:00
|
|
|
private readonly ILibraryManager _libraryManager;
|
2018-09-12 17:26:21 +00:00
|
|
|
private readonly IMediaSourceManager _mediaSourceManager;
|
2013-12-06 03:39:44 +00:00
|
|
|
|
2020-08-07 17:26:28 +00:00
|
|
|
public FFProbeAudioInfo(
|
|
|
|
IMediaSourceManager mediaSourceManager,
|
|
|
|
IMediaEncoder mediaEncoder,
|
|
|
|
IItemRepository itemRepo,
|
|
|
|
ILibraryManager libraryManager)
|
2013-03-02 17:59:15 +00:00
|
|
|
{
|
2014-02-06 04:39:16 +00:00
|
|
|
_mediaEncoder = mediaEncoder;
|
2013-12-06 03:39:44 +00:00
|
|
|
_itemRepo = itemRepo;
|
2015-06-28 17:00:36 +00:00
|
|
|
_libraryManager = libraryManager;
|
2018-09-12 17:26:21 +00:00
|
|
|
_mediaSourceManager = mediaSourceManager;
|
2013-03-02 17:59:15 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 11:20:39 +00:00
|
|
|
public async Task<ItemUpdateType> Probe<T>(
|
|
|
|
T item,
|
|
|
|
MetadataRefreshOptions options,
|
2018-09-12 17:26:21 +00:00
|
|
|
CancellationToken cancellationToken)
|
2014-02-06 04:39:16 +00:00
|
|
|
where T : Audio
|
2013-06-18 19:16:27 +00:00
|
|
|
{
|
2018-09-12 17:26:21 +00:00
|
|
|
var path = item.Path;
|
|
|
|
var protocol = item.PathProtocol ?? MediaProtocol.File;
|
2013-06-18 19:16:27 +00:00
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
if (!item.IsShortcut || options.EnableRemoteContentProbe)
|
|
|
|
{
|
|
|
|
if (item.IsShortcut)
|
|
|
|
{
|
|
|
|
path = item.ShortcutPath;
|
|
|
|
protocol = _mediaSourceManager.GetPathProtocol(path);
|
|
|
|
}
|
2013-06-18 19:16:27 +00:00
|
|
|
|
2020-09-07 11:20:39 +00:00
|
|
|
var result = await _mediaEncoder.GetMediaInfo(
|
|
|
|
new MediaInfoRequest
|
2018-09-12 17:26:21 +00:00
|
|
|
{
|
2020-09-07 11:20:39 +00:00
|
|
|
MediaType = DlnaProfileType.Audio,
|
|
|
|
MediaSource = new MediaSourceInfo
|
|
|
|
{
|
|
|
|
Path = path,
|
|
|
|
Protocol = protocol
|
|
|
|
}
|
|
|
|
},
|
|
|
|
cancellationToken).ConfigureAwait(false);
|
2014-02-06 04:39:16 +00:00
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
2014-02-09 21:11:11 +00:00
|
|
|
|
2020-09-07 11:20:39 +00:00
|
|
|
Fetch(item, result, cancellationToken);
|
2018-09-12 17:26:21 +00:00
|
|
|
}
|
2014-02-09 21:11:11 +00:00
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
return ItemUpdateType.MetadataImport;
|
2013-06-18 19:16:27 +00:00
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Fetches the specified audio.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="audio">The audio.</param>
|
2015-04-04 19:35:29 +00:00
|
|
|
/// <param name="mediaInfo">The media information.</param>
|
2020-09-07 11:20:39 +00:00
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
protected void Fetch(Audio audio, Model.MediaInfo.MediaInfo mediaInfo, CancellationToken cancellationToken)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2017-08-04 20:29:34 +00:00
|
|
|
audio.Container = mediaInfo.Container;
|
2015-04-04 19:35:29 +00:00
|
|
|
audio.TotalBitrate = mediaInfo.Bitrate;
|
2013-12-06 03:39:44 +00:00
|
|
|
|
2015-04-04 19:35:29 +00:00
|
|
|
audio.RunTimeTicks = mediaInfo.RunTimeTicks;
|
|
|
|
audio.Size = mediaInfo.Size;
|
2013-05-15 04:05:52 +00:00
|
|
|
|
2020-06-14 09:11:11 +00:00
|
|
|
// var extension = (Path.GetExtension(audio.Path) ?? string.Empty).TrimStart('.');
|
|
|
|
// audio.Container = extension;
|
2014-01-11 23:07:56 +00:00
|
|
|
|
2017-08-27 00:32:33 +00:00
|
|
|
FetchDataFromTags(audio, mediaInfo);
|
2013-12-06 03:39:44 +00:00
|
|
|
|
2022-01-22 14:40:05 +00:00
|
|
|
_itemRepo.SaveMediaStreams(audio.Id, mediaInfo.MediaStreams, cancellationToken);
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-06-15 22:37:52 +00:00
|
|
|
/// Fetches data from the tags dictionary.
|
2013-02-21 01:33:05 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="audio">The audio.</param>
|
2015-04-04 19:35:29 +00:00
|
|
|
/// <param name="data">The data.</param>
|
2017-08-27 00:32:33 +00:00
|
|
|
private void FetchDataFromTags(Audio audio, Model.MediaInfo.MediaInfo data)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
|
|
|
// Only set Name if title was found in the dictionary
|
2016-02-18 02:55:15 +00:00
|
|
|
if (!string.IsNullOrEmpty(data.Name))
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2016-02-18 02:55:15 +00:00
|
|
|
audio.Name = data.Name;
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
2021-04-04 21:34:29 +00:00
|
|
|
if (!string.IsNullOrEmpty(data.ForcedSortName))
|
|
|
|
{
|
|
|
|
audio.ForcedSortName = data.ForcedSortName;
|
|
|
|
}
|
|
|
|
|
2020-06-09 22:12:53 +00:00
|
|
|
if (audio.SupportsPeople && !audio.LockedFields.Contains(MetadataField.Cast))
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2015-06-28 17:00:36 +00:00
|
|
|
var people = new List<PersonInfo>();
|
2013-08-29 21:00:27 +00:00
|
|
|
|
2015-04-04 19:35:29 +00:00
|
|
|
foreach (var person in data.People)
|
2013-08-04 00:59:23 +00:00
|
|
|
{
|
2015-06-28 17:00:36 +00:00
|
|
|
PeopleHelper.AddPerson(people, new PersonInfo
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2015-04-04 19:35:29 +00:00
|
|
|
Name = person.Name,
|
|
|
|
Type = person.Type,
|
|
|
|
Role = person.Role
|
|
|
|
});
|
2015-01-27 22:45:59 +00:00
|
|
|
}
|
2015-06-28 17:00:36 +00:00
|
|
|
|
2017-08-27 00:32:33 +00:00
|
|
|
_libraryManager.UpdatePeople(audio, people);
|
2015-03-13 01:55:22 +00:00
|
|
|
}
|
2014-06-23 16:05:19 +00:00
|
|
|
|
2015-04-04 19:35:29 +00:00
|
|
|
audio.Album = data.Album;
|
2017-08-24 19:52:19 +00:00
|
|
|
audio.Artists = data.Artists;
|
2015-04-04 19:35:29 +00:00
|
|
|
audio.AlbumArtists = data.AlbumArtists;
|
|
|
|
audio.IndexNumber = data.IndexNumber;
|
2015-04-09 17:30:18 +00:00
|
|
|
audio.ParentIndexNumber = data.ParentIndexNumber;
|
2015-04-04 19:35:29 +00:00
|
|
|
audio.ProductionYear = data.ProductionYear;
|
|
|
|
audio.PremiereDate = data.PremiereDate;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
// If we don't have a ProductionYear try and get it from PremiereDate
|
|
|
|
if (audio.PremiereDate.HasValue && !audio.ProductionYear.HasValue)
|
|
|
|
{
|
2013-04-12 18:22:40 +00:00
|
|
|
audio.ProductionYear = audio.PremiereDate.Value.ToLocalTime().Year;
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-09 22:12:53 +00:00
|
|
|
if (!audio.LockedFields.Contains(MetadataField.Genres))
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2018-09-12 17:26:21 +00:00
|
|
|
audio.Genres = Array.Empty<string>();
|
2013-04-28 05:44:45 +00:00
|
|
|
|
2015-04-04 19:35:29 +00:00
|
|
|
foreach (var genre in data.Genres)
|
2013-04-28 05:44:45 +00:00
|
|
|
{
|
2013-09-05 22:59:07 +00:00
|
|
|
audio.AddGenre(genre);
|
2013-04-28 05:44:45 +00:00
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-09 22:12:53 +00:00
|
|
|
if (!audio.LockedFields.Contains(MetadataField.Studios))
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2017-08-09 19:56:38 +00:00
|
|
|
audio.SetStudios(data.Studios);
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-06 19:17:49 +00:00
|
|
|
audio.SetProviderId(MetadataProvider.MusicBrainzAlbumArtist, data.GetProviderId(MetadataProvider.MusicBrainzAlbumArtist));
|
|
|
|
audio.SetProviderId(MetadataProvider.MusicBrainzArtist, data.GetProviderId(MetadataProvider.MusicBrainzArtist));
|
|
|
|
audio.SetProviderId(MetadataProvider.MusicBrainzAlbum, data.GetProviderId(MetadataProvider.MusicBrainzAlbum));
|
|
|
|
audio.SetProviderId(MetadataProvider.MusicBrainzReleaseGroup, data.GetProviderId(MetadataProvider.MusicBrainzReleaseGroup));
|
|
|
|
audio.SetProviderId(MetadataProvider.MusicBrainzTrack, data.GetProviderId(MetadataProvider.MusicBrainzTrack));
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
2014-02-06 04:39:16 +00:00
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|