diff --git a/DeezNET.Tests/MetadataTests.cs b/DeezNET.Tests/MetadataTests.cs index 0386b6b..720fd40 100644 --- a/DeezNET.Tests/MetadataTests.cs +++ b/DeezNET.Tests/MetadataTests.cs @@ -28,5 +28,26 @@ public void ParseYearTreatsMissingDateAsMissing() { Downloader.ParseYear(null).ShouldBeNull(); } + + [Fact] + public void TrackTitleIncludesTheVersion() + { + var data = new JObject { ["SNG_TITLE"] = "Watch The Sunrise", ["VERSION"] = "(Axwell Remode)" }; + + Downloader.TrackTitle(data).ShouldBe("Watch The Sunrise (Axwell Remode)"); + } + + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData(" ")] + public void TrackTitleWithoutAVersionIsTheTitle(string? version) + { + var data = new JObject { ["SNG_TITLE"] = "Watch The Sunrise" }; + if (version != null) + data["VERSION"] = version; + + Downloader.TrackTitle(data).ShouldBe("Watch The Sunrise"); + } } } diff --git a/DeezNET/Downloader.cs b/DeezNET/Downloader.cs index 51ecdb0..146ed10 100644 --- a/DeezNET/Downloader.cs +++ b/DeezNET/Downloader.cs @@ -369,7 +369,7 @@ private async Task ApplyMetadataToTagLibFile(TagLib.File track, long trackId, in byte[]? albumArt = null; try { albumArt = await GetArtBytes(page["DATA"]!["ALB_PICTURE"]!.ToString(), coverResolution, token); } catch (UnavailableArtException) { } - track.Tag.Title = page["DATA"]!["SNG_TITLE"]!.ToString(); + track.Tag.Title = TrackTitle(page["DATA"]!); track.Tag.Album = page["DATA"]!["ALB_TITLE"]!.ToString(); track.Tag.Performers = page["DATA"]!["ARTISTS"]!.Select(a => a["ART_NAME"]!.ToString()).ToArray(); track.Tag.AlbumArtists = albumPage["DATA"]!["ARTISTS"]!.Select(a => a["ART_NAME"]!.ToString()).ToArray(); @@ -499,6 +499,17 @@ private async Task ApplyMetadataToTagLibFile(TagLib.File track, long trackId, in track.Save(); } + // Deezer keeps a track's mix or edit apart from its title: SNG_TITLE "Watch The Sunrise", VERSION "(Axwell Remode)". + // Without the version every track of a remix release is tagged with the same title, and Lidarr, which matches + // tracks by title, can only tell them apart by length. + internal static string TrackTitle(JToken data) + { + string title = data["SNG_TITLE"]!.ToString(); + string? version = data["VERSION"]?.ToString().Trim(); + + return string.IsNullOrEmpty(version) ? title : $"{title} {version}"; + } + // reads the year from a yyyy-MM-dd date, treating 0000 and anything unparseable as missing internal static uint? ParseYear(JToken? date) {