diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs b/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs index 25ca792ac1..f2f1663e46 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs @@ -8,6 +8,7 @@ using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Entities; using MediaBrowser.Model.MediaInfo; using MediaBrowser.Model.Serialization; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; @@ -22,15 +23,17 @@ namespace MediaBrowser.Providers.MediaInfo private readonly IItemRepository _itemRepo; private readonly IApplicationPaths _appPaths; private readonly IJsonSerializer _json; + private readonly ILibraryManager _libraryManager; private readonly CultureInfo _usCulture = new CultureInfo("en-US"); - public FFProbeAudioInfo(IMediaEncoder mediaEncoder, IItemRepository itemRepo, IApplicationPaths appPaths, IJsonSerializer json) + public FFProbeAudioInfo(IMediaEncoder mediaEncoder, IItemRepository itemRepo, IApplicationPaths appPaths, IJsonSerializer json, ILibraryManager libraryManager) { _mediaEncoder = mediaEncoder; _itemRepo = itemRepo; _appPaths = appPaths; _json = json; + _libraryManager = libraryManager; } public async Task Probe(T item, CancellationToken cancellationToken) @@ -96,7 +99,7 @@ namespace MediaBrowser.Providers.MediaInfo /// The cancellation token. /// The media information. /// Task. - protected Task Fetch(Audio audio, CancellationToken cancellationToken, Model.MediaInfo.MediaInfo mediaInfo) + protected async Task Fetch(Audio audio, CancellationToken cancellationToken, Model.MediaInfo.MediaInfo mediaInfo) { var mediaStreams = mediaInfo.MediaStreams; @@ -110,9 +113,9 @@ namespace MediaBrowser.Providers.MediaInfo var extension = (Path.GetExtension(audio.Path) ?? string.Empty).TrimStart('.'); audio.Container = extension; - FetchDataFromTags(audio, mediaInfo); + await FetchDataFromTags(audio, mediaInfo).ConfigureAwait(false); - return _itemRepo.SaveMediaStreams(audio.Id, mediaStreams, cancellationToken); + await _itemRepo.SaveMediaStreams(audio.Id, mediaStreams, cancellationToken).ConfigureAwait(false); } /// @@ -120,7 +123,7 @@ namespace MediaBrowser.Providers.MediaInfo /// /// The audio. /// The data. - private void FetchDataFromTags(Audio audio, Model.MediaInfo.MediaInfo data) + private async Task FetchDataFromTags(Audio audio, Model.MediaInfo.MediaInfo data) { // Only set Name if title was found in the dictionary if (!string.IsNullOrEmpty(data.Title)) @@ -130,17 +133,19 @@ namespace MediaBrowser.Providers.MediaInfo if (!audio.LockedFields.Contains(MetadataFields.Cast)) { - audio.People.Clear(); + var people = new List(); foreach (var person in data.People) { - PeopleHelper.AddPerson(audio.People, new PersonInfo + PeopleHelper.AddPerson(people, new PersonInfo { Name = person.Name, Type = person.Type, Role = person.Role }); } + + await _libraryManager.UpdatePeople(audio, people).ConfigureAwait(false); } audio.Album = data.Album; diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs index f141fbd599..395d95cc57 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs @@ -46,10 +46,11 @@ namespace MediaBrowser.Providers.MediaInfo private readonly IServerConfigurationManager _config; private readonly ISubtitleManager _subtitleManager; private readonly IChapterManager _chapterManager; + private readonly ILibraryManager _libraryManager; private readonly CultureInfo _usCulture = new CultureInfo("en-US"); - public FFProbeVideoInfo(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) + public FFProbeVideoInfo(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; @@ -64,6 +65,7 @@ namespace MediaBrowser.Providers.MediaInfo _config = config; _subtitleManager = subtitleManager; _chapterManager = chapterManager; + _libraryManager = libraryManager; } public async Task ProbeVideo(T item, @@ -219,6 +221,7 @@ namespace MediaBrowser.Providers.MediaInfo await AddExternalSubtitles(video, mediaStreams, options, cancellationToken).ConfigureAwait(false); FetchEmbeddedInfo(video, mediaInfo, options); + await FetchPeople(video, mediaInfo, options).ConfigureAwait(false); video.IsHD = mediaStreams.Any(i => i.Type == MediaStreamType.Video && i.Width.HasValue && i.Width.Value >= 1270); @@ -370,24 +373,6 @@ namespace MediaBrowser.Providers.MediaInfo } } - if (!video.LockedFields.Contains(MetadataFields.Cast)) - { - if (video.People.Count == 0 || isFullRefresh) - { - video.People.Clear(); - - foreach (var person in data.People) - { - PeopleHelper.AddPerson(video.People, new PersonInfo - { - Name = person.Name, - Type = person.Type, - Role = person.Role - }); - } - } - } - if (!video.LockedFields.Contains(MetadataFields.Genres)) { if (video.Genres.Count == 0 || isFullRefresh) @@ -458,6 +443,31 @@ namespace MediaBrowser.Providers.MediaInfo } } + private async Task FetchPeople(Video video, Model.MediaInfo.MediaInfo data, MetadataRefreshOptions options) + { + var isFullRefresh = options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh; + + if (!video.LockedFields.Contains(MetadataFields.Cast)) + { + if (isFullRefresh || _libraryManager.GetPeople(video).Count == 0) + { + var people = new List(); + + foreach (var person in data.People) + { + PeopleHelper.AddPerson(people, new PersonInfo + { + Name = person.Name, + Type = person.Type, + Role = person.Role + }); + } + + await _libraryManager.UpdatePeople(video, people); + } + } + } + private SubtitleOptions GetOptions() { return _config.GetConfiguration("subtitles"); diff --git a/MediaBrowser.Providers/TV/TvdbEpisodeProvider.cs b/MediaBrowser.Providers/TV/TvdbEpisodeProvider.cs index db5bc3b657..b8ef6e5ae3 100644 --- a/MediaBrowser.Providers/TV/TvdbEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/TvdbEpisodeProvider.cs @@ -314,11 +314,6 @@ namespace MediaBrowser.Providers.TV { using (var streamReader = new StreamReader(xmlFile, Encoding.UTF8)) { - if (!item.LockedFields.Contains(MetadataFields.Cast)) - { - item.People.Clear(); - } - // Use XmlReader for best performance using (var reader = XmlReader.Create(streamReader, new XmlReaderSettings {