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
2 changes: 1 addition & 1 deletion DeezNET/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>1.2.4</Version>
<Version>1.2.5</Version>
<Company>TrevTV</Company>
<Copyright>Copyright (C) Trevor Jackson</Copyright>
<LangVersion>latest</LangVersion>
Expand Down
14 changes: 11 additions & 3 deletions DeezNET/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,15 @@ private async Task ApplyMetadataToTagLibFile(TagLib.File track, long trackId, in
JToken page = await _gw.GetTrackPage(trackId, token);
long albumId = long.Parse(page["DATA"]!["ALB_ID"]!.ToString());
JToken albumPage = await _gw.GetAlbumPage(albumId, token);
JToken publicAlbum = await _publicApi.GetAlbum(albumId, token: token);

// the public API is only needed for genres, so a quota error or missing genre list shouldn't fail the whole tag write
string[]? genres = null;
try
{
JToken publicAlbum = await _publicApi.GetAlbum(albumId, token: token);
genres = (publicAlbum["genres"]?["data"] as JArray)?.Select(a => a["name"]?.ToString()).OfType<string>().ToArray();
}
catch (Exception e) when (e is not OperationCanceledException) { }

byte[]? albumArt = null;
try { albumArt = await GetArtBytes(page["DATA"]!["ALB_PICTURE"]!.ToString(), coverResolution, token); } catch (UnavailableArtException) { }
Expand Down Expand Up @@ -377,8 +385,8 @@ private async Task ApplyMetadataToTagLibFile(TagLib.File track, long trackId, in
// the song list is incomplete or has no disc numbers, so per-disc counts can't be trusted; keep the album total
track.Tag.TrackCount = albumTrackCount;
}
// i have yet to find an album without a genre attached, but this may still break at some point
track.Tag.Genres = publicAlbum["genres"]!["data"]!.Select(a => a["name"]!.ToString()).ToArray();
if (genres != null)
track.Tag.Genres = genres;

if (albumArt != null)
track.Tag.Pictures = [new TagLib.Picture(new TagLib.ByteVector(albumArt))];
Expand Down
2 changes: 1 addition & 1 deletion DeezNET/MusicBrainzLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class MusicBrainzLookup
public MusicBrainzLookup(HttpClient? client = null, string? userAgent = null)
{
_client = client ?? new HttpClient();
_userAgent = userAgent ?? "DeezNET/1.2.4 (https://github.com/jasonpatrickellykrause/DeezNET)";
_userAgent = userAgent ?? "DeezNET/1.2.5 (https://github.com/jasonpatrickellykrause/DeezNET)";
}

/// <summary>
Expand Down
13 changes: 10 additions & 3 deletions DeezNET/PublicApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,10 @@ public async Task<JToken> SearchTrack(string query, bool strict = false, SearchO
public async Task<JToken> SearchUser(string query, bool strict = false, SearchOrder? order = null, int index = 0, int limit = 25, CancellationToken token = default)
=> await Call("search/user", PublicApi.GenerateSearchArgs(query, strict, order, index, limit), token);

private async Task<JToken> Call(string method, Dictionary<string, string>? parameters = null, CancellationToken token = default)
private const int MAX_QUOTA_RETRIES = 3;
private static readonly TimeSpan QUOTA_RETRY_DELAY = TimeSpan.FromSeconds(5);

private async Task<JToken> Call(string method, Dictionary<string, string>? parameters = null, CancellationToken token = default, int quotaRetries = 0)
{
parameters ??= [];

Expand Down Expand Up @@ -397,8 +400,12 @@ private async Task<JToken> Call(string method, Dictionary<string, string>? param
case 4:
case 700:
{
await Task.Delay(5000, token);
return await Call(method, parameters, token);
// quota exceeded; retrying without a limit kept a caller waiting forever while Deezer kept refusing
if (quotaRetries >= MAX_QUOTA_RETRIES)
throw new APIException($"Deezer's public API refused {method} with error {err} after {MAX_QUOTA_RETRIES} retries: {message}");

await Task.Delay(QUOTA_RETRY_DELAY, token);
return await Call(method, parameters, token, quotaRetries + 1);
}
case 100:
throw new ItemsLimitExceededException(message ?? "");
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ The main differences from upstream:

## Changelog

### 1.2.5
**Fixes**
- `PublicApi` retries a quota error (codes 4 and 700) up to three times, then throws `APIException`. Before, it retried every 5 seconds with no limit, so a caller waited until Deezer stopped refusing.
- Tagging no longer fails or stalls when the public API can't return the album's genres. The track is tagged without genres. Tagging calls the public API only for genres, once per track.

### 1.2.4
**Fixes**
- Track downloads stream from the CDN instead of loading the whole file before decrypting it. Before, `HttpClient`'s 100-second timeout covered the entire download, so large FLACs on slow connections failed, and `GetRawTrackStream` held the track in memory twice. A stalled connection now fails with `TimeoutException` after `Downloader.ReadTimeout` (60 seconds by default) without data.
Expand Down