Просмотр исходного кода

Improve metadata probing to better support music videos

Maxr1998 4 лет назад
Родитель
Сommit
24ac8a1223

+ 56 - 39
MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs

@@ -121,19 +121,67 @@ namespace MediaBrowser.MediaEncoding.Probing
             {
                 info.Name = title;
             }
+            else
+            {
+                title = FFProbeHelpers.GetDictionaryValue(tags, "title-eng");
+                if (!string.IsNullOrWhiteSpace(title))
+                {
+                    info.Name = title;
+                }
+            }
+
+            var titleSort = FFProbeHelpers.GetDictionaryValue(tags, "titlesort");
+            if (!string.IsNullOrWhiteSpace(titleSort))
+            {
+                info.ForcedSortName = titleSort;
+            }
 
             info.IndexNumber = FFProbeHelpers.GetDictionaryNumericValue(tags, "episode_sort");
             info.ParentIndexNumber = FFProbeHelpers.GetDictionaryNumericValue(tags, "season_number");
             info.ShowName = FFProbeHelpers.GetDictionaryValue(tags, "show_name");
             info.ProductionYear = FFProbeHelpers.GetDictionaryNumericValue(tags, "date");
 
-            // Several different forms of retaildate
-            info.PremiereDate = FFProbeHelpers.GetDictionaryDateTime(tags, "retaildate") ??
+            // Several different forms of retail/premiere date
+            info.PremiereDate =
+                FFProbeHelpers.GetDictionaryDateTime(tags, "retaildate") ??
                 FFProbeHelpers.GetDictionaryDateTime(tags, "retail date") ??
                 FFProbeHelpers.GetDictionaryDateTime(tags, "retail_date") ??
                 FFProbeHelpers.GetDictionaryDateTime(tags, "date_released") ??
                 FFProbeHelpers.GetDictionaryDateTime(tags, "date");
 
+            // Set common metadata for music (audio) and music videos (video)
+            info.Album = FFProbeHelpers.GetDictionaryValue(tags, "album");
+
+            var artists = FFProbeHelpers.GetDictionaryValue(tags, "artists");
+
+            if (!string.IsNullOrWhiteSpace(artists))
+            {
+                info.Artists = SplitArtists(artists, new[] { '/', ';' }, false)
+                    .DistinctNames()
+                    .ToArray();
+            }
+            else
+            {
+                var artist = FFProbeHelpers.GetDictionaryValue(tags, "artist");
+                if (string.IsNullOrWhiteSpace(artist))
+                {
+                    info.Artists = Array.Empty<string>();
+                }
+                else
+                {
+                    info.Artists = SplitArtists(artist, _nameDelimiters, true)
+                        .DistinctNames()
+                        .ToArray();
+                }
+            }
+
+            // If we don't have a ProductionYear try and get it from PremiereDate
+            if (!info.ProductionYear.HasValue && info.PremiereDate.HasValue)
+            {
+                info.ProductionYear = info.PremiereDate.Value.Year;
+            }
+
+            // Set mediaType-specific metadata
             if (isAudio)
             {
                 SetAudioRuntimeTicks(data, info);
@@ -1076,13 +1124,13 @@ namespace MediaBrowser.MediaEncoding.Probing
 
         private void SetAudioInfoFromTags(MediaInfo audio, Dictionary<string, string> tags)
         {
-            var peoples = new List<BaseItemPerson>();
+            var people = new List<BaseItemPerson>();
             var composer = FFProbeHelpers.GetDictionaryValue(tags, "composer");
             if (!string.IsNullOrWhiteSpace(composer))
             {
                 foreach (var person in Split(composer, false))
                 {
-                    peoples.Add(new BaseItemPerson { Name = person, Type = PersonType.Composer });
+                    people.Add(new BaseItemPerson { Name = person, Type = PersonType.Composer });
                 }
             }
 
@@ -1091,7 +1139,7 @@ namespace MediaBrowser.MediaEncoding.Probing
             {
                 foreach (var person in Split(conductor, false))
                 {
-                    peoples.Add(new BaseItemPerson { Name = person, Type = PersonType.Conductor });
+                    people.Add(new BaseItemPerson { Name = person, Type = PersonType.Conductor });
                 }
             }
 
@@ -1100,46 +1148,21 @@ namespace MediaBrowser.MediaEncoding.Probing
             {
                 foreach (var person in Split(lyricist, false))
                 {
-                    peoples.Add(new BaseItemPerson { Name = person, Type = PersonType.Lyricist });
+                    people.Add(new BaseItemPerson { Name = person, Type = PersonType.Lyricist });
                 }
             }
 
             // Check for writer some music is tagged that way as alternative to composer/lyricist
             var writer = FFProbeHelpers.GetDictionaryValue(tags, "writer");
-
             if (!string.IsNullOrWhiteSpace(writer))
             {
                 foreach (var person in Split(writer, false))
                 {
-                    peoples.Add(new BaseItemPerson { Name = person, Type = PersonType.Writer });
+                    people.Add(new BaseItemPerson { Name = person, Type = PersonType.Writer });
                 }
             }
 
-            audio.People = peoples.ToArray();
-            audio.Album = FFProbeHelpers.GetDictionaryValue(tags, "album");
-
-            var artists = FFProbeHelpers.GetDictionaryValue(tags, "artists");
-
-            if (!string.IsNullOrWhiteSpace(artists))
-            {
-                audio.Artists = SplitArtists(artists, new[] { '/', ';' }, false)
-                    .DistinctNames()
-                    .ToArray();
-            }
-            else
-            {
-                var artist = FFProbeHelpers.GetDictionaryValue(tags, "artist");
-                if (string.IsNullOrWhiteSpace(artist))
-                {
-                    audio.Artists = Array.Empty<string>();
-                }
-                else
-                {
-                    audio.Artists = SplitArtists(artist, _nameDelimiters, true)
-                    .DistinctNames()
-                        .ToArray();
-                }
-            }
+            audio.People = people.ToArray();
 
             var albumArtist = FFProbeHelpers.GetDictionaryValue(tags, "albumartist");
             if (string.IsNullOrWhiteSpace(albumArtist))
@@ -1174,12 +1197,6 @@ namespace MediaBrowser.MediaEncoding.Probing
             // Disc number
             audio.ParentIndexNumber = GetDictionaryDiscValue(tags, "disc");
 
-            // If we don't have a ProductionYear try and get it from PremiereDate
-            if (audio.PremiereDate.HasValue && !audio.ProductionYear.HasValue)
-            {
-                audio.ProductionYear = audio.PremiereDate.Value.ToLocalTime().Year;
-            }
-
             // There's several values in tags may or may not be present
             FetchStudios(audio, tags, "organization");
             FetchStudios(audio, tags, "ensemble");

+ 2 - 0
MediaBrowser.Model/MediaInfo/MediaInfo.cs

@@ -51,6 +51,8 @@ namespace MediaBrowser.Model.MediaInfo
 
         public string ShowName { get; set; }
 
+        public string ForcedSortName { get; set; }
+
         public int? IndexNumber { get; set; }
 
         public int? ParentIndexNumber { get; set; }

+ 5 - 0
MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs

@@ -111,6 +111,11 @@ namespace MediaBrowser.Providers.MediaInfo
                 audio.Name = data.Name;
             }
 
+            if (!string.IsNullOrEmpty(data.ForcedSortName))
+            {
+                audio.ForcedSortName = data.ForcedSortName;
+            }
+
             if (audio.SupportsPeople && !audio.LockedFields.Contains(MetadataField.Cast))
             {
                 var people = new List<PersonInfo>();

+ 11 - 0
MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs

@@ -394,6 +394,12 @@ namespace MediaBrowser.Providers.MediaInfo
                 }
             }
 
+            if (video is MusicVideo musicVideo)
+            {
+                musicVideo.Album = data.Album;
+                musicVideo.Artists = data.Artists;
+            }
+
             if (data.ProductionYear.HasValue)
             {
                 if (!video.ProductionYear.HasValue || isFullRefresh)
@@ -436,6 +442,11 @@ namespace MediaBrowser.Providers.MediaInfo
                         video.Name = data.Name;
                     }
                 }
+
+                if (!string.IsNullOrWhiteSpace(data.ForcedSortName))
+                {
+                    video.ForcedSortName = data.ForcedSortName;
+                }
             }
 
             // If we don't have a ProductionYear try and get it from PremiereDate