Skip to content

Commit

Permalink
fix deezer arl support
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Aug 8, 2024
1 parent 645b6fc commit 503d81b
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 114 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,16 @@ follow [this guide](https://developer.apple.com/help/account/configure-app-capab
AudioPlayerManager playerManager = new DefaultAudioPlayerManager();

// create a new DeezerSourceManager with the master decryption key and register it
playerManager.registerSourceManager(new DeezerSourceManager("...");
playerManager.registerSourceManager(new DeezerSourceManager("...", "your arl", formats);
```

<details>
<summary>How to get deezer arl cookie</summary>

Use google to find a guide on how to get the arl cookie. It's not that hard.
</details>
#### Yandex Music
<details>
Expand Down Expand Up @@ -212,6 +219,8 @@ To get your Spotify spDc cookie go [here](#spotify)
To get your Apple Music api token go [here](#apple-music)
To get your Deezer arl cookie go [here](#deezer)
To get your Yandex Music access token go [here](#yandex-music)
(YES `plugins` IS AT ROOT IN THE YAML)
Expand Down Expand Up @@ -258,6 +267,8 @@ plugins:
albumLoadLimit: 6 # The number of pages at 300 tracks each
deezer:
masterDecryptionKey: "your master decryption key" # the master key used for decrypting the deezer tracks. (yes this is not here you need to get it from somewhere else)
arl: "your deezer arl" # the arl cookie used for accessing the deezer api
formats: [ "FLAC", "MP3_320", "MP3_256", "MP3_128", "MP3_64", "AAC_64" ] # the formats you want to use for the deezer tracks. "FLAC", "MP3_320", "MP3_256" & "AAC_64" are only available for premium users and require a valid arl
yandexmusic:
accessToken: "your access token" # the token used for accessing the yandex music api. See https://github.com/TopiSenpai/LavaSrc#yandex-music
playlistLoadLimit: 1 # The number of pages at 100 tracks each
Expand Down
2 changes: 2 additions & 0 deletions application.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ plugins:
albumLoadLimit: 6 # The number of pages at 300 tracks each
deezer:
masterDecryptionKey: "your master decryption key" # the master key used for decrypting the deezer tracks. (yes this is not here you need to get it from somewhere else)
arl: "your deezer arl" # the arl cookie used for accessing the deezer api
formats: [ "FLAC", "MP3_320", "MP3_256", "MP3_128", "MP3_64", "AAC_64" ] # the formats you want to use for the deezer tracks. "FLAC", "MP3_320", "MP3_256" & "AAC_64" are only available for premium users and require a valid arl
yandexmusic:
accessToken: "your access token" # the token used for accessing the yandex music api. See https://github.com/TopiSenpai/LavaSrc#yandex-music
playlistLoadLimit: 1 # The number of pages at 100 tracks each
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class DeezerAudioSourceManager extends ExtendedAudioSourceManager impleme

private final String masterDecryptionKey;
private final String arl;
private final DeezerAudioTrack.TrackFormat[] formats;
private final HttpInterfaceManager httpInterfaceManager;
private Tokens tokens;

Expand All @@ -65,15 +66,31 @@ public DeezerAudioSourceManager(String masterDecryptionKey) {
}

public DeezerAudioSourceManager(String masterDecryptionKey, @Nullable String arl) {
this(masterDecryptionKey, arl, null);
}

public DeezerAudioSourceManager(String masterDecryptionKey, @Nullable String arl, @Nullable DeezerAudioTrack.TrackFormat[] formats) {
if (masterDecryptionKey == null || masterDecryptionKey.isEmpty()) {
throw new IllegalArgumentException("Deezer master key must be set");
}

this.masterDecryptionKey = masterDecryptionKey;
this.arl = arl != null && arl.isEmpty() ? null : arl;
this.formats = formats != null && formats.length > 0 ? formats : DeezerAudioTrack.TrackFormat.DEFAULT_FORMATS;
this.httpInterfaceManager = HttpClientTools.createCookielessThreadLocalManager();
}

static void checkResponse(JsonBrowser json, String message) throws IllegalStateException {
if (json == null) {
throw new IllegalStateException(message + "No response");
}
var errors = json.get("data").index(0).get("errors").values();
if (!errors.isEmpty()) {
var errorsStr = errors.stream().map(error -> error.get("code").text() + ": " + error.get("message").text()).collect(Collectors.joining(", "));
throw new IllegalStateException(message + errorsStr);
}
}

private void refreshSession() throws IOException {
var getSessionID = new HttpPost(DeezerAudioSourceManager.PRIVATE_API_BASE + "?method=deezer.ping&input=3&api_version=1.0&api_token=");
var json = LavaSrcTools.fetchResponseAsJson(this.getHttpInterface(), getSessionID);
Expand All @@ -100,17 +117,6 @@ public Tokens getTokens() throws IOException {
return this.tokens;
}

static void checkResponse(JsonBrowser json, String message) throws IllegalStateException {
if (json == null) {
throw new IllegalStateException(message + "No response");
}
var errors = json.get("data").index(0).get("errors").values();
if (!errors.isEmpty()) {
var errorsStr = errors.stream().map(error -> error.get("code").text() + ": " + error.get("message").text()).collect(Collectors.joining(", "));
throw new IllegalStateException(message + errorsStr);
}
}

@NotNull
@Override
public String getSourceName() {
Expand Down Expand Up @@ -405,12 +411,12 @@ private AudioItem getAlbum(String id, boolean preview) throws IOException {
}

return new DeezerAudioPlaylist(json.get("title").text(),
this.parseTracks(tracks, preview),
DeezerAudioPlaylist.Type.ALBUM,
json.get("link").text(),
artworkUrl,
author,
(int) json.get("nb_tracks").asLong(0));
this.parseTracks(tracks, preview),
DeezerAudioPlaylist.Type.ALBUM,
json.get("link").text(),
artworkUrl,
author,
(int) json.get("nb_tracks").asLong(0));
}

private AudioItem getTrack(String id, boolean preview) throws IOException {
Expand All @@ -434,12 +440,12 @@ private AudioItem getPlaylist(String id, boolean preview) throws IOException {
var tracks = this.getJson(PUBLIC_API_BASE + "/playlist/" + id + "/tracks?limit=10000");

return new DeezerAudioPlaylist(json.get("title").text(),
this.parseTracks(tracks, preview),
DeezerAudioPlaylist.Type.PLAYLIST,
json.get("link").text(),
artworkUrl,
author,
(int) json.get("nb_tracks").asLong(0));
this.parseTracks(tracks, preview),
DeezerAudioPlaylist.Type.PLAYLIST,
json.get("link").text(),
artworkUrl,
author,
(int) json.get("nb_tracks").asLong(0));
}

private AudioItem getArtist(String id, boolean preview) throws IOException {
Expand Down Expand Up @@ -491,6 +497,10 @@ public String getArl() {
return this.arl;
}

public DeezerAudioTrack.TrackFormat[] getFormats() {
return this.formats;
}

public HttpInterface getHttpInterface() {
return this.httpInterfaceManager.getInterface();
}
Expand Down
Loading

0 comments on commit 503d81b

Please sign in to comment.