Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions DeezNET.Tests/MetadataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
13 changes: 12 additions & 1 deletion DeezNET/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
{
Expand Down