From 27259c1ebd64d3f17388058160572b7ed2c0b627 Mon Sep 17 00:00:00 2001 From: Sean A Date: Fri, 8 Oct 2021 16:58:20 +0800 Subject: [PATCH] Fixed: Ensure AudioTag years have default values (#1272) * Fixed: Ensure AudioTagService years have default values * Fix AudioTagServiceFixture.cs tests Co-authored-by: Sean Anderson --- .../MediaFiles/AudioTagServiceFixture.cs | 29 ++++++++++++++----- .../MediaFiles/AudioTagService.cs | 4 +-- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/NzbDrone.Core.Test/MediaFiles/AudioTagServiceFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/AudioTagServiceFixture.cs index b01bca7c2..b7ac1279c 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/AudioTagServiceFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/AudioTagServiceFixture.cs @@ -17,14 +17,13 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture { [TestFixture] - [Ignore("Readarr doesn't currently support audio")] public class AudioTagServiceFixture : CoreTest { public static class TestCaseFactory { private static readonly string[] MediaFiles = new[] { "nin.mp2", "nin.mp3", "nin.flac", "nin.m4a", "nin.wma", "nin.ape", "nin.opus" }; - private static readonly string[] SkipProperties = new[] { "IsValid", "Duration", "Quality", "MediaInfo", "ImageFile" }; + private static readonly string[] SkipProperties = new[] { "IsValid", "Duration", "Quality", "MediaInfo", "ImageFile", "BookAuthors" }; private static readonly Dictionary SkipPropertiesByFile = new Dictionary { { "nin.mp2", new[] { "OriginalReleaseDate" } } @@ -194,6 +193,9 @@ public void should_read_write_tags(string filename, string[] skipProperties) var writtentags = Subject.ReadAudioTag(path); VerifySame(writtentags, _testTags, skipProperties); + writtentags.BookAuthors.Should().BeEquivalentTo( + _testTags.BookAuthors.Concat(_testTags.Performers), + options => options.WithStrictOrdering()); } [Test] @@ -337,12 +339,12 @@ public void get_metadata_should_not_fail_with_missing_country() [Test] public void should_not_fail_if_media_has_been_omitted() { - // make sure that we aren't relying on index of items in - // Media being the same as the medium number - var file = GivenPopulatedTrackfile(100); - var tag = Subject.GetTrackMetadata(file); + GivenFileCopy("nin.mp3"); - tag.Media.Should().NotBeNull(); + var file = GivenPopulatedTrackfile(100); + file.Path = _copiedFile; + + Assert.DoesNotThrow(() => Subject.GetTrackMetadata(file)); } [TestCase("nin.mp3")] @@ -363,5 +365,18 @@ public void write_tags_should_update_trackfile_size_and_modified(string filename file.Modified.Should().Be(fileInfo.LastWriteTimeUtc); file.Size.Should().Be(fileInfo.Length); } + + [Test] + public void should_not_fail_reading_metadata_with_dates_omitted() + { + GivenFileCopy("nin.mp3"); + + var bookFile = GivenPopulatedTrackfile(0); + bookFile.Path = _copiedFile; + bookFile.Edition.Value.ReleaseDate = null; + bookFile.Edition.Value.Book.Value.ReleaseDate = null; + + Assert.DoesNotThrow(() => Subject.GetTrackMetadata(bookFile)); + } } } diff --git a/src/NzbDrone.Core/MediaFiles/AudioTagService.cs b/src/NzbDrone.Core/MediaFiles/AudioTagService.cs index 5317f54ed..18bc20648 100644 --- a/src/NzbDrone.Core/MediaFiles/AudioTagService.cs +++ b/src/NzbDrone.Core/MediaFiles/AudioTagService.cs @@ -108,9 +108,9 @@ public AudioTag GetTrackMetadata(BookFile trackfile) // We may have omitted media so index in the list isn't the same as medium number Media = fileTags.Media, Date = edition.ReleaseDate, - Year = (uint)edition.ReleaseDate?.Year, + Year = (uint)(edition.ReleaseDate?.Year ?? 0), OriginalReleaseDate = book.ReleaseDate, - OriginalYear = (uint)book.ReleaseDate?.Year, + OriginalYear = (uint)(book.ReleaseDate?.Year ?? 0), Publisher = edition.Publisher, Genres = new string[0], ImageFile = imageFile,