discord-player-deezer 2.5.0-beta.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.yarn/install-state.gz +0 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +105 -65
- package/package.json +1 -1
- package/src/DeezerExtractor.ts +202 -141
- package/src/utils/util.ts +202 -155
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Track, ExtractorStreamable, BaseExtractor, SearchQueryType, ExtractorSearchContext, Playlist as Playlist$1, ExtractorInfo, Player } from 'discord-player';
|
|
2
1
|
import { Playlist, Track as Track$1 } from '@mithron/deezer-music-metadata';
|
|
2
|
+
import { Track, ExtractorStreamable, BaseExtractor, SearchQueryType, ExtractorSearchContext, Playlist as Playlist$1, ExtractorInfo, Player } from 'discord-player';
|
|
3
3
|
import * as crypto from 'crypto';
|
|
4
4
|
import { PassThrough } from 'stream';
|
|
5
5
|
import Blowfish from 'blowfish-node';
|
|
@@ -74,7 +74,7 @@ interface DeezerSearchTrackResponse {
|
|
|
74
74
|
type: "track";
|
|
75
75
|
}[];
|
|
76
76
|
}
|
|
77
|
-
declare function buildTrackFromSearch(track: DeezerSearchTrackResponse, player: Player, requestedBy?: Track[
|
|
77
|
+
declare function buildTrackFromSearch(track: DeezerSearchTrackResponse, player: Player, requestedBy?: Track["requestedBy"]): Track<unknown>[];
|
|
78
78
|
declare function extractTrackId(query: string): string;
|
|
79
79
|
declare function searchOneTrack(query: string): Promise<DeezerSearchTrackResponse | undefined>;
|
|
80
80
|
declare function streamTrack(track: Track, ext: DeezerExtractor): Promise<PassThrough>;
|
package/dist/index.js
CHANGED
|
@@ -48,8 +48,9 @@ __export(src_exports, {
|
|
|
48
48
|
module.exports = __toCommonJS(src_exports);
|
|
49
49
|
|
|
50
50
|
// src/DeezerExtractor.ts
|
|
51
|
-
var import_discord_player2 = require("discord-player");
|
|
52
51
|
var import_deezer_music_metadata = require("@mithron/deezer-music-metadata");
|
|
52
|
+
var import_discord_player2 = require("discord-player");
|
|
53
|
+
var import_promises = require("timers/promises");
|
|
53
54
|
|
|
54
55
|
// src/utils/util.ts
|
|
55
56
|
var import_discord_player = require("discord-player");
|
|
@@ -110,22 +111,28 @@ var DeezerAPIRoutes = {
|
|
|
110
111
|
async function search(query, limit = 10) {
|
|
111
112
|
const route = DeezerAPIRoutes.searchTrack(query, limit);
|
|
112
113
|
const response = await fetch(route);
|
|
113
|
-
if (!response.status.toString().startsWith("2"))
|
|
114
|
+
if (!response.status.toString().startsWith("2"))
|
|
115
|
+
throw new Error("Server responded with a non 2xx status.");
|
|
114
116
|
const jsonTrack = await response.json();
|
|
115
|
-
if (!jsonTrack.data || !Array.isArray(jsonTrack.data) || jsonTrack.data.length === 0)
|
|
117
|
+
if (!jsonTrack.data || !Array.isArray(jsonTrack.data) || jsonTrack.data.length === 0)
|
|
118
|
+
throw new Error(
|
|
119
|
+
"Unable get tracks from Deezer for the query '" + query + "'"
|
|
120
|
+
);
|
|
116
121
|
return jsonTrack;
|
|
117
122
|
}
|
|
118
123
|
function buildTrackFromSearch(track, player, requestedBy) {
|
|
119
|
-
const tracks = track.data.map(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
124
|
+
const tracks = track.data.map(
|
|
125
|
+
(v) => new import_discord_player.Track(player, {
|
|
126
|
+
source: "arbitrary",
|
|
127
|
+
duration: import_discord_player.Util.buildTimeCode(import_discord_player.Util.parseMS(v.duration * 1e3)),
|
|
128
|
+
author: Array.isArray(v.artist) ? v.artist.map((a) => a.name).join(", ") : v.artist.name,
|
|
129
|
+
url: v.link,
|
|
130
|
+
title: v.title,
|
|
131
|
+
thumbnail: v.album.cover_xl || v.album.cover_medium || v.album.cover || v.album.cover_small || "https://play-lh.googleusercontent.com/xtIOV8iPeAY4GrldTDo3CbLAEpbea2DqnfxaB4Nn2p5qz6KAiumY74qH86pgu1HA1A",
|
|
132
|
+
live: false,
|
|
133
|
+
requestedBy
|
|
134
|
+
})
|
|
135
|
+
);
|
|
129
136
|
return tracks;
|
|
130
137
|
}
|
|
131
138
|
function extractTrackId(query) {
|
|
@@ -150,39 +157,52 @@ async function streamTrack(track, ext) {
|
|
|
150
157
|
const trackKey = Buffer.alloc(16);
|
|
151
158
|
const Decryptor = ext.options.decryptor || JSDecryptor;
|
|
152
159
|
for (let iter = 0; iter < 16; iter++)
|
|
153
|
-
trackKey.writeInt8(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
160
|
+
trackKey.writeInt8(
|
|
161
|
+
trackHash[iter].charCodeAt(0) ^ trackHash[iter + 16].charCodeAt(0) ^ decryptionKey[iter].charCodeAt(0),
|
|
162
|
+
iter
|
|
163
|
+
);
|
|
164
|
+
const trackInfoRes = await ext.fetch(
|
|
165
|
+
`https://www.deezer.com/ajax/gw-light.php?method=song.getListData&input=3&api_version=1.0&api_token=${ext.userInfo.csrfToken}`,
|
|
166
|
+
{
|
|
167
|
+
method: "POST",
|
|
168
|
+
headers: {
|
|
169
|
+
Cookie: `${ext.userInfo.cookie}; arl=${ext.options.arl}`,
|
|
170
|
+
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0",
|
|
171
|
+
DNT: "1"
|
|
172
|
+
},
|
|
173
|
+
body: JSON.stringify({
|
|
174
|
+
sng_ids: [trackId]
|
|
175
|
+
})
|
|
176
|
+
}
|
|
177
|
+
);
|
|
165
178
|
const songInfo = (await trackInfoRes.json()).results.data[0];
|
|
166
179
|
const streamInfoRes = await fetch("https://media.deezer.com/v1/get_url", {
|
|
167
180
|
method: "POST",
|
|
168
181
|
body: JSON.stringify({
|
|
169
182
|
license_token: ext.userInfo.licenseToken,
|
|
170
|
-
media: [
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
media: [
|
|
184
|
+
{
|
|
185
|
+
type: "FULL",
|
|
186
|
+
formats: [
|
|
187
|
+
{
|
|
188
|
+
cipher: "BF_CBC_STRIPE",
|
|
189
|
+
format: "FLAC"
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
cipher: "BF_CBC_STRIPE",
|
|
193
|
+
format: "MP3_256"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
cipher: "BF_CBC_STRIPE",
|
|
197
|
+
format: "MP3_128"
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
cipher: "BF_CBC_STRIPE",
|
|
201
|
+
format: "MP3_MISC"
|
|
202
|
+
}
|
|
203
|
+
]
|
|
204
|
+
}
|
|
205
|
+
],
|
|
186
206
|
track_tokens: [songInfo.TRACK_TOKEN]
|
|
187
207
|
})
|
|
188
208
|
});
|
|
@@ -227,14 +247,13 @@ async function streamTrack(track, ext) {
|
|
|
227
247
|
var deezerRegex = {
|
|
228
248
|
track: /(^https:)\/\/(www\.)?deezer.com\/([a-zA-Z]+\/)?track\/[0-9]+/,
|
|
229
249
|
playlistNalbums: /(^https:)\/\/(www\.)?deezer.com\/[a-zA-Z]+\/(playlist|album)\/[0-9]+(\?)?(.*)/,
|
|
230
|
-
share: /(^https:)\/\/
|
|
250
|
+
share: /(^https:)\/\/dzr\.page\.link\/[A-Za-z0-9]+/
|
|
231
251
|
};
|
|
232
252
|
function validate(query) {
|
|
233
253
|
return deezerRegex.track.test(query) ?? deezerRegex.playlistNalbums.test(query) ?? deezerRegex.share.test(query);
|
|
234
254
|
}
|
|
235
255
|
|
|
236
256
|
// src/DeezerExtractor.ts
|
|
237
|
-
var import_promises = require("timers/promises");
|
|
238
257
|
var Warnings = {
|
|
239
258
|
MissingDecryption: "Decryption Key missing! This is needed for extracting streams."
|
|
240
259
|
};
|
|
@@ -252,9 +271,13 @@ async function fetchDeezerUser(ext) {
|
|
|
252
271
|
const usrDataRes = await ext.fetch(deezerUsrDataUrl);
|
|
253
272
|
const usrData = await usrDataRes.json();
|
|
254
273
|
const licenseToken = usrData.results.USER.OPTIONS.license_token;
|
|
255
|
-
if (typeof licenseToken !== "string")
|
|
274
|
+
if (typeof licenseToken !== "string")
|
|
275
|
+
throw new Error("Unable to get licenseToken");
|
|
256
276
|
const csrfToken = usrData.results.checkForm;
|
|
257
|
-
if (typeof csrfToken !== "string")
|
|
277
|
+
if (typeof csrfToken !== "string")
|
|
278
|
+
throw new Error(
|
|
279
|
+
"Unable to get csrf token which is required for decryption"
|
|
280
|
+
);
|
|
258
281
|
return {
|
|
259
282
|
cookie: usrDataRes.headers.get("set-cookie"),
|
|
260
283
|
licenseToken,
|
|
@@ -264,25 +287,27 @@ async function fetchDeezerUser(ext) {
|
|
|
264
287
|
}
|
|
265
288
|
var DeezerExtractor = class extends import_discord_player2.BaseExtractor {
|
|
266
289
|
async fetch(input, options) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
});
|
|
290
|
+
if (!options) options = {};
|
|
291
|
+
options.headers = {
|
|
292
|
+
Cookie: parseCookie({ arl: this.options.arl }),
|
|
293
|
+
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0",
|
|
294
|
+
DNT: "1",
|
|
295
|
+
Origin: "https://www.deezer.com",
|
|
296
|
+
Connection: "keep-alive",
|
|
297
|
+
Referer: "https://www.deezer.com/login",
|
|
298
|
+
...options?.headers
|
|
299
|
+
};
|
|
300
|
+
return fetch(input, options);
|
|
279
301
|
}
|
|
280
302
|
async activate() {
|
|
281
303
|
this.protocols = ["deezer"];
|
|
282
|
-
if (!this.options.decryptionKey)
|
|
304
|
+
if (!this.options.decryptionKey)
|
|
305
|
+
process.emitWarning(Warnings.MissingDecryption);
|
|
283
306
|
else {
|
|
284
307
|
this.userInfo = await fetchDeezerUser(this);
|
|
285
|
-
this.context.player.debug(
|
|
308
|
+
this.context.player.debug(
|
|
309
|
+
"USER INFO EXT: " + JSON.stringify(this.userInfo)
|
|
310
|
+
);
|
|
286
311
|
}
|
|
287
312
|
if (this.options.priority) {
|
|
288
313
|
this.priority = this.options.priority;
|
|
@@ -292,7 +317,9 @@ var DeezerExtractor = class extends import_discord_player2.BaseExtractor {
|
|
|
292
317
|
try {
|
|
293
318
|
this.userInfo = await fetchDeezerUser(this);
|
|
294
319
|
} catch {
|
|
295
|
-
this.context.player.debug(
|
|
320
|
+
this.context.player.debug(
|
|
321
|
+
"[DEEZER_EXTRACTOR_ERR]: Unable to fetch user information from Deezer. Retrying in 3 seconds ..."
|
|
322
|
+
);
|
|
296
323
|
await (0, import_promises.setTimeout)(
|
|
297
324
|
3e3
|
|
298
325
|
/* 3 seconds */
|
|
@@ -300,7 +327,9 @@ var DeezerExtractor = class extends import_discord_player2.BaseExtractor {
|
|
|
300
327
|
try {
|
|
301
328
|
this.userInfo = await fetchDeezerUser(this);
|
|
302
329
|
} catch (err) {
|
|
303
|
-
this.context.player.debug(
|
|
330
|
+
this.context.player.debug(
|
|
331
|
+
"[DEEZER_EXTRACTOR_ERR]: Retry failed. Using old user ..."
|
|
332
|
+
);
|
|
304
333
|
}
|
|
305
334
|
}
|
|
306
335
|
},
|
|
@@ -336,7 +365,11 @@ var DeezerExtractor = class extends import_discord_player2.BaseExtractor {
|
|
|
336
365
|
async handle(query, context) {
|
|
337
366
|
if (!isUrl(query)) {
|
|
338
367
|
const rawSearch = await search(query);
|
|
339
|
-
const tracks = buildTrackFromSearch(
|
|
368
|
+
const tracks = buildTrackFromSearch(
|
|
369
|
+
rawSearch,
|
|
370
|
+
this.context.player,
|
|
371
|
+
context.requestedBy
|
|
372
|
+
);
|
|
340
373
|
return this.createResponse(null, tracks);
|
|
341
374
|
}
|
|
342
375
|
if (deezerRegex.share.test(query)) {
|
|
@@ -344,7 +377,8 @@ var DeezerExtractor = class extends import_discord_player2.BaseExtractor {
|
|
|
344
377
|
query = redirect.url;
|
|
345
378
|
}
|
|
346
379
|
const metadata = await (0, import_deezer_music_metadata.getData)(query);
|
|
347
|
-
if (metadata?.type === "song")
|
|
380
|
+
if (metadata?.type === "song")
|
|
381
|
+
return this.createResponse(null, [this.buildTrack(metadata, context)]);
|
|
348
382
|
if (metadata?.type === "playlist" || metadata?.type === "album") {
|
|
349
383
|
const playlist = this.buildPlaylistData(metadata, context);
|
|
350
384
|
return this.createResponse(playlist, playlist.tracks);
|
|
@@ -363,9 +397,15 @@ var DeezerExtractor = class extends import_discord_player2.BaseExtractor {
|
|
|
363
397
|
});
|
|
364
398
|
}
|
|
365
399
|
async bridge(track) {
|
|
366
|
-
const deezerTrack = await searchOneTrack(
|
|
400
|
+
const deezerTrack = await searchOneTrack(
|
|
401
|
+
`${track.author} ${track.source === "youtube" ? track.cleanTitle : track.title}`
|
|
402
|
+
);
|
|
367
403
|
if (!deezerTrack) return null;
|
|
368
|
-
const dpTrack = buildTrackFromSearch(
|
|
404
|
+
const dpTrack = buildTrackFromSearch(
|
|
405
|
+
deezerTrack,
|
|
406
|
+
this.context.player,
|
|
407
|
+
track.requestedBy
|
|
408
|
+
);
|
|
369
409
|
const stream = this.stream(dpTrack[0]);
|
|
370
410
|
return stream;
|
|
371
411
|
}
|
package/package.json
CHANGED
package/src/DeezerExtractor.ts
CHANGED
|
@@ -1,198 +1,259 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
Playlist as DeezerPlaylist,
|
|
3
|
+
Track as DeezerTrack,
|
|
4
|
+
getData,
|
|
5
|
+
} from "@mithron/deezer-music-metadata";
|
|
6
|
+
import {
|
|
7
|
+
BaseExtractor,
|
|
8
|
+
Util as DPUtil,
|
|
9
|
+
ExtractorInfo,
|
|
10
|
+
ExtractorSearchContext,
|
|
11
|
+
ExtractorStreamable,
|
|
12
|
+
Playlist,
|
|
13
|
+
SearchQueryType,
|
|
14
|
+
Track,
|
|
15
|
+
} from "discord-player";
|
|
16
|
+
import { setTimeout } from "node:timers/promises";
|
|
5
17
|
import { BaseDecryptor } from "./Crypto/BaseDecryptor";
|
|
18
|
+
import {
|
|
19
|
+
buildTrackFromSearch,
|
|
20
|
+
deezerRegex,
|
|
21
|
+
getCrypto,
|
|
22
|
+
isUrl,
|
|
23
|
+
search,
|
|
24
|
+
searchOneTrack,
|
|
25
|
+
streamTrack,
|
|
26
|
+
validate,
|
|
27
|
+
} from "./utils/util";
|
|
6
28
|
|
|
7
29
|
/**
|
|
8
30
|
* -------------------------------NOTICE-------------------------------------
|
|
9
31
|
* STREAMING CODE IS MAINLY TAKEN FROM https://github.com/PerformanC/NodeLink
|
|
10
32
|
* WHICH HAS THE "BSD 2-Clause "Simplified" License"
|
|
11
|
-
*
|
|
33
|
+
*
|
|
12
34
|
* PLEASE SHOW THE ORIGINAL AUTHOR SUPPORT BY STARING HIS GITHUB REPO
|
|
13
35
|
* --------------------------------------------------------------------------
|
|
14
36
|
*/
|
|
15
37
|
|
|
16
38
|
export type DeezerExtractorOptions = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
39
|
+
decryptionKey?: string; // needed for decrypting deezer songs
|
|
40
|
+
createStream?: (
|
|
41
|
+
track: Track,
|
|
42
|
+
ext: DeezerExtractor
|
|
43
|
+
) => Promise<ExtractorStreamable>;
|
|
44
|
+
searchLimit?: number;
|
|
45
|
+
reloadUserInterval?: number;
|
|
46
|
+
priority?: number;
|
|
47
|
+
arl: string;
|
|
48
|
+
decryptor?: typeof BaseDecryptor;
|
|
49
|
+
};
|
|
25
50
|
|
|
26
51
|
export type DeezerUserInfo = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
52
|
+
cookie: string;
|
|
53
|
+
licenseToken: string;
|
|
54
|
+
csrfToken: string;
|
|
55
|
+
mediaUrl: string;
|
|
56
|
+
};
|
|
32
57
|
|
|
33
58
|
export const Warnings = {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
59
|
+
MissingDecryption:
|
|
60
|
+
"Decryption Key missing! This is needed for extracting streams.",
|
|
61
|
+
} as const;
|
|
62
|
+
export type Warnings = (typeof Warnings)[keyof typeof Warnings];
|
|
37
63
|
|
|
38
64
|
function parseCookie(obj: Record<string, string>) {
|
|
39
|
-
let str = ""
|
|
40
|
-
for(const key of Object.keys(obj)) {
|
|
41
|
-
str += ` ${key}=${obj[key]}
|
|
65
|
+
let str = "";
|
|
66
|
+
for (const key of Object.keys(obj)) {
|
|
67
|
+
str += ` ${key}=${obj[key]};`;
|
|
42
68
|
}
|
|
43
69
|
|
|
44
|
-
return str.trim()
|
|
70
|
+
return str.trim();
|
|
45
71
|
}
|
|
46
72
|
|
|
47
73
|
async function fetchDeezerUser(ext: DeezerExtractor): Promise<DeezerUserInfo> {
|
|
48
74
|
// extract deezer username
|
|
49
75
|
// dynamically load crypto because some might not want streaming
|
|
50
|
-
const crypto = await getCrypto()
|
|
51
|
-
const randomToken = crypto.randomBytes(16).toString("hex")
|
|
52
|
-
const deezerUsrDataUrl = `https://www.deezer.com/ajax/gw-light.php?method=deezer.getUserData&input=3&api_version=1.0&api_token=${randomToken}
|
|
76
|
+
const crypto = await getCrypto();
|
|
77
|
+
const randomToken = crypto.randomBytes(16).toString("hex");
|
|
78
|
+
const deezerUsrDataUrl = `https://www.deezer.com/ajax/gw-light.php?method=deezer.getUserData&input=3&api_version=1.0&api_token=${randomToken}`;
|
|
53
79
|
|
|
54
|
-
const usrDataRes = await ext.fetch(deezerUsrDataUrl)
|
|
55
|
-
const usrData = await usrDataRes.json()
|
|
80
|
+
const usrDataRes = await ext.fetch(deezerUsrDataUrl);
|
|
81
|
+
const usrData = await usrDataRes.json();
|
|
56
82
|
|
|
57
|
-
const licenseToken = usrData.results.USER.OPTIONS.license_token
|
|
58
|
-
if(typeof licenseToken !== "string")
|
|
83
|
+
const licenseToken = usrData.results.USER.OPTIONS.license_token;
|
|
84
|
+
if (typeof licenseToken !== "string")
|
|
85
|
+
throw new Error("Unable to get licenseToken");
|
|
59
86
|
|
|
60
|
-
const csrfToken = usrData.results.checkForm
|
|
61
|
-
if(typeof csrfToken !== "string")
|
|
87
|
+
const csrfToken = usrData.results.checkForm;
|
|
88
|
+
if (typeof csrfToken !== "string")
|
|
89
|
+
throw new Error(
|
|
90
|
+
"Unable to get csrf token which is required for decryption"
|
|
91
|
+
);
|
|
62
92
|
|
|
63
93
|
return {
|
|
64
94
|
cookie: usrDataRes.headers.get("set-cookie")!,
|
|
65
95
|
licenseToken,
|
|
66
96
|
csrfToken,
|
|
67
97
|
mediaUrl: usrData.results.URL_MEDIA || "https://media.deezer.com",
|
|
68
|
-
}
|
|
98
|
+
};
|
|
69
99
|
}
|
|
70
100
|
|
|
71
101
|
export class DeezerExtractor extends BaseExtractor<DeezerExtractorOptions> {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
async fetch(input: Parameters<typeof fetch>[0], options?: Parameters<typeof fetch>[1]) {
|
|
78
|
-
return fetch(input, {
|
|
79
|
-
...options,
|
|
80
|
-
headers: {
|
|
81
|
-
...options?.headers,
|
|
82
|
-
Cookie: parseCookie({ arl: this.options.arl }),
|
|
83
|
-
'User-Agent': "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0",
|
|
84
|
-
'DNT': '1',
|
|
85
|
-
"Origin": "https://www.deezer.com",
|
|
86
|
-
'Connection': 'keep-alive',
|
|
87
|
-
'Referer': 'https://www.deezer.com/login'
|
|
88
|
-
}
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async activate(): Promise<void> {
|
|
93
|
-
this.protocols = ["deezer"]
|
|
94
|
-
if(!this.options.decryptionKey) process.emitWarning(Warnings.MissingDecryption)
|
|
95
|
-
else {
|
|
96
|
-
this.userInfo = await fetchDeezerUser(this)
|
|
97
|
-
|
|
98
|
-
this.context.player.debug('USER INFO EXT: ' + JSON.stringify(this.userInfo))
|
|
99
|
-
}
|
|
102
|
+
static readonly identifier: string =
|
|
103
|
+
"com.retrouser955.discord-player.deezr-ext";
|
|
104
|
+
userInfo!: DeezerUserInfo;
|
|
105
|
+
/* tslint:disable-next-line */
|
|
106
|
+
__interval?: ReturnType<typeof setInterval>;
|
|
100
107
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
108
|
+
async fetch(
|
|
109
|
+
input: Parameters<typeof fetch>[0],
|
|
110
|
+
options?: Parameters<typeof fetch>[1]
|
|
111
|
+
) {
|
|
112
|
+
if (!options) options = {};
|
|
113
|
+
options.headers = {
|
|
114
|
+
Cookie: parseCookie({ arl: this.options.arl }),
|
|
115
|
+
"User-Agent":
|
|
116
|
+
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0",
|
|
117
|
+
DNT: "1",
|
|
118
|
+
Origin: "https://www.deezer.com",
|
|
119
|
+
Connection: "keep-alive",
|
|
120
|
+
Referer: "https://www.deezer.com/login",
|
|
121
|
+
...options?.headers,
|
|
122
|
+
};
|
|
123
|
+
return fetch(input, options);
|
|
124
|
+
}
|
|
104
125
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
try {
|
|
112
|
-
this.userInfo = await fetchDeezerUser(this)
|
|
113
|
-
} catch (err) {
|
|
114
|
-
this.context.player.debug("[DEEZER_EXTRACTOR_ERR]: Retry failed. Using old user ...")
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}, this.options.reloadUserInterval || 8.64e+7/* one day */).unref()
|
|
118
|
-
}
|
|
126
|
+
async activate(): Promise<void> {
|
|
127
|
+
this.protocols = ["deezer"];
|
|
128
|
+
if (!this.options.decryptionKey)
|
|
129
|
+
process.emitWarning(Warnings.MissingDecryption);
|
|
130
|
+
else {
|
|
131
|
+
this.userInfo = await fetchDeezerUser(this);
|
|
119
132
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
133
|
+
this.context.player.debug(
|
|
134
|
+
"USER INFO EXT: " + JSON.stringify(this.userInfo)
|
|
135
|
+
);
|
|
123
136
|
}
|
|
124
137
|
|
|
125
|
-
|
|
126
|
-
|
|
138
|
+
if (this.options.priority) {
|
|
139
|
+
this.priority = this.options.priority;
|
|
127
140
|
}
|
|
128
141
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
source: "arbitrary",
|
|
144
|
-
id: identifier,
|
|
145
|
-
url: data.url
|
|
146
|
-
})
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
async handle(query: string, context: ExtractorSearchContext): Promise<ExtractorInfo> {
|
|
150
|
-
if(!isUrl(query)) {
|
|
151
|
-
const rawSearch = await search(query)
|
|
152
|
-
const tracks = buildTrackFromSearch(rawSearch, this.context.player, context.requestedBy)
|
|
153
|
-
return this.createResponse(null, tracks)
|
|
142
|
+
this.__interval = setInterval(async () => {
|
|
143
|
+
try {
|
|
144
|
+
this.userInfo = await fetchDeezerUser(this);
|
|
145
|
+
} catch {
|
|
146
|
+
this.context.player.debug(
|
|
147
|
+
"[DEEZER_EXTRACTOR_ERR]: Unable to fetch user information from Deezer. Retrying in 3 seconds ..."
|
|
148
|
+
);
|
|
149
|
+
await setTimeout(3000 /* 3 seconds */);
|
|
150
|
+
try {
|
|
151
|
+
this.userInfo = await fetchDeezerUser(this);
|
|
152
|
+
} catch (err) {
|
|
153
|
+
this.context.player.debug(
|
|
154
|
+
"[DEEZER_EXTRACTOR_ERR]: Retry failed. Using old user ..."
|
|
155
|
+
);
|
|
154
156
|
}
|
|
157
|
+
}
|
|
158
|
+
}, this.options.reloadUserInterval || 8.64e7 /* one day */).unref();
|
|
159
|
+
}
|
|
155
160
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const metadata = await getData(query)
|
|
161
|
+
async deactivate() {
|
|
162
|
+
if (this.__interval) clearInterval(this.__interval);
|
|
163
|
+
this.protocols = [];
|
|
164
|
+
}
|
|
161
165
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
166
|
+
async validate(
|
|
167
|
+
query: string,
|
|
168
|
+
type: SearchQueryType & "deezer"
|
|
169
|
+
): Promise<boolean> {
|
|
170
|
+
return validate(query) || type === "deezer" || !isUrl(query);
|
|
171
|
+
}
|
|
165
172
|
|
|
166
|
-
|
|
167
|
-
|
|
173
|
+
buildPlaylistData(
|
|
174
|
+
data: DeezerPlaylist,
|
|
175
|
+
handleContext: ExtractorSearchContext
|
|
176
|
+
) {
|
|
177
|
+
const raw: string[] = data.url.split("/");
|
|
178
|
+
const identifier: string = raw[raw.length - 1].split("?")[0];
|
|
179
|
+
|
|
180
|
+
return new Playlist(this.context.player, {
|
|
181
|
+
title: data.name,
|
|
182
|
+
thumbnail: data.thumbnail[0].url,
|
|
183
|
+
author: {
|
|
184
|
+
name: data.artist.name,
|
|
185
|
+
url: data.artist.url,
|
|
186
|
+
},
|
|
187
|
+
type: data.type,
|
|
188
|
+
tracks: data.tracks.map((v) => this.buildTrack(v, handleContext)),
|
|
189
|
+
description: "",
|
|
190
|
+
source: "arbitrary",
|
|
191
|
+
id: identifier,
|
|
192
|
+
url: data.url,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
168
195
|
|
|
169
|
-
|
|
196
|
+
async handle(
|
|
197
|
+
query: string,
|
|
198
|
+
context: ExtractorSearchContext
|
|
199
|
+
): Promise<ExtractorInfo> {
|
|
200
|
+
if (!isUrl(query)) {
|
|
201
|
+
const rawSearch = await search(query);
|
|
202
|
+
const tracks = buildTrackFromSearch(
|
|
203
|
+
rawSearch,
|
|
204
|
+
this.context.player,
|
|
205
|
+
context.requestedBy
|
|
206
|
+
);
|
|
207
|
+
return this.createResponse(null, tracks);
|
|
170
208
|
}
|
|
171
209
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
author: track.author.map((v) => v.name).join(", "),
|
|
176
|
-
url: track.url,
|
|
177
|
-
source: "arbitrary",
|
|
178
|
-
thumbnail: track.thumbnail[0].url,
|
|
179
|
-
duration: DPUtil.buildTimeCode(DPUtil.parseMS(track.duration)),
|
|
180
|
-
requestedBy
|
|
181
|
-
})
|
|
210
|
+
if (deezerRegex.share.test(query)) {
|
|
211
|
+
const redirect = await this.fetch(query);
|
|
212
|
+
query = redirect.url; // follow the redirect of deezer page links
|
|
182
213
|
}
|
|
214
|
+
const metadata = await getData(query);
|
|
183
215
|
|
|
184
|
-
|
|
185
|
-
|
|
216
|
+
if (metadata?.type === "song")
|
|
217
|
+
return this.createResponse(null, [this.buildTrack(metadata, context)]);
|
|
218
|
+
if (metadata?.type === "playlist" || metadata?.type === "album") {
|
|
219
|
+
const playlist = this.buildPlaylistData(metadata, context);
|
|
186
220
|
|
|
187
|
-
|
|
188
|
-
|
|
221
|
+
return this.createResponse(playlist, playlist.tracks);
|
|
222
|
+
}
|
|
189
223
|
|
|
190
|
-
|
|
224
|
+
throw new Error("Unable to get data from Deezer");
|
|
225
|
+
}
|
|
191
226
|
|
|
192
|
-
|
|
193
|
-
|
|
227
|
+
buildTrack(track: DeezerTrack, { requestedBy }: ExtractorSearchContext) {
|
|
228
|
+
return new Track(this.context.player, {
|
|
229
|
+
title: track.name,
|
|
230
|
+
author: track.author.map((v) => v.name).join(", "),
|
|
231
|
+
url: track.url,
|
|
232
|
+
source: "arbitrary",
|
|
233
|
+
thumbnail: track.thumbnail[0].url,
|
|
234
|
+
duration: DPUtil.buildTimeCode(DPUtil.parseMS(track.duration)),
|
|
235
|
+
requestedBy,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
194
238
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
239
|
+
async bridge(track: Track): Promise<ExtractorStreamable | null> {
|
|
240
|
+
const deezerTrack = await searchOneTrack(
|
|
241
|
+
`${track.author} ${track.source === "youtube" ? track.cleanTitle : track.title}`
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
if (!deezerTrack) return null;
|
|
245
|
+
const dpTrack = buildTrackFromSearch(
|
|
246
|
+
deezerTrack,
|
|
247
|
+
this.context.player,
|
|
248
|
+
track.requestedBy
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
const stream = this.stream(dpTrack[0]);
|
|
252
|
+
|
|
253
|
+
return stream;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
stream(info: Track): Promise<ExtractorStreamable> {
|
|
257
|
+
return streamTrack(info, this);
|
|
258
|
+
}
|
|
198
259
|
}
|
package/src/utils/util.ts
CHANGED
|
@@ -1,218 +1,265 @@
|
|
|
1
1
|
import { type Player, Track, Util } from "discord-player";
|
|
2
|
-
import
|
|
3
|
-
import { Readable, PassThrough } from 'stream'
|
|
4
|
-
import Blowfish from "blowfish-node";
|
|
2
|
+
import { PassThrough, Readable } from "stream";
|
|
5
3
|
import { JSDecryptor } from "../Crypto/JSDecryptor";
|
|
4
|
+
import type { DeezerExtractor } from "../DeezerExtractor";
|
|
6
5
|
|
|
7
|
-
const IV = Buffer.from(Array.from({ length: 8 }, (_, x) => x))
|
|
6
|
+
const IV = Buffer.from(Array.from({ length: 8 }, (_, x) => x));
|
|
8
7
|
|
|
9
|
-
let rawCrypto: typeof import("crypto")
|
|
8
|
+
let rawCrypto: typeof import("crypto");
|
|
10
9
|
|
|
11
10
|
export async function getCrypto() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
if (!rawCrypto) {
|
|
12
|
+
rawCrypto = await import("crypto");
|
|
13
|
+
return rawCrypto;
|
|
14
|
+
}
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
return rawCrypto;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
export function isUrl(query: string) {
|
|
21
20
|
try {
|
|
22
|
-
const url = new URL(query)
|
|
23
|
-
return [
|
|
21
|
+
const url = new URL(query);
|
|
22
|
+
return ["https:", "http:"].includes(url.protocol);
|
|
24
23
|
} catch {
|
|
25
|
-
return false
|
|
24
|
+
return false;
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
const DeezerAPIRoutes = {
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
searchTrack(query: string, limit?: number) {
|
|
30
|
+
const url = `https://api.deezer.com/search/track?q=${encodeURIComponent(query)}&${limit ? `limit=${limit}` : ""}`;
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} as const
|
|
32
|
+
return url;
|
|
33
|
+
},
|
|
34
|
+
} as const;
|
|
36
35
|
|
|
37
36
|
export async function search(query: string, limit: number = 10) {
|
|
38
37
|
const route = DeezerAPIRoutes.searchTrack(query, limit);
|
|
39
38
|
|
|
40
|
-
const response = await fetch(route)
|
|
39
|
+
const response = await fetch(route);
|
|
41
40
|
|
|
42
|
-
if(!response.status.toString().startsWith("2"))
|
|
41
|
+
if (!response.status.toString().startsWith("2"))
|
|
42
|
+
throw new Error("Server responded with a non 2xx status.");
|
|
43
43
|
|
|
44
|
-
const jsonTrack = await response.json()
|
|
44
|
+
const jsonTrack = await response.json();
|
|
45
45
|
|
|
46
|
-
if
|
|
46
|
+
if (
|
|
47
|
+
!jsonTrack.data ||
|
|
48
|
+
!Array.isArray(jsonTrack.data) ||
|
|
49
|
+
jsonTrack.data.length === 0
|
|
50
|
+
)
|
|
51
|
+
throw new Error(
|
|
52
|
+
"Unable get tracks from Deezer for the query '" + query + "'"
|
|
53
|
+
);
|
|
47
54
|
|
|
48
|
-
return jsonTrack as DeezerSearchTrackResponse
|
|
55
|
+
return jsonTrack as DeezerSearchTrackResponse;
|
|
49
56
|
}
|
|
50
57
|
|
|
51
|
-
export type ArrayOrObject<T> = T | T[]
|
|
58
|
+
export type ArrayOrObject<T> = T | T[];
|
|
52
59
|
|
|
53
60
|
export interface DeezerSearchTrackResponse {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
data: {
|
|
62
|
+
link: string;
|
|
63
|
+
title: string;
|
|
64
|
+
album: {
|
|
65
|
+
cover_xl?: string;
|
|
66
|
+
cover_medium?: string;
|
|
67
|
+
cover_small?: string;
|
|
68
|
+
cover?: string;
|
|
69
|
+
};
|
|
70
|
+
artist: {
|
|
71
|
+
name: string;
|
|
72
|
+
};
|
|
73
|
+
duration: number; // in seconds
|
|
74
|
+
type: "track";
|
|
75
|
+
}[];
|
|
69
76
|
}
|
|
70
77
|
|
|
71
|
-
export function buildTrackFromSearch(
|
|
72
|
-
|
|
78
|
+
export function buildTrackFromSearch(
|
|
79
|
+
track: DeezerSearchTrackResponse,
|
|
80
|
+
player: Player,
|
|
81
|
+
requestedBy?: Track["requestedBy"]
|
|
82
|
+
) {
|
|
83
|
+
const tracks = track.data.map(
|
|
84
|
+
(v) =>
|
|
85
|
+
new Track(player, {
|
|
73
86
|
source: "arbitrary",
|
|
74
87
|
duration: Util.buildTimeCode(Util.parseMS(v.duration * 1000)),
|
|
75
|
-
author: Array.isArray(v.artist)
|
|
88
|
+
author: Array.isArray(v.artist)
|
|
89
|
+
? v.artist.map((a) => a.name).join(", ")
|
|
90
|
+
: v.artist.name,
|
|
76
91
|
url: v.link,
|
|
77
92
|
title: v.title,
|
|
78
|
-
thumbnail:
|
|
93
|
+
thumbnail:
|
|
94
|
+
v.album.cover_xl ||
|
|
95
|
+
v.album.cover_medium ||
|
|
96
|
+
v.album.cover ||
|
|
97
|
+
v.album.cover_small ||
|
|
98
|
+
"https://play-lh.googleusercontent.com/xtIOV8iPeAY4GrldTDo3CbLAEpbea2DqnfxaB4Nn2p5qz6KAiumY74qH86pgu1HA1A",
|
|
79
99
|
live: false,
|
|
80
|
-
requestedBy
|
|
81
|
-
|
|
100
|
+
requestedBy,
|
|
101
|
+
})
|
|
102
|
+
);
|
|
82
103
|
|
|
83
|
-
|
|
104
|
+
return tracks;
|
|
84
105
|
}
|
|
85
106
|
|
|
86
107
|
export function extractTrackId(query: string) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
108
|
+
if (!validate(query)) throw new Error("Invalid track url");
|
|
109
|
+
const trackIdWithUrlParams = query.split("/").at(-1);
|
|
110
|
+
if (!trackIdWithUrlParams) throw new Error("Cannot find track ID");
|
|
111
|
+
return trackIdWithUrlParams.split("?")[0];
|
|
91
112
|
}
|
|
92
113
|
|
|
93
114
|
// used for bridging
|
|
94
115
|
export async function searchOneTrack(query: string) {
|
|
95
|
-
|
|
116
|
+
const url = DeezerAPIRoutes.searchTrack(query, 1);
|
|
96
117
|
|
|
97
|
-
|
|
98
|
-
|
|
118
|
+
const trackRes = await fetch(url);
|
|
119
|
+
if (trackRes.status !== 200) throw new Error("Fetch failed");
|
|
99
120
|
|
|
100
|
-
|
|
101
|
-
|
|
121
|
+
const trackData = (await trackRes.json()) as
|
|
122
|
+
| DeezerSearchTrackResponse
|
|
123
|
+
| undefined;
|
|
124
|
+
return trackData;
|
|
102
125
|
}
|
|
103
126
|
|
|
104
127
|
export async function streamTrack(track: Track, ext: DeezerExtractor) {
|
|
105
|
-
|
|
106
|
-
|
|
128
|
+
const decryptionKey = ext.options.decryptionKey;
|
|
129
|
+
if (!decryptionKey) throw new Error("MISSING DEEZER DECRYPTION KEY"); // cant decrypt due to missing key
|
|
130
|
+
|
|
131
|
+
const crypto = await getCrypto();
|
|
132
|
+
const trackId = extractTrackId(track.url);
|
|
133
|
+
|
|
134
|
+
const trackHash = crypto
|
|
135
|
+
.createHash("md5")
|
|
136
|
+
.update(trackId, "ascii")
|
|
137
|
+
.digest("hex");
|
|
138
|
+
const trackKey = Buffer.alloc(16);
|
|
139
|
+
|
|
140
|
+
const Decryptor = ext.options.decryptor || JSDecryptor;
|
|
141
|
+
|
|
142
|
+
for (let iter = 0; iter < 16; iter++)
|
|
143
|
+
/* tslint:disable-next-line no-bitwise */
|
|
144
|
+
trackKey.writeInt8(
|
|
145
|
+
trackHash[iter].charCodeAt(0) ^
|
|
146
|
+
trackHash[iter + 16].charCodeAt(0) ^
|
|
147
|
+
decryptionKey[iter].charCodeAt(0),
|
|
148
|
+
iter
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const trackInfoRes = await ext.fetch(
|
|
152
|
+
`https://www.deezer.com/ajax/gw-light.php?method=song.getListData&input=3&api_version=1.0&api_token=${ext.userInfo.csrfToken}`,
|
|
153
|
+
{
|
|
154
|
+
method: "POST",
|
|
155
|
+
headers: {
|
|
156
|
+
Cookie: `${ext.userInfo.cookie}; arl=${ext.options.arl}`,
|
|
157
|
+
"User-Agent":
|
|
158
|
+
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0",
|
|
159
|
+
DNT: "1",
|
|
160
|
+
},
|
|
161
|
+
body: JSON.stringify({
|
|
162
|
+
sng_ids: [trackId],
|
|
163
|
+
}),
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
const songInfo = (await trackInfoRes.json()).results.data[0];
|
|
168
|
+
|
|
169
|
+
const streamInfoRes = await fetch("https://media.deezer.com/v1/get_url", {
|
|
170
|
+
method: "POST",
|
|
171
|
+
body: JSON.stringify({
|
|
172
|
+
license_token: ext.userInfo.licenseToken,
|
|
173
|
+
media: [
|
|
174
|
+
{
|
|
175
|
+
type: "FULL",
|
|
176
|
+
formats: [
|
|
177
|
+
{
|
|
178
|
+
cipher: "BF_CBC_STRIPE",
|
|
179
|
+
format: "FLAC",
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
cipher: "BF_CBC_STRIPE",
|
|
183
|
+
format: "MP3_256",
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
cipher: "BF_CBC_STRIPE",
|
|
187
|
+
format: "MP3_128",
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
cipher: "BF_CBC_STRIPE",
|
|
191
|
+
format: "MP3_MISC",
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
track_tokens: [songInfo.TRACK_TOKEN],
|
|
197
|
+
}),
|
|
198
|
+
});
|
|
199
|
+
const streamInfo = await streamInfoRes.json();
|
|
107
200
|
|
|
108
|
-
|
|
109
|
-
const trackId = extractTrackId(track.url)
|
|
201
|
+
const trackMediaUrl = streamInfo.data[0].media[0].sources[0].url;
|
|
110
202
|
|
|
111
|
-
|
|
112
|
-
const trackKey = Buffer.alloc(16)
|
|
203
|
+
ext.context.player.debug("DEEZER FOUND MEDIA URL " + trackMediaUrl);
|
|
113
204
|
|
|
114
|
-
|
|
205
|
+
const trackReq = await ext.fetch(trackMediaUrl);
|
|
206
|
+
// @ts-ignore
|
|
207
|
+
const readable = Readable.fromWeb(trackReq.body);
|
|
208
|
+
let buffer = Buffer.alloc(0);
|
|
209
|
+
let i = 0;
|
|
115
210
|
|
|
116
|
-
|
|
117
|
-
/* tslint:disable-next-line no-bitwise */
|
|
118
|
-
trackKey.writeInt8(trackHash[iter].charCodeAt(0) ^ trackHash[iter + 16].charCodeAt(0) ^ decryptionKey[iter].charCodeAt(0), iter)
|
|
211
|
+
const bufferSize = 2048; // 2mb
|
|
119
212
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const streamInfoRes = await fetch('https://media.deezer.com/v1/get_url', {
|
|
135
|
-
method: "POST",
|
|
136
|
-
body: JSON.stringify({
|
|
137
|
-
license_token: ext.userInfo.licenseToken,
|
|
138
|
-
media: [{
|
|
139
|
-
type: 'FULL',
|
|
140
|
-
formats: [{
|
|
141
|
-
cipher: 'BF_CBC_STRIPE',
|
|
142
|
-
format: 'FLAC'
|
|
143
|
-
}, {
|
|
144
|
-
cipher: 'BF_CBC_STRIPE',
|
|
145
|
-
format: 'MP3_256'
|
|
146
|
-
}, {
|
|
147
|
-
cipher: 'BF_CBC_STRIPE',
|
|
148
|
-
format: 'MP3_128'
|
|
149
|
-
}, {
|
|
150
|
-
cipher: 'BF_CBC_STRIPE',
|
|
151
|
-
format: 'MP3_MISC'
|
|
152
|
-
}]
|
|
153
|
-
}],
|
|
154
|
-
track_tokens: [songInfo.TRACK_TOKEN]
|
|
155
|
-
})
|
|
156
|
-
})
|
|
157
|
-
const streamInfo = await streamInfoRes.json()
|
|
158
|
-
|
|
159
|
-
const trackMediaUrl = streamInfo.data[0].media[0].sources[0].url
|
|
160
|
-
|
|
161
|
-
ext.context.player.debug("DEEZER FOUND MEDIA URL " + trackMediaUrl)
|
|
162
|
-
|
|
163
|
-
const trackReq = await ext.fetch(trackMediaUrl)
|
|
164
|
-
// @ts-ignore
|
|
165
|
-
const readable = Readable.fromWeb(trackReq.body)
|
|
166
|
-
let buffer = Buffer.alloc(0)
|
|
167
|
-
let i = 0
|
|
168
|
-
|
|
169
|
-
const bufferSize = 2048 // 2mb
|
|
170
|
-
|
|
171
|
-
const passThrough = new PassThrough()
|
|
172
|
-
|
|
173
|
-
const decryptor = new Decryptor(trackKey, IV)
|
|
174
|
-
|
|
175
|
-
readable.on("readable", async () => {
|
|
176
|
-
let chunk = null;
|
|
177
|
-
while (true) {
|
|
178
|
-
chunk = readable.read(bufferSize)
|
|
179
|
-
|
|
180
|
-
if (!chunk) {
|
|
181
|
-
if (readable.readableLength) {
|
|
182
|
-
chunk = readable.read(readable.readableLength)
|
|
183
|
-
buffer = Buffer.concat([buffer, chunk])
|
|
184
|
-
}
|
|
185
|
-
break;
|
|
186
|
-
} else {
|
|
187
|
-
buffer = Buffer.concat([buffer, chunk])
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
while (buffer.length >= bufferSize) {
|
|
191
|
-
const bufferSized = buffer.subarray(0, bufferSize)
|
|
192
|
-
|
|
193
|
-
if (i % 3 === 0) {
|
|
194
|
-
const decipher = await decryptor.decrypt(bufferSized)
|
|
195
|
-
passThrough.write(decipher)
|
|
196
|
-
} else {
|
|
197
|
-
passThrough.write(bufferSized)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
i++
|
|
201
|
-
|
|
202
|
-
buffer = buffer.subarray(bufferSize)
|
|
203
|
-
}
|
|
213
|
+
const passThrough = new PassThrough();
|
|
214
|
+
|
|
215
|
+
const decryptor = new Decryptor(trackKey, IV);
|
|
216
|
+
|
|
217
|
+
readable.on("readable", async () => {
|
|
218
|
+
let chunk = null;
|
|
219
|
+
while (true) {
|
|
220
|
+
chunk = readable.read(bufferSize);
|
|
221
|
+
|
|
222
|
+
if (!chunk) {
|
|
223
|
+
if (readable.readableLength) {
|
|
224
|
+
chunk = readable.read(readable.readableLength);
|
|
225
|
+
buffer = Buffer.concat([buffer, chunk]);
|
|
204
226
|
}
|
|
205
|
-
|
|
227
|
+
break;
|
|
228
|
+
} else {
|
|
229
|
+
buffer = Buffer.concat([buffer, chunk]);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
while (buffer.length >= bufferSize) {
|
|
233
|
+
const bufferSized = buffer.subarray(0, bufferSize);
|
|
234
|
+
|
|
235
|
+
if (i % 3 === 0) {
|
|
236
|
+
const decipher = await decryptor.decrypt(bufferSized);
|
|
237
|
+
passThrough.write(decipher);
|
|
238
|
+
} else {
|
|
239
|
+
passThrough.write(bufferSized);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
i++;
|
|
243
|
+
|
|
244
|
+
buffer = buffer.subarray(bufferSize);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
});
|
|
206
248
|
|
|
207
|
-
|
|
249
|
+
return passThrough;
|
|
208
250
|
}
|
|
209
251
|
|
|
210
252
|
export const deezerRegex = {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
253
|
+
track: /(^https:)\/\/(www\.)?deezer.com\/([a-zA-Z]+\/)?track\/[0-9]+/,
|
|
254
|
+
playlistNalbums:
|
|
255
|
+
/(^https:)\/\/(www\.)?deezer.com\/[a-zA-Z]+\/(playlist|album)\/[0-9]+(\?)?(.*)/,
|
|
256
|
+
share: /(^https:)\/\/dzr\.page\.link\/[A-Za-z0-9]+/,
|
|
214
257
|
} as const;
|
|
215
258
|
|
|
216
259
|
export function validate(query: string) {
|
|
217
|
-
|
|
260
|
+
return (
|
|
261
|
+
deezerRegex.track.test(query) ??
|
|
262
|
+
deezerRegex.playlistNalbums.test(query) ??
|
|
263
|
+
deezerRegex.share.test(query)
|
|
264
|
+
);
|
|
218
265
|
}
|