A .NET Deezer API wrapper and track downloading library. There's a CLI tool in there as well.
This is a fork of TrevTV/DeezNET. The upstream repository's last change was in May 2025, and its maintainer isn't merging pull requests. This fork keeps the library working for Lidarr.Plugin.Deezer, which builds it from source as a submodule.
The NuGet badge above and the package on NuGet are TrevTV's release (1.2.1). This fork isn't published to NuGet. Reference it as a project or submodule instead.
The main differences from upstream:
- Decrypted tracks no longer end with leftover bytes from the previous block.
- The library retries a failed session or expired ARL once, then reports it, instead of retrying without limit.
- Download failures report Deezer's error code instead of writing an error page to disk as audio.
- The library can tag tracks with MusicBrainz IDs.
Changes
- The repository moved to
matrix-runout/DeezNET. The MusicBrainz user agent now links to the new address.
Fixes
- When the session expires during concurrent requests, the library refreshes the token once and the other requests reuse it. Before, each request refreshed it separately, sending a burst of
deezer.getUserDatacalls at once.SetARLalways refreshes, so a new ARL gets its own session. - Downloading without an ARL throws
InvalidARLExceptioninstead of aNullReferenceException. - HTTP responses are disposed after use, which returns their connections to the pool sooner.
UnshortenURLfollows any redirect status, not only 302.- Cancelling during the MusicBrainz lookup cancels the operation instead of being treated as a failed lookup.
- MusicBrainz searches escape backslashes in artist and album names.
ApplyMetadataToTrackStreamreads all four format bytes even when the stream returns them in parts, so it no longer misdetects a FLAC as an MP3.RemoveSongsFromPlaylistandRemoveSongFromPlaylistpass their cancellation token to the request.- The MusicBrainz user agent takes its version from the assembly, so it no longer needs updating by hand.
Fixes
PublicApiretries a quota error (codes 4 and 700) up to three times, then throwsAPIException. 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.
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, andGetRawTrackStreamheld the track in memory twice. A stalled connection now fails withTimeoutExceptionafterDownloader.ReadTimeout(60 seconds by default) without data. GetArtBytesthrowsUnavailableArtExceptionfor any unsuccessful CDN response and for an empty art ID. Before, only a 401 threw, and other error pages were embedded in tracks as cover art.- A release date of
0000-00-00no longer stops a track from being tagged. The year falls back to the album's release dates, and is left out if none are valid. - Tracks are tagged with their disc number. On multi-disc albums, the track count and disc count are per disc when Deezer returns the full track list. Before, tracks with the same number on different discs got identical tags.
New
Decryption.DecodeTrackStreamAsyncdecodes without blocking and supports cancellation and a read timeout.
Maintenance
- Pull requests and pushes to
mainbuild the solution and run the tests. Tests taggedLivecall Deezer and only run locally. - CodeQL scans the C# code and the workflows on every pull request and weekly.
- Pull requests fail if they add a dependency with a high or critical advisory.
- Dependabot also updates the pinned GitHub Actions, and groups test package updates into one pull request.
Fixes
DecodeTrackStreamwrote the whole 6144-byte buffer on every pass, so most tracks ended with up to 6143 stale bytes. It now writes only the bytes it read and keeps the stripe alignment when the stream returns short reads. From TrevTV/DeezNET#4.- When Deezer rejected the session token,
GWApirefreshed it and retried with no limit, and refreshing from insidedeezer.getUserDatarecursed. It now retries once after a short delay, never refreshes from insidedeezer.getUserData, and throwsInvalidARLExceptionif the retry fails. - A media URL request that returns errors refreshes the license token once, then throws
APIExceptionwith Deezer's error code. NoSourcesAvailableExceptionincludes Deezer's per-track error code and message, which explains rights and region restrictions.- A non-success response from the CDN throws instead of the library decrypting it and saving it as audio.
WriteRawTrackToFilecreates the output file only after the download starts successfully. SetARLreturns early when given a blank ARL instead of setting it anyway.
New
- MusicBrainz ID tagging:
ApplyMetadataToFileaccepts aMusicBrainzIdsvalue and writes release, release group, artist, release artist, and recording IDs. From TrevTV/DeezNET#3 by jtstothard. MusicBrainzIds.RecordingIdsets the recording ID for the current track. It takes precedence overTrackRecordingIds, which uses per-disc track numbers as keys and collides on multi-disc releases.- The blind MusicBrainz search runs only when the caller passes no
MusicBrainzIdsvalue. Pass an empty one to opt out. - Requests send a browser User-Agent.
Maintenance
- Dependabot opens weekly NuGet update pull requests.
- Builds fail on high or critical NuGet advisories, including transitive packages.
If you would like this repository to be taken down, please send me a cease and desist.
You may e-mail it to me here: [email protected].
Or go through the standard GitHub DMCA procedure, but that isn't as fun.
- Newtonsoft.Json for every API call
- BouncyCastle.Cryptography for decrypting track data (
client.Downloader.GetRawTrackBytes()) - TagLibSharp for applying metadata to decrypted track data (
client.Downloader.ApplyMetadataToTrackBytes())
DeezNET is built around a core class, DeezerClient. That class itself does very little, under it is Downloader, GWApi, and PublicApi.
Downloaderprovides functions for downloading tracks by their ID, as well as applying metadata. It requires an ARL supplied toDeezerClientto function.GWApiis a wrapper for the backend API used by Deezer. It requires an ARL supplied toDeezerClientto function.PublicApiis a wrapper for the public Deezer API. It does not require an ARL.
All API calls return a Newtonsoft.JSON JToken as I did not want to deal with parsing everything into model classes since there are many different API endpoints.
In addition to DeezerClient, there is DeezerURL which is a class for parsing Deezer URLs into their entity type and ID. It also handles unshortening the standard Deezer share URLs (deezer.page.link).
var client = new DeezerClient();
var trackData = await client.PublicApi.GetTrack(1903638027);
Console.WriteLine($"{trackData["title"]!} by {trackData["contributors"]!.First()["name"]!}");
// Output: Let You Down by Dawid Podsiadłovar client = new DeezerClient();
await client.SetARL("[ARL]");
var trackData = await client.GWApi.GetTrack(1903638027);
Console.WriteLine($"{trackData["SNG_TITLE"]!} by {trackData["ART_NAME"]!}");
// Output: Let You Down by Dawid Podsiadłovar client = new DeezerClient();
await client.SetARL("[ARL]");
var trackBytes = await client.Downloader.GetRawTrackBytes(1903638027, DeezNET.Data.Bitrate.FLAC);
trackBytes = await client.Downloader.ApplyMetadataToTrackBytes(1903638027, trackBytes); // if you want metadata
File.WriteAllBytes(Path.Combine(Environment.CurrentDirectory, "LYD.flac"), trackBytes);
// Saves a metadata-applied FLAC of Let You Down by Dawid Podsiadło to your current working directoryvar client = new DeezerClient();
await client.SetARL("[ARL]");
var urlData = DeezerURL.Parse("https://deezer.page.link/uwdUFsjkJbGkngSm7"); // this is a short URL, can also be a full one like "https://www.deezer.com/us/album/548556802"
var tracksInAlbum = await urlData.GetAssociatedTracks(client);
foreach (var track in tracksInAlbum)
{
var trackBytes = await client.Downloader.GetRawTrackBytes(track, DeezNET.Data.Bitrate.FLAC);
trackBytes = await client.Downloader.ApplyMetadataToTrackBytes(track, trackBytes); // if you want metadata
File.WriteAllBytes(Path.Combine(Environment.CurrentDirectory, $"{track}.flac"), trackBytes);
}
// Saves metadata-applied FLACs of every track in GLOOM DIVISION by I DONT KNOW HOW BUT THEY FOUND ME to your current working directoryUSAGE
DeezCLI <url> [options]
DESCRIPTION
Downloads the given URL.
PARAMETERS
* url The URL of the item to download. Can be a shortened URL.
OPTIONS
-b|--bitrate The preferred bitrate when downloading. Falls back to a lower quality if unavailable. Choices: "MP3_128", "MP3_320", "FLAC". Default: "FLAC".
-m|--add-metadata Whether to attach metadata to the downloaded audio file. Default: "True".
-L|--add-sync-lyrics Specifies whether to add a synced lyrics file to the download directory. Default: "False".
-B|--add-lrclib-lyrics Specifies whether to fetch lyrics from LRCLIB if available. Default: "False".
-o|--output The directory to save downloaded media to. Default: "E:\Projects\GitHub\DeezNET\DeezCLI\bin\Release\net8.0".
-a|--arl The account ARL to download with. A paid plan allows for higher quality downloads. Some regions do not have full tracks available without a premium account. Default: "".
-l|--top-limit The max amount of tracks to download. Only applicable when downloading an artist's top tracks. Default: "100".
-c|--concurrent The max amount of allowed concurrent track downloads. Default: "3".
-d|--folder-template The folder path template to use when saving tracks to file. Default: "%albumartist%/%album%/".
-f|--file-template The file path template to use when saving tracks to file. Default: "%track% - %title%.%ext%".
-h|--help Shows help text.
--version Shows version information.
AVAILABLE TEMPLATE VARIABLES
%title%
%album%
%albumartist%
%artist%
%albumartists%
%artists%
%track%
%trackcount%
%trackid%
%albumid%
%artistid%
%ext%
%year%
- This project is heavily based on deemix-py and deezer-py, both under the GNU GPLv3 License.