discord-player-deezer 2.6.0 → 3.0.0-dev.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/dist/index.js CHANGED
@@ -32,8 +32,10 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  BaseDecryptor: () => BaseDecryptor,
34
34
  DeezerExtractor: () => DeezerExtractor,
35
+ DiskAudioCache: () => DiskAudioCache,
35
36
  JSDecryptor: () => JSDecryptor,
36
37
  NodeDecryptor: () => NodeDecryptor,
38
+ StripeDecryptStream: () => StripeDecryptStream,
37
39
  Warnings: () => Warnings,
38
40
  buildTrackFromSearch: () => buildTrackFromSearch,
39
41
  deezerRegex: () => deezerRegex,
@@ -56,6 +58,57 @@ var import_promises = require("timers/promises");
56
58
  var import_discord_player = require("discord-player");
57
59
  var import_stream = require("stream");
58
60
 
61
+ // src/Cache/CacheTapStream.ts
62
+ var import_node_stream = require("stream");
63
+ var CacheTapStream = class extends import_node_stream.Transform {
64
+ constructor(sink) {
65
+ super();
66
+ this.sinkFailed = false;
67
+ this.flushed = false;
68
+ this.sink = sink;
69
+ this.sink.once("error", () => {
70
+ this.sinkFailed = true;
71
+ });
72
+ }
73
+ _transform(chunk, _encoding, callback) {
74
+ this.push(chunk);
75
+ if (this.sinkFailed || this.sink.destroyed || this.sink.writableEnded) {
76
+ callback();
77
+ return;
78
+ }
79
+ if (this.sink.write(chunk)) {
80
+ callback();
81
+ return;
82
+ }
83
+ const done = () => {
84
+ this.sink.off("drain", done);
85
+ this.sink.off("error", done);
86
+ callback();
87
+ };
88
+ this.sink.once("drain", done);
89
+ this.sink.once("error", done);
90
+ }
91
+ _flush(callback) {
92
+ this.flushed = true;
93
+ if (this.sinkFailed || this.sink.destroyed || this.sink.writableEnded) {
94
+ callback();
95
+ return;
96
+ }
97
+ const done = () => {
98
+ this.sink.off("finish", done);
99
+ this.sink.off("error", done);
100
+ callback();
101
+ };
102
+ this.sink.once("finish", done);
103
+ this.sink.once("error", done);
104
+ this.sink.end();
105
+ }
106
+ _destroy(error, callback) {
107
+ if (!this.flushed && !this.sink.destroyed) this.sink.destroy();
108
+ callback(error);
109
+ }
110
+ };
111
+
59
112
  // src/Crypto/JSDecryptor.ts
60
113
  var import_blowfish_node = __toESM(require("blowfish-node"));
61
114
 
@@ -74,18 +127,107 @@ var BaseDecryptor = class {
74
127
  var JSDecryptor = class extends BaseDecryptor {
75
128
  constructor(...args) {
76
129
  super(...args);
77
- this.bfDecryptor = new import_blowfish_node.default(new Uint8Array(this.key), import_blowfish_node.MODE.CBC, import_blowfish_node.PADDING.NULL);
78
- this.bfDecryptor.setIv(new Uint8Array(this.iv));
130
+ const schedule = new import_blowfish_node.default(
131
+ new Uint8Array(this.key),
132
+ import_blowfish_node.MODE.CBC,
133
+ import_blowfish_node.PADDING.NULL
134
+ );
135
+ this.p = Uint32Array.from(schedule.p);
136
+ this.s0 = Uint32Array.from(schedule.s[0]);
137
+ this.s1 = Uint32Array.from(schedule.s[1]);
138
+ this.s2 = Uint32Array.from(schedule.s[2]);
139
+ this.s3 = Uint32Array.from(schedule.s[3]);
140
+ this.iv0 = this.iv[0] << 24 | this.iv[1] << 16 | this.iv[2] << 8 | this.iv[3];
141
+ this.iv1 = this.iv[4] << 24 | this.iv[5] << 16 | this.iv[6] << 8 | this.iv[7];
79
142
  }
80
143
  async decrypt(chunk) {
81
- const chunkUint = new Uint8Array(chunk);
82
- const decoded = this.bfDecryptor.decode(chunkUint, import_blowfish_node.TYPE.UINT8_ARRAY);
83
- return Buffer.from(decoded);
144
+ if (chunk.length % 8 !== 0) {
145
+ throw new Error("Decoded data should be multiple of 8 bytes");
146
+ }
147
+ const out = Buffer.from(chunk);
148
+ const view = new DataView(
149
+ out.buffer,
150
+ out.byteOffset,
151
+ out.byteLength
152
+ );
153
+ const { p, s0, s1, s2, s3 } = this;
154
+ let prevL = this.iv0;
155
+ let prevR = this.iv1;
156
+ for (let offset = 0; offset < out.length; offset += 8) {
157
+ let l = view.getUint32(offset, false);
158
+ let r = view.getUint32(offset + 4, false);
159
+ const cipherL = l;
160
+ const cipherR = r;
161
+ for (let round = 17; round > 1; round--) {
162
+ l ^= p[round];
163
+ let f = (s0[l >>> 24 & 255] + s1[l >>> 16 & 255] | 0) ^ s2[l >>> 8 & 255];
164
+ f = f + s3[l & 255] | 0;
165
+ r ^= f;
166
+ const tmp = l;
167
+ l = r;
168
+ r = tmp;
169
+ }
170
+ const swap = l;
171
+ l = r;
172
+ r = swap;
173
+ r ^= p[1];
174
+ l ^= p[0];
175
+ l ^= prevL;
176
+ r ^= prevR;
177
+ prevL = cipherL;
178
+ prevR = cipherR;
179
+ view.setUint32(offset, l, false);
180
+ view.setUint32(offset + 4, r, false);
181
+ }
182
+ return out;
84
183
  }
85
184
  };
86
185
 
87
- // src/utils/util.ts
88
- var IV = Buffer.from(Array.from({ length: 8 }, (_, x) => x));
186
+ // src/Crypto/StripeDecryptStream.ts
187
+ var import_node_stream2 = require("stream");
188
+ var STRIPE_SIZE = 2048;
189
+ var ENCRYPTED_STRIPE_INTERVAL = 3;
190
+ var StripeDecryptStream = class extends import_node_stream2.Transform {
191
+ constructor(decryptor) {
192
+ super();
193
+ this.stripeIndex = 0;
194
+ this.remainder = Buffer.alloc(0);
195
+ this.decryptor = decryptor;
196
+ }
197
+ async _transform(chunk, _encoding, callback) {
198
+ try {
199
+ const data = this.remainder.length ? Buffer.concat([this.remainder, chunk]) : chunk;
200
+ let offset = 0;
201
+ while (data.length - offset >= STRIPE_SIZE) {
202
+ const stripe = data.subarray(offset, offset + STRIPE_SIZE);
203
+ offset += STRIPE_SIZE;
204
+ this.push(await this.decodeStripe(stripe));
205
+ }
206
+ this.remainder = Buffer.from(data.subarray(offset));
207
+ callback();
208
+ } catch (error) {
209
+ callback(error);
210
+ }
211
+ }
212
+ async _flush(callback) {
213
+ try {
214
+ if (this.remainder.length) {
215
+ this.push(await this.decodeStripe(this.remainder));
216
+ this.remainder = Buffer.alloc(0);
217
+ }
218
+ callback();
219
+ } catch (error) {
220
+ callback(error);
221
+ }
222
+ }
223
+ async decodeStripe(stripe) {
224
+ const encrypted = this.stripeIndex++ % ENCRYPTED_STRIPE_INTERVAL === 0;
225
+ if (!encrypted || stripe.length % 8 !== 0) return stripe;
226
+ return this.decryptor.decrypt(stripe);
227
+ }
228
+ };
229
+
230
+ // src/utils/crypto.ts
89
231
  var rawCrypto;
90
232
  async function getCrypto() {
91
233
  if (!rawCrypto) {
@@ -94,6 +236,9 @@ async function getCrypto() {
94
236
  }
95
237
  return rawCrypto;
96
238
  }
239
+
240
+ // src/utils/util.ts
241
+ var IV = Buffer.from(Array.from({ length: 8 }, (_, x) => x));
97
242
  function isUrl(query) {
98
243
  try {
99
244
  const url = new URL(query);
@@ -149,10 +294,22 @@ async function searchOneTrack(query) {
149
294
  return trackData;
150
295
  }
151
296
  async function streamTrack(track, ext) {
297
+ const cache = ext.options.cache;
298
+ const trackId = extractTrackId(track.url);
299
+ if (cache) {
300
+ try {
301
+ const cached = await cache.read(trackId);
302
+ if (cached) {
303
+ ext.context.player.debug(`DEEZER CACHE HIT ${trackId}`);
304
+ return cached;
305
+ }
306
+ } catch (error) {
307
+ ext.context.player.debug(`DEEZER CACHE READ ERROR ${String(error)}`);
308
+ }
309
+ }
152
310
  const decryptionKey = ext.options.decryptionKey;
153
311
  if (!decryptionKey) throw new Error("MISSING DEEZER DECRYPTION KEY");
154
312
  const crypto = await getCrypto();
155
- const trackId = extractTrackId(track.url);
156
313
  const trackHash = crypto.createHash("md5").update(trackId, "ascii").digest("hex");
157
314
  const trackKey = Buffer.alloc(16);
158
315
  const Decryptor = ext.options.decryptor || JSDecryptor;
@@ -213,38 +370,32 @@ async function streamTrack(track, ext) {
213
370
  ext.context.player.debug("DEEZER FOUND MEDIA URL " + trackMediaUrl);
214
371
  const trackReq = await ext.fetch(trackMediaUrl);
215
372
  const readable = import_stream.Readable.fromWeb(trackReq.body);
216
- let buffer = Buffer.alloc(0);
217
- let i = 0;
218
- const bufferSize = 2048;
219
- const passThrough = new import_stream.PassThrough();
220
373
  const decryptor = new Decryptor(trackKey, IV);
221
- readable.on("readable", async () => {
222
- let chunk = null;
223
- while (true) {
224
- chunk = readable.read(bufferSize);
225
- if (!chunk) {
226
- if (readable.readableLength) {
227
- chunk = readable.read(readable.readableLength);
228
- buffer = Buffer.concat([buffer, chunk]);
229
- }
230
- break;
231
- } else {
232
- buffer = Buffer.concat([buffer, chunk]);
233
- }
234
- while (buffer.length >= bufferSize) {
235
- const bufferSized = buffer.subarray(0, bufferSize);
236
- if (i % 3 === 0) {
237
- const decipher = await decryptor.decrypt(bufferSized);
238
- passThrough.write(decipher);
239
- } else {
240
- passThrough.write(bufferSized);
241
- }
242
- i++;
243
- buffer = buffer.subarray(bufferSize);
244
- }
245
- }
374
+ const stream = new StripeDecryptStream(decryptor);
375
+ readable.on("error", (error) => stream.destroy(error));
376
+ readable.pipe(stream);
377
+ stream.once("close", () => {
378
+ if (!stream.readableEnded && !readable.destroyed) readable.destroy();
246
379
  });
247
- return passThrough;
380
+ if (!cache) return stream;
381
+ try {
382
+ const sink = await cache.write(trackId);
383
+ sink.on("error", (error) => {
384
+ ext.context.player.debug(`DEEZER CACHE WRITE ERROR ${String(error)}`);
385
+ });
386
+ const output = new CacheTapStream(sink);
387
+ stream.on("error", (error) => output.destroy(error));
388
+ output.once("close", () => {
389
+ if (output.readableEnded) return;
390
+ if (!stream.destroyed) stream.destroy();
391
+ if (!readable.destroyed) readable.destroy();
392
+ });
393
+ stream.pipe(output);
394
+ return output;
395
+ } catch (error) {
396
+ ext.context.player.debug(`DEEZER CACHE WRITE ERROR ${String(error)}`);
397
+ return stream;
398
+ }
248
399
  }
249
400
  var deezerRegex = {
250
401
  track: /(^https:)\/\/(www\.)?deezer.com\/([a-zA-Z]+\/)?track\/[0-9]+/,
@@ -342,6 +493,7 @@ var DeezerExtractor = class extends import_discord_player2.BaseExtractor {
342
493
  async deactivate() {
343
494
  if (this.__interval) clearInterval(this.__interval);
344
495
  this.protocols = [];
496
+ await this.options.cache?.close?.();
345
497
  }
346
498
  async validate(query, type) {
347
499
  return validate(query) || type === "deezer" || !isUrl(query);
@@ -419,24 +571,189 @@ DeezerExtractor.identifier = "com.retrouser955.discord-player.deezr-ext";
419
571
 
420
572
  // src/Crypto/NodeDecryptor.ts
421
573
  var NodeDecryptor = class extends BaseDecryptor {
422
- constructor(...args) {
423
- super(...args);
424
- (async () => {
425
- if (!(await getCrypto()).getCiphers().includes("bf-cbc")) throw new Error("Cannot find bf-cbc");
426
- })();
574
+ constructor() {
575
+ super(...arguments);
576
+ this.firstChunk = true;
427
577
  }
428
578
  async decrypt(chunk) {
579
+ if (chunk.length % 8 !== 0) {
580
+ throw new Error("Decoded data should be multiple of 8 bytes");
581
+ }
582
+ if (chunk.length === 0) return Buffer.alloc(0);
429
583
  const crypto = await getCrypto();
430
- const decipher = crypto.createDecipheriv("bf-cbc", this.key, this.iv).setAutoPadding(false);
431
- return Buffer.concat([decipher.update(chunk), decipher.final()]);
584
+ if (!this.decipher) {
585
+ try {
586
+ this.decipher = crypto.createDecipheriv(
587
+ "bf-cbc",
588
+ this.key,
589
+ this.iv
590
+ ).setAutoPadding(false);
591
+ } catch {
592
+ throw new Error(
593
+ "Cannot find bf-cbc. Start Node with --openssl-legacy-provider or use JSDecryptor."
594
+ );
595
+ }
596
+ this.previousCipherBlock = Buffer.alloc(8);
597
+ }
598
+ const out = this.decipher.update(chunk);
599
+ if (!this.firstChunk && this.previousCipherBlock && out.length >= 8) {
600
+ for (let i = 0; i < 8; i++) {
601
+ out[i] ^= this.previousCipherBlock[i] ^ this.iv[i];
602
+ }
603
+ }
604
+ this.firstChunk = false;
605
+ this.previousCipherBlock = Buffer.from(
606
+ chunk.subarray(chunk.length - 8)
607
+ );
608
+ return out;
609
+ }
610
+ };
611
+
612
+ // src/Cache/DiskAudioCache.ts
613
+ var import_node_crypto = require("crypto");
614
+ var import_node_fs = require("fs");
615
+ var import_promises2 = require("fs/promises");
616
+ var import_node_os = require("os");
617
+ var import_node_path = require("path");
618
+ var CACHE_EXTENSION = ".audio";
619
+ var TEMP_EXTENSION = ".part";
620
+ var TEMP_MAX_AGE = 24 * 60 * 60 * 1e3;
621
+ var DEFAULT_MAX_SONGS = 100;
622
+ var DEFAULT_MAX_AGE = 7 * 24 * 60 * 60 * 1e3;
623
+ var DEFAULT_CLEANUP_INTERVAL = 60 * 60 * 1e3;
624
+ var DiskAudioCache = class {
625
+ constructor(options = {}) {
626
+ this.closed = false;
627
+ this.directory = options.directory ?? (0, import_node_path.join)((0, import_node_os.tmpdir)(), "discord-player-deezer-cache");
628
+ this.maxSongs = options.maxSongs ?? DEFAULT_MAX_SONGS;
629
+ this.maxAge = options.maxAge ?? DEFAULT_MAX_AGE;
630
+ this.cleanupInterval = options.cleanupInterval ?? DEFAULT_CLEANUP_INTERVAL;
631
+ this.ready = (0, import_promises2.mkdir)(this.directory, { recursive: true }).then(
632
+ () => void 0
633
+ );
634
+ if (this.cleanupInterval > 0) {
635
+ this.timer = setInterval(() => {
636
+ void this.cleanup().catch(() => void 0);
637
+ }, this.cleanupInterval);
638
+ this.timer.unref();
639
+ }
640
+ void this.cleanup().catch(() => void 0);
641
+ }
642
+ async read(key) {
643
+ await this.ready;
644
+ const file = this.pathFor(key);
645
+ try {
646
+ const handle = await (0, import_promises2.open)(file, "r");
647
+ const now = /* @__PURE__ */ new Date();
648
+ await (0, import_promises2.utimes)(file, now, now).catch(() => void 0);
649
+ const stream = handle.createReadStream({ autoClose: false });
650
+ let released = false;
651
+ const release = () => {
652
+ if (released) return;
653
+ released = true;
654
+ void handle.close().catch(() => void 0);
655
+ };
656
+ stream.once("end", release);
657
+ stream.once("error", release);
658
+ stream.once("close", release);
659
+ return stream;
660
+ } catch (error) {
661
+ if (error.code === "ENOENT") return null;
662
+ throw error;
663
+ }
664
+ }
665
+ async write(key) {
666
+ if (this.closed) throw new Error("DiskAudioCache is closed");
667
+ await this.ready;
668
+ const target = this.pathFor(key);
669
+ const temp = `${target}.${(0, import_node_crypto.randomBytes)(8).toString("hex")}${TEMP_EXTENSION}`;
670
+ const out = (0, import_node_fs.createWriteStream)(temp);
671
+ let committed = false;
672
+ out.on("error", () => {
673
+ void (0, import_promises2.unlink)(temp).catch(() => void 0);
674
+ });
675
+ out.once("finish", () => {
676
+ committed = true;
677
+ void (0, import_promises2.rename)(temp, target).then(() => this.cleanup()).catch(async () => {
678
+ await (0, import_promises2.unlink)(temp).catch(() => void 0);
679
+ });
680
+ });
681
+ out.once("close", () => {
682
+ if (!committed) void (0, import_promises2.unlink)(temp).catch(() => void 0);
683
+ });
684
+ return out;
685
+ }
686
+ async delete(key) {
687
+ await this.ready;
688
+ await (0, import_promises2.unlink)(this.pathFor(key)).catch((error) => {
689
+ if (error.code !== "ENOENT") throw error;
690
+ });
691
+ }
692
+ cleanup() {
693
+ if (!this.cleaning) {
694
+ this.cleaning = this.runCleanup().finally(() => {
695
+ this.cleaning = void 0;
696
+ });
697
+ }
698
+ return this.cleaning;
699
+ }
700
+ async close() {
701
+ this.closed = true;
702
+ if (this.timer) {
703
+ clearInterval(this.timer);
704
+ this.timer = void 0;
705
+ }
706
+ if (this.cleaning) await this.cleaning.catch(() => void 0);
707
+ }
708
+ pathFor(key) {
709
+ const hash = (0, import_node_crypto.createHash)("sha256").update(key).digest("hex");
710
+ return (0, import_node_path.join)(this.directory, hash + CACHE_EXTENSION);
711
+ }
712
+ async runCleanup() {
713
+ await this.ready;
714
+ const now = Date.now();
715
+ const entries = await (0, import_promises2.readdir)(this.directory, { withFileTypes: true });
716
+ const songs = [];
717
+ for (const entry of entries) {
718
+ if (!entry.isFile()) continue;
719
+ const isSong = entry.name.endsWith(CACHE_EXTENSION);
720
+ const isTemp = entry.name.endsWith(TEMP_EXTENSION);
721
+ if (!isSong && !isTemp) continue;
722
+ const file = (0, import_node_path.join)(this.directory, entry.name);
723
+ let info;
724
+ try {
725
+ info = await (0, import_promises2.stat)(file);
726
+ } catch {
727
+ continue;
728
+ }
729
+ if (isTemp) {
730
+ if (now - info.mtimeMs > TEMP_MAX_AGE) {
731
+ await (0, import_promises2.unlink)(file).catch(() => void 0);
732
+ }
733
+ continue;
734
+ }
735
+ if (this.maxAge > 0 && now - info.mtimeMs > this.maxAge) {
736
+ await (0, import_promises2.unlink)(file).catch(() => void 0);
737
+ continue;
738
+ }
739
+ songs.push({ file, mtimeMs: info.mtimeMs });
740
+ }
741
+ if (this.maxSongs > 0 && songs.length > this.maxSongs) {
742
+ songs.sort((a, b) => b.mtimeMs - a.mtimeMs);
743
+ for (let i = this.maxSongs; i < songs.length; i++) {
744
+ await (0, import_promises2.unlink)(songs[i].file).catch(() => void 0);
745
+ }
746
+ }
432
747
  }
433
748
  };
434
749
  // Annotate the CommonJS export names for ESM import in node:
435
750
  0 && (module.exports = {
436
751
  BaseDecryptor,
437
752
  DeezerExtractor,
753
+ DiskAudioCache,
438
754
  JSDecryptor,
439
755
  NodeDecryptor,
756
+ StripeDecryptStream,
440
757
  Warnings,
441
758
  buildTrackFromSearch,
442
759
  deezerRegex,
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
- {
2
- "name": "discord-player-deezer",
3
- "version": "2.6.0",
4
- "description": "A custom extractor made for discord-player that enables you to extract from Deezer.",
5
- "main": "dist/index.js",
6
- "author": "retro_ig",
7
- "license": "MIT",
8
- "dependencies": {
9
- "@mithron/deezer-music-metadata": "^1.0.3",
10
- "blowfish-node": "^1.1.4"
11
- },
12
- "devDependencies": {
13
- "@discord-player/extractor": "^7.1.0",
14
- "@types/node": "^22.10.10",
15
- "discord-player": "^7.1.0",
16
- "prettier": "^3.4.2",
17
- "tslint": "^6.1.3",
18
- "tslint-config-prettier": "^1.18.0",
19
- "tsup": "^8.3.5",
20
- "typescript": "^5.7.2"
21
- },
22
- "scripts": {
23
- "build": "yarn lint && tsup",
24
- "lint": "tslint -p tsconfig.json",
25
- "npm:publish": "yarn build && npm publish --access public",
26
- "prepare": "tsup"
27
- },
28
- "repository": {
29
- "type": "git",
30
- "url": "git+https://github.com/retrouser955/discord-player-deezer.git"
31
- },
32
- "bugs": {
33
- "url": "https://github.com/retrouser955/discord-player-deezer/issues"
34
- },
35
- "packageManager": "yarn@4.5.1+sha512.341db9396b6e289fecc30cd7ab3af65060e05ebff4b3b47547b278b9e67b08f485ecd8c79006b405446262142c7a38154445ef7f17c1d5d1de7d90bf9ce7054d"
36
- }
1
+ {
2
+ "name": "discord-player-deezer",
3
+ "version": "3.0.0-dev.0",
4
+ "description": "A custom extractor made for discord-player that enables you to extract from Deezer.",
5
+ "main": "dist/index.js",
6
+ "author": "retro_ig",
7
+ "license": "MIT",
8
+ "dependencies": {
9
+ "@mithron/deezer-music-metadata": "^1.0.3",
10
+ "blowfish-node": "^1.1.4"
11
+ },
12
+ "devDependencies": {
13
+ "@discord-player/extractor": "^7.1.0",
14
+ "@types/node": "^22.10.10",
15
+ "discord-player": "^7.1.0",
16
+ "prettier": "^3.4.2",
17
+ "tslint": "^6.1.3",
18
+ "tslint-config-prettier": "^1.18.0",
19
+ "tsup": "^8.3.5",
20
+ "typescript": "^5.7.2"
21
+ },
22
+ "scripts": {
23
+ "build": "yarn lint && tsup",
24
+ "lint": "tslint -p tsconfig.json",
25
+ "npm:publish": "yarn build && npm publish --access public",
26
+ "prepare": "tsup"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/retrouser955/discord-player-deezer.git"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/retrouser955/discord-player-deezer/issues"
34
+ },
35
+ "packageManager": "yarn@4.5.1+sha512.341db9396b6e289fecc30cd7ab3af65060e05ebff4b3b47547b278b9e67b08f485ecd8c79006b405446262142c7a38154445ef7f17c1d5d1de7d90bf9ce7054d"
36
+ }
package/readme.md CHANGED
@@ -1,35 +1,57 @@
1
- # Discord Player Deezer
2
-
3
- Discord Player Deezer is a Deezer platform plugin for discord-player
4
-
5
- # Installation
6
-
7
- ```bash
8
- $ npm install discord-player-deezer
9
- ```
10
-
11
- # Register the extractor
12
-
13
- ```ts
14
- import { DeezerExtractor } from "discord-player-deezer"
15
- import { Player } from "discord-player"
16
-
17
- const player = new Player(...)
18
-
19
- await player.extractors.register(DeezerExtractor, {})
20
- ```
21
-
22
- # Extracting Streams
23
-
24
- As Deezer sends DMCA to repositories containing the hard-coded decryption key, it is not provided. You can find this key in the code of related projects (deezer downloaders) and your client-side JavaScript code.
25
-
26
- ```ts
27
- import { DeezerExtractor } from "discord-player-deezer"
28
- import { Player } from "discord-player"
29
-
30
- const player = new Player(...)
31
-
32
- await player.extractors.register(DeezerExtractor, {
33
- decryptionKey: "master-decryption-key"
34
- })
35
- ```
1
+ # Discord Player Deezer
2
+
3
+ Discord Player Deezer is a Deezer platform plugin for discord-player
4
+
5
+ # Installation
6
+
7
+ ```bash
8
+ $ npm install discord-player-deezer
9
+ ```
10
+
11
+ # Register the extractor
12
+
13
+ ```ts
14
+ import { DeezerExtractor } from "discord-player-deezer"
15
+ import { Player } from "discord-player"
16
+
17
+ const player = new Player(...)
18
+
19
+ await player.extractors.register(DeezerExtractor, {})
20
+ ```
21
+
22
+ # Extracting Streams
23
+
24
+ As Deezer sends DMCA to repositories containing the hard-coded decryption key, it is not provided. You can find this key in the code of related projects (deezer downloaders) and your client-side JavaScript code.
25
+
26
+ ```ts
27
+ import { DeezerExtractor } from "discord-player-deezer"
28
+ import { Player } from "discord-player"
29
+
30
+ const player = new Player(...)
31
+
32
+ await player.extractors.register(DeezerExtractor, {
33
+ decryptionKey: "master-decryption-key"
34
+ })
35
+ ```
36
+
37
+ # Caching (optional)
38
+
39
+ Pass a `cache` to store decrypted tracks on disk. Caching is disabled unless you provide one; cached tracks skip both the download and the decryption step on repeat plays.
40
+
41
+ ```ts
42
+ import { DeezerExtractor, DiskAudioCache } from "discord-player-deezer"
43
+
44
+ const cache = new DiskAudioCache({
45
+ directory: "./deezer-cache", // default: <tmp>/discord-player-deezer-cache
46
+ maxSongs: 100, // oldest entries are removed first
47
+ maxAge: 7 * 24 * 60 * 60 * 1000, // expire entries after 7 days (0 = never)
48
+ cleanupInterval: 60 * 60 * 1000 // run cleanup hourly (0 = only after writes)
49
+ })
50
+
51
+ await player.extractors.register(DeezerExtractor, {
52
+ decryptionKey: "master-decryption-key",
53
+ cache
54
+ })
55
+ ```
56
+
57
+ You can also implement `IAudioCache` to use a different storage backend.