From 1e147580729e24fbb6d8707d2a0ddfc8bd036d43 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Wed, 6 Dec 2023 19:25:18 +0200 Subject: [PATCH] Fixed: Don't write audio tags if there are no updates --- .../MediaFiles/AudioTagServiceFixture.cs | 42 +++++++++++++++---- .../MediaFiles/AudioTagService.cs | 6 +++ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/NzbDrone.Core.Test/MediaFiles/AudioTagServiceFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/AudioTagServiceFixture.cs index 4099b95d3..1b155c1df 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/AudioTagServiceFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/AudioTagServiceFixture.cs @@ -5,11 +5,14 @@ using System.IO; using System.Linq; using FizzWare.NBuilder; using FluentAssertions; +using Moq; using NUnit.Framework; using NzbDrone.Common.Disk; using NzbDrone.Common.Extensions; using NzbDrone.Core.Configuration; using NzbDrone.Core.MediaFiles; +using NzbDrone.Core.MediaFiles.Events; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Music; using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common; @@ -166,7 +169,7 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture } [Test] - [TestCaseSource(typeof(TestCaseFactory), "TestCases")] + [TestCaseSource(typeof(TestCaseFactory), nameof(TestCaseFactory.TestCases))] public void should_read_duration(string filename, string[] ignored) { var path = Path.Combine(_testdir, filename); @@ -177,7 +180,7 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture } [Test] - [TestCaseSource(typeof(TestCaseFactory), "TestCases")] + [TestCaseSource(typeof(TestCaseFactory), nameof(TestCaseFactory.TestCases))] public void should_read_write_tags(string filename, string[] skipProperties) { GivenFileCopy(filename); @@ -195,7 +198,7 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture } [Test] - [TestCaseSource(typeof(TestCaseFactory), "TestCases")] + [TestCaseSource(typeof(TestCaseFactory), nameof(TestCaseFactory.TestCases))] public void should_remove_mb_tags(string filename, string[] skipProperties) { GivenFileCopy(filename); @@ -229,7 +232,7 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture } [Test] - [TestCaseSource(typeof(TestCaseFactory), "TestCases")] + [TestCaseSource(typeof(TestCaseFactory), nameof(TestCaseFactory.TestCases))] public void should_read_audiotag_from_file_with_no_tags(string filename, string[] skipProperties) { GivenFileCopy(filename); @@ -251,7 +254,7 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture } [Test] - [TestCaseSource(typeof(TestCaseFactory), "TestCases")] + [TestCaseSource(typeof(TestCaseFactory), nameof(TestCaseFactory.TestCases))] public void should_read_parsedtrackinfo_from_file_with_no_tags(string filename, string[] skipProperties) { GivenFileCopy(filename); @@ -266,7 +269,7 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture } [Test] - [TestCaseSource(typeof(TestCaseFactory), "TestCases")] + [TestCaseSource(typeof(TestCaseFactory), nameof(TestCaseFactory.TestCases))] public void should_set_quality_and_mediainfo_for_corrupt_file(string filename, string[] skipProperties) { // use missing to simulate corrupt @@ -281,7 +284,7 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture } [Test] - [TestCaseSource(typeof(TestCaseFactory), "TestCases")] + [TestCaseSource(typeof(TestCaseFactory), nameof(TestCaseFactory.TestCases))] public void should_read_file_with_only_title_tag(string filename, string[] ignored) { GivenFileCopy(filename); @@ -301,7 +304,7 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture } [Test] - [TestCaseSource(typeof(TestCaseFactory), "TestCases")] + [TestCaseSource(typeof(TestCaseFactory), nameof(TestCaseFactory.TestCases))] public void should_remove_date_from_tags_when_not_in_metadata(string filename, string[] ignored) { GivenFileCopy(filename); @@ -413,6 +416,29 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture var fileInfo = _diskProvider.GetFileInfo(file.Path); file.Modified.Should().Be(fileInfo.LastWriteTimeUtc); file.Size.Should().Be(fileInfo.Length); + + Mocker.GetMock() + .Verify(v => v.PublishEvent(It.IsAny()), Times.Once()); + } + + [TestCase("nin.mp3")] + public void write_tags_should_not_update_tags_if_already_updated(string filename) + { + Mocker.GetMock() + .Setup(x => x.ScrubAudioTags) + .Returns(true); + + GivenFileCopy(filename); + + var file = GivenPopulatedTrackfile(0); + + file.Path = _copiedFile; + Subject.WriteTags(file, false, true); + Subject.WriteTags(file, false, true); + Subject.WriteTags(file, false, true); + + Mocker.GetMock() + .Verify(v => v.PublishEvent(It.IsAny()), Times.Once()); } } } diff --git a/src/NzbDrone.Core/MediaFiles/AudioTagService.cs b/src/NzbDrone.Core/MediaFiles/AudioTagService.cs index 82d1e1274..abb727111 100644 --- a/src/NzbDrone.Core/MediaFiles/AudioTagService.cs +++ b/src/NzbDrone.Core/MediaFiles/AudioTagService.cs @@ -220,6 +220,12 @@ namespace NzbDrone.Core.MediaFiles var diff = oldTags.Diff(newTags); + if (!diff.Any()) + { + _logger.Debug("No tags update for {0} due to no difference", trackfile); + return; + } + _rootFolderWatchingService.ReportFileSystemChangeBeginning(path); if (_configService.ScrubAudioTags)