Explorar o código

Merge pull request #6262 from MrTimscampi/scanner-prefer-original-date

Claus Vium %!s(int64=3) %!d(string=hai) anos
pai
achega
408d5c78a9

+ 2 - 1
MediaBrowser.MediaEncoding/Probing/FFProbeHelpers.cs

@@ -63,7 +63,8 @@ namespace MediaBrowser.MediaEncoding.Probing
         public static DateTime? GetDictionaryDateTime(IReadOnlyDictionary<string, string> tags, string key)
         {
             if (tags.TryGetValue(key, out var val)
-                && DateTime.TryParse(val, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.AssumeUniversal, out var dateTime))
+                && (DateTime.TryParse(val, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.AssumeUniversal, out var dateTime)
+                    || DateTime.TryParseExact(val, "yyyy", DateTimeFormatInfo.CurrentInfo, DateTimeStyles.AssumeUniversal, out dateTime)))
             {
                 return dateTime.ToUniversalTime();
             }

+ 1 - 0
MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs

@@ -121,6 +121,7 @@ namespace MediaBrowser.MediaEncoding.Probing
 
             // Several different forms of retail/premiere date
             info.PremiereDate =
+                FFProbeHelpers.GetDictionaryDateTime(tags, "originaldate") ??
                 FFProbeHelpers.GetDictionaryDateTime(tags, "retaildate") ??
                 FFProbeHelpers.GetDictionaryDateTime(tags, "retail date") ??
                 FFProbeHelpers.GetDictionaryDateTime(tags, "retail_date") ??

+ 20 - 0
tests/Jellyfin.MediaEncoding.Tests/Probing/ProbeResultNormalizerTests.cs

@@ -71,5 +71,25 @@ namespace Jellyfin.MediaEncoding.Tests.Probing
             Assert.True(res.PremiereDate.HasValue);
             Assert.Equal(DateTime.Parse("2021-01-01T00:00Z", DateTimeFormatInfo.CurrentInfo).ToUniversalTime(), res.PremiereDate);
         }
+
+        [Fact]
+        public void GetMediaInfo_GivenOriginalDateContainsOnlyYear_Success()
+        {
+            var bytes = File.ReadAllBytes("Test Data/Probing/music_year_only_metadata.json");
+            var internalMediaInfoResult = JsonSerializer.Deserialize<InternalMediaInfoResult>(bytes, _jsonOptions);
+            MediaInfo res = _probeResultNormalizer.GetMediaInfo(internalMediaInfoResult, null, true, "Test Data/Probing/music.flac", MediaProtocol.File);
+
+            Assert.Equal("Baker Street", res.Name);
+            Assert.Single(res.Artists);
+            Assert.Equal("Gerry Rafferty", res.Artists[0]);
+            Assert.Equal("City to City", res.Album);
+            Assert.Equal(1978, res.ProductionYear);
+            Assert.True(res.PremiereDate.HasValue);
+            Assert.Equal(DateTime.Parse("1978-01-01T00:00Z", DateTimeFormatInfo.CurrentInfo).ToUniversalTime(), res.PremiereDate);
+            Assert.Contains("Electronic", res.Genres);
+            Assert.Contains("Ambient", res.Genres);
+            Assert.Contains("Pop", res.Genres);
+            Assert.Contains("Jazz", res.Genres);
+        }
     }
 }

+ 147 - 0
tests/Jellyfin.MediaEncoding.Tests/Test Data/Probing/music_year_only_metadata.json

@@ -0,0 +1,147 @@
+{
+    "streams": [
+        {
+            "index": 0,
+            "codec_name": "flac",
+            "codec_long_name": "FLAC (Free Lossless Audio Codec)",
+            "codec_type": "audio",
+            "codec_tag_string": "[0][0][0][0]",
+            "codec_tag": "0x0000",
+            "sample_fmt": "s16",
+            "sample_rate": "44100",
+            "channels": 2,
+            "channel_layout": "stereo",
+            "bits_per_sample": 0,
+            "r_frame_rate": "0/0",
+            "avg_frame_rate": "0/0",
+            "time_base": "1/44100",
+            "start_pts": 0,
+            "start_time": "0.000000",
+            "duration_ts": 16394616,
+            "duration": "371.760000",
+            "bits_per_raw_sample": "16",
+            "disposition": {
+                "default": 0,
+                "dub": 0,
+                "original": 0,
+                "comment": 0,
+                "lyrics": 0,
+                "karaoke": 0,
+                "forced": 0,
+                "hearing_impaired": 0,
+                "visual_impaired": 0,
+                "clean_effects": 0,
+                "attached_pic": 0,
+                "timed_thumbnails": 0
+            }
+        },
+        {
+            "index": 1,
+            "codec_name": "mjpeg",
+            "codec_long_name": "Motion JPEG",
+            "profile": "Baseline",
+            "codec_type": "video",
+            "codec_tag_string": "[0][0][0][0]",
+            "codec_tag": "0x0000",
+            "width": 500,
+            "height": 498,
+            "coded_width": 500,
+            "coded_height": 498,
+            "closed_captions": 0,
+            "has_b_frames": 0,
+            "sample_aspect_ratio": "1:1",
+            "display_aspect_ratio": "250:249",
+            "pix_fmt": "yuvj420p",
+            "level": -99,
+            "color_range": "pc",
+            "color_space": "bt470bg",
+            "chroma_location": "center",
+            "refs": 1,
+            "r_frame_rate": "90000/1",
+            "avg_frame_rate": "0/0",
+            "time_base": "1/90000",
+            "start_pts": 0,
+            "start_time": "0.000000",
+            "duration_ts": 33458400,
+            "duration": "371.760000",
+            "bits_per_raw_sample": "8",
+            "disposition": {
+                "default": 0,
+                "dub": 0,
+                "original": 0,
+                "comment": 0,
+                "lyrics": 0,
+                "karaoke": 0,
+                "forced": 0,
+                "hearing_impaired": 0,
+                "visual_impaired": 0,
+                "clean_effects": 0,
+                "attached_pic": 1,
+                "timed_thumbnails": 0
+            },
+            "tags": {
+                "comment": "Cover (front)"
+            }
+        }
+    ],
+    "format": {
+        "filename": "02 Baker Street.flac",
+        "nb_streams": 2,
+        "nb_programs": 0,
+        "format_name": "flac",
+        "format_long_name": "raw FLAC",
+        "start_time": "0.000000",
+        "duration": "371.760000",
+        "size": "37072649",
+        "bit_rate": "797775",
+        "probe_score": 100,
+        "tags": {
+            "MUSICBRAINZ_RELEASEGROUPID": "238c3fb4-5792-342b-b217-02f66298b424",
+            "ORIGINALDATE": "1978",
+            "ORIGINALYEAR": "1978",
+            "RELEASETYPE": "album",
+            "MUSICBRAINZ_ALBUMID": "30156786-e511-3106-ac95-66f0e880b24b",
+            "ASIN": "B000007O5H",
+            "MUSICBRAINZ_ALBUMARTISTID": "563201cb-721c-4cfb-acca-c1ba69e3d1fb",
+            "album_artist": "Gerry Rafferty",
+            "ALBUMARTISTSORT": "Rafferty, Gerry",
+            "LABEL": "Liberty EMI Records UK",
+            "CATALOGNUMBER": "CDP 7 46049 2",
+            "DATE": "1989-07-26",
+            "RELEASECOUNTRY": "GB",
+            "BARCODE": "077774604925",
+            "ALBUM": "City to City",
+            "SCRIPT": "Latn",
+            "RELEASESTATUS": "official",
+            "TOTALDISCS": "1",
+            "disc": "1",
+            "MEDIA": "CD",
+            "TOTALTRACKS": "10",
+            "MUSICBRAINZ_TRACKID": "9235e22e-afbd-48f7-b329-21dae6da2810",
+            "ISRC": "GBAYE1100924;GBAYE7800619",
+            "PERFORMER": "Hugh Burns (electric guitar);Nigel Jenkins (electric guitar);Tommy Eyre (keyboard and Moog);Glen LeFleur (percussion);Raphael Ravenscroft (saxophone);Henry Spinetti (drums (drum set));Gary Taylor (bass);Gerry Rafferty (lead vocals)",
+            "ARRANGER": "Graham Preskett",
+            "MIXER": "Declan O’Doherty",
+            "PRODUCER": "Hugh Murphy;Gerry Rafferty",
+            "MUSICBRAINZ_WORKID": "a9eb3c45-784c-3c32-860c-4b406f03961b",
+            "LANGUAGE": "eng",
+            "WORK": "Baker Street",
+            "COMPOSER": "Gerry Rafferty",
+            "COMPOSERSORT": "Rafferty, Gerry",
+            "LYRICIST": "Gerry Rafferty",
+            "TITLE": "Baker Street",
+            "MUSICBRAINZ_ARTISTID": "563201cb-721c-4cfb-acca-c1ba69e3d1fb",
+            "ARTIST": "Gerry Rafferty",
+            "ARTISTSORT": "Rafferty, Gerry",
+            "ARTISTS": "Gerry Rafferty",
+            "MUSICBRAINZ_RELEASETRACKID": "407cf7f7-440d-3e76-8b89-8686198868ea",
+            "track": "2",
+            "GENRE": "Electronic;Ambient;Pop;Jazz",
+            "WEBSITE": "http://www.gerryrafferty.com/",
+            "ACOUSTID_ID": "68f8d979-a659-4aa0-a216-eb3721a951eb",
+            "MOOD": "Acoustic;Not aggressive;Not electronic;Not happy;Party;Relaxed;Not sad",
+            "TRACKTOTAL": "10",
+            "DISCTOTAL": "1"
+        }
+    }
+}