discord-player-deezer 2.0.0-beta.1 → 2.0.0-beta.3

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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Track, ExtractorStreamable, BaseExtractor, ExtractorSearchContext, Playlist as Playlist$1, ExtractorInfo } from 'discord-player';
1
+ import { Track, ExtractorStreamable, BaseExtractor, ExtractorSearchContext, Playlist as Playlist$1, ExtractorInfo, Player } from 'discord-player';
2
2
  import { Playlist, Track as Track$1 } from '@mithron/deezer-music-metadata';
3
3
  import * as crypto from 'crypto';
4
4
  import { PassThrough } from 'stream';
@@ -28,11 +28,33 @@ declare class DeezerExtractor extends BaseExtractor<DeezerExtractorOptions> {
28
28
  validate(query: string): Promise<boolean>;
29
29
  buildPlaylistData(data: Playlist, handleContext: ExtractorSearchContext): Playlist$1;
30
30
  handle(query: string, context: ExtractorSearchContext): Promise<ExtractorInfo>;
31
- buildTrack(track: Track$1, handleContext: ExtractorSearchContext): Track<unknown>;
31
+ buildTrack(track: Track$1, { requestedBy }: ExtractorSearchContext): Track<unknown>;
32
+ bridge(track: Track): Promise<ExtractorStreamable | null>;
32
33
  stream(info: Track): Promise<ExtractorStreamable>;
33
34
  }
34
35
 
35
36
  declare function getCrypto(): Promise<typeof crypto>;
37
+ type ArrayOrObject<T> = T | T[];
38
+ interface DeezerSearchTrackResponse {
39
+ data: {
40
+ link: string;
41
+ title: string;
42
+ album: {
43
+ cover_xl?: string;
44
+ cover_medium?: string;
45
+ cover_small?: string;
46
+ cover?: string;
47
+ };
48
+ artist: {
49
+ name: string;
50
+ };
51
+ duration: number;
52
+ type: "track";
53
+ }[];
54
+ }
55
+ declare function buildTrackFromSearch(track: DeezerSearchTrackResponse, player: Player, requestedBy?: Track['requestedBy']): Track<unknown>[];
56
+ declare function extractTrackId(query: string): string;
57
+ declare function searchOneTrack(query: string): Promise<DeezerSearchTrackResponse | undefined>;
36
58
  declare function streamTrack(track: Track, ext: DeezerExtractor): Promise<PassThrough>;
37
59
  declare const deezerRegex: {
38
60
  readonly track: RegExp;
@@ -41,4 +63,4 @@ declare const deezerRegex: {
41
63
  };
42
64
  declare function validate(query: string): boolean;
43
65
 
44
- export { DeezerExtractor, type DeezerExtractorOptions, type DeezerUserInfo, deezerRegex, getCrypto, streamTrack, validate };
66
+ export { type ArrayOrObject, DeezerExtractor, type DeezerExtractorOptions, type DeezerSearchTrackResponse, type DeezerUserInfo, buildTrackFromSearch, deezerRegex, extractTrackId, getCrypto, searchOneTrack, streamTrack, validate };
package/dist/index.js CHANGED
@@ -31,18 +31,22 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
33
  DeezerExtractor: () => DeezerExtractor,
34
+ buildTrackFromSearch: () => buildTrackFromSearch,
34
35
  deezerRegex: () => deezerRegex,
36
+ extractTrackId: () => extractTrackId,
35
37
  getCrypto: () => getCrypto,
38
+ searchOneTrack: () => searchOneTrack,
36
39
  streamTrack: () => streamTrack,
37
40
  validate: () => validate
38
41
  });
39
42
  module.exports = __toCommonJS(src_exports);
40
43
 
41
44
  // src/DeezerExtractor.ts
42
- var import_discord_player = require("discord-player");
45
+ var import_discord_player2 = require("discord-player");
43
46
  var import_deezer_music_metadata = require("@mithron/deezer-music-metadata");
44
47
 
45
48
  // src/utils/util.ts
49
+ var import_discord_player = require("discord-player");
46
50
  var import_stream = require("stream");
47
51
  var IV = Buffer.from(Array.from({ length: 8 }, (_, x) => x));
48
52
  var rawCrypto;
@@ -53,13 +57,43 @@ async function getCrypto() {
53
57
  }
54
58
  return rawCrypto;
55
59
  }
60
+ var DeezerAPIRoutes = {
61
+ searchTrack(query, limit) {
62
+ const url = `https://api.deezer.com/search/track?q=${encodeURIComponent(query)}&${limit ? `limit=${limit}` : ""}`;
63
+ return url;
64
+ }
65
+ };
66
+ function buildTrackFromSearch(track, player, requestedBy) {
67
+ return track.data.map((v) => new import_discord_player.Track(player, {
68
+ source: "arbitrary",
69
+ duration: import_discord_player.Util.buildTimeCode(import_discord_player.Util.parseMS(v.duration * 1e3)),
70
+ author: Array.isArray(v.artist) ? v.artist.map((a) => a.name).join(", ") : v.artist.name,
71
+ url: v.link,
72
+ title: v.title,
73
+ thumbnail: v.album.cover_xl || v.album.cover_medium || v.album.cover || v.album.cover_small || "https://play-lh.googleusercontent.com/xtIOV8iPeAY4GrldTDo3CbLAEpbea2DqnfxaB4Nn2p5qz6KAiumY74qH86pgu1HA1A",
74
+ live: false,
75
+ requestedBy
76
+ }));
77
+ }
78
+ function extractTrackId(query) {
79
+ if (!validate(query)) throw new Error("Invalid track url");
80
+ const trackIdWithUrlParams = query.split("/").at(-1);
81
+ if (!trackIdWithUrlParams) throw new Error("Cannot find track ID");
82
+ return trackIdWithUrlParams.split("?")[0];
83
+ }
84
+ async function searchOneTrack(query) {
85
+ const url = DeezerAPIRoutes.searchTrack(query, 1);
86
+ const trackRes = await fetch(url);
87
+ if (trackRes.status !== 200) throw new Error("Fetch failed");
88
+ const trackData = await trackRes.json();
89
+ const track = trackData;
90
+ return track;
91
+ }
56
92
  async function streamTrack(track, ext) {
57
- const trackIdWithUrlParams = track.url.split("/").at(-1);
58
- if (!trackIdWithUrlParams || !validate(track.url)) throw new Error("INVALID TRACK");
59
93
  const decryptionKey = ext.options.decryptionKey;
60
94
  if (!decryptionKey) throw new Error("MISSING DEEZER DECRYPTION KEY");
61
95
  const crypto = await getCrypto();
62
- const trackId = trackIdWithUrlParams.split("?")[0];
96
+ const trackId = extractTrackId(track.url);
63
97
  const trackHash = crypto.createHash("md5").update(trackId, "ascii").digest("hex");
64
98
  const trackKey = Buffer.alloc(16);
65
99
  for (let iter = 0; iter < 16; iter++)
@@ -153,7 +187,7 @@ function validate(query) {
153
187
  }
154
188
 
155
189
  // src/DeezerExtractor.ts
156
- var DeezerExtractor = class extends import_discord_player.BaseExtractor {
190
+ var DeezerExtractor = class extends import_discord_player2.BaseExtractor {
157
191
  async activate() {
158
192
  if (!this.options.decryptionKey) process.emitWarning("Decryption Key missing! This is needed for extracting streams.");
159
193
  else {
@@ -178,7 +212,7 @@ var DeezerExtractor = class extends import_discord_player.BaseExtractor {
178
212
  buildPlaylistData(data, handleContext) {
179
213
  const raw = data.url.split("/");
180
214
  const identifier = raw[raw.length - 1].split("?")[0];
181
- return new import_discord_player.Playlist(this.context.player, {
215
+ return new import_discord_player2.Playlist(this.context.player, {
182
216
  title: data.name,
183
217
  thumbnail: data.thumbnail[0].url,
184
218
  author: {
@@ -202,17 +236,24 @@ var DeezerExtractor = class extends import_discord_player.BaseExtractor {
202
236
  }
203
237
  throw new Error("Unable to get data from Deezer");
204
238
  }
205
- buildTrack(track, handleContext) {
206
- return new import_discord_player.Track(this.context.player, {
239
+ buildTrack(track, { requestedBy }) {
240
+ return new import_discord_player2.Track(this.context.player, {
207
241
  title: track.name,
208
242
  author: track.author.map((v) => v.name).join(", "),
209
243
  url: track.url,
210
244
  source: "arbitrary",
211
245
  thumbnail: track.thumbnail[0].url,
212
- duration: import_discord_player.Util.buildTimeCode(import_discord_player.Util.parseMS(track.duration)),
213
- requestedBy: handleContext.requestedBy
246
+ duration: import_discord_player2.Util.buildTimeCode(import_discord_player2.Util.parseMS(track.duration)),
247
+ requestedBy
214
248
  });
215
249
  }
250
+ async bridge(track) {
251
+ const deezerTrack = await searchOneTrack(`${track.author} ${track.source === "youtube" ? track.cleanTitle : track.title}`);
252
+ if (!deezerTrack || !deezerTrack?.data[0]) return null;
253
+ const dpTrack = buildTrackFromSearch(deezerTrack, this.context.player, track.requestedBy);
254
+ const stream = this.stream(dpTrack[0]);
255
+ return stream;
256
+ }
216
257
  stream(info) {
217
258
  return streamTrack(info, this);
218
259
  }
@@ -221,8 +262,11 @@ DeezerExtractor.identifier = "com.retrouser955.discord-player.deezr-ext";
221
262
  // Annotate the CommonJS export names for ESM import in node:
222
263
  0 && (module.exports = {
223
264
  DeezerExtractor,
265
+ buildTrackFromSearch,
224
266
  deezerRegex,
267
+ extractTrackId,
225
268
  getCrypto,
269
+ searchOneTrack,
226
270
  streamTrack,
227
271
  validate
228
272
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "discord-player-deezer",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.3",
4
4
  "description": "A custom extractor made for discord-player that enables you to extract from Deezer.",
5
5
  "main": "dist/index.js",
6
6
  "author": "retro_ig",
@@ -11,7 +11,6 @@
11
11
  },
12
12
  "devDependencies": {
13
13
  "@discord-player/extractor": "^4.5.1",
14
- "cross-env": "^7.0.3",
15
14
  "discord-player": "^6.7.1",
16
15
  "prettier": "^3.4.2",
17
16
  "tslint": "^6.1.3",
@@ -22,7 +21,7 @@
22
21
  "scripts": {
23
22
  "build": "yarn lint && tsup",
24
23
  "lint": "tslint -p tsconfig.json",
25
- "npm:publish": "cross-env NODE_OPTIONS=--openssl-legacy-provider yarn build && npm publish --access public"
24
+ "npm:publish": "yarn build && npm publish --access public"
26
25
  },
27
26
  "repository": {
28
27
  "type": "git",
package/readme.md CHANGED
@@ -1,65 +1,43 @@
1
- # Discord Player Deezer Extractor
1
+ # Discord Player Deezer
2
2
 
3
- Discord Player Deezer Extractor. An extractor made for discord-player for **Deezer** support. Deezer extractor works by either making a request to the Deezer API or extracting metadata from the Deezer site. Because we cannot get streams from deezer itself, the extractor uses the extracted data to stream from youtube!
3
+ Discord Player Deezer is a Deezer platform plugin for discord-player
4
4
 
5
- ## Installing the extractor
5
+ # Installation
6
6
 
7
7
  ```bash
8
- npm install discord-player-deezer
9
- # or
10
- yarn add discord-player-deezer
8
+ $ npm install discord-player-deezer
11
9
  ```
12
10
 
13
- ## Loading the extractor
11
+ # Register the extractor
14
12
 
15
- ### CJS
16
- ```js
17
- const DeezerExtractor = require("discord-player-deezer").default // or const { default: DeezerExtractor } = require("discord-player-deezer")
18
- const player = getMainPlayerSomehow()
13
+ ```ts
14
+ import { DeezerExtractor } from "discord-player-deezer"
15
+ import { Player } from "discord-player"
19
16
 
20
- player.extractors.register(DeezerExtractor)
21
- ```
17
+ const player = new Player(...)
22
18
 
23
- ### ESM
24
- ```js
25
- import { default as DeezerExtractor } from "discord-player-deezer"
19
+ await player.extractors.register(DeezerExtractor, {})
20
+ ```
26
21
 
27
- const player = getMainPlayerSomehow()
22
+ # Extracting Streams
28
23
 
29
- player.extractors.register(DeezerExtractor)
30
- ```
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.
31
25
 
32
- ### Typescript
33
26
  ```ts
34
- import DeezerExtractor from "discord-player-deezer"
27
+ import { DeezerExtractor } from "discord-player-deezer"
28
+ import { Player } from "discord-player"
35
29
 
36
- const player = getMainPlayerSomehow()
30
+ const player = new Player(...)
37
31
 
38
- player.extractors.register(DeezerExtractor)
32
+ await player.extractors.register(DeezerExtractor, {
33
+ decryptionKey: "master-decryption-key"
34
+ })
39
35
  ```
40
36
 
41
- *note: be sure to register it before loading the default extractors to make sure any conflicts with discord-player's default attachment extractor is resolved!*
42
-
43
- That's it! See the magic happen as you bot is now able to play from Deezer URLs
37
+ # Important information
44
38
 
45
- # Options
39
+ As Node has migrated from openssl for decryption, we must use the `--openssl-legacy-provider` flag when starting our application with stream extraction
46
40
 
47
- DP Deezer accepts the following options.
48
- ```ts
49
- interface DeezerOptions {
50
- forceEngine?: EngineType;
51
- createStream?: () => Promise<string|Readable>;
52
- beforeCreateStream?: () => Promise<unknown>|unknown;
53
- }
54
- ```
55
- One thing to keep in mind is, while using the two functions, if you want to access track data, you must you `useTrack()` function exported by the library. For example ...
56
-
57
- ```ts
58
- player.extractors.register(DeezerExtractor, {
59
- createStream: () => {
60
- const track = useTrack()
61
-
62
- return getStreamSomehow(track)
63
- }
64
- })
41
+ ```bash
42
+ $ node --openssl-legacy-provider yourfile.js
65
43
  ```
@@ -1,17 +0,0 @@
1
- name: publish dp deezer
2
- on:
3
- release:
4
- types: [published]
5
-
6
- jobs:
7
- publish-npm:
8
- runs-on: ubuntu-latest
9
- steps:
10
- - uses: actions/checkout@v2
11
- - uses: actions/setup-node@v1
12
- with:
13
- node-version: 20
14
- registry-url: https://registry.npmjs.org/
15
- - run: yarn npm:publish
16
- env:
17
- NODE_AUTH_TOKEN: ${{secrets.npm_token}}
@@ -1,107 +0,0 @@
1
- import { BaseExtractor, ExtractorSearchContext, ExtractorStreamable, Track, Playlist, Util as DPUtil, ExtractorInfo } from "discord-player"
2
- import { Playlist as DeezerPlaylist, Track as DeezerTrack, getData } from "@mithron/deezer-music-metadata";
3
- import { getCrypto, streamTrack, validate } from "./utils/util";
4
-
5
- /**
6
- * -------------------------------NOTICE-------------------------------------
7
- * STREAMING CODE IS MAINLY TAKEN FROM https://github.com/PerformanC/NodeLink
8
- * WHICH HAS THE "BSD 2-Clause "Simplified" License"
9
- *
10
- * PLEASE SHOW THE ORIGINAL AUTHOR SUPPORT BY STARING HIS GITHUB REPO
11
- * --------------------------------------------------------------------------
12
- */
13
-
14
- export type DeezerExtractorOptions = {
15
- decryptionKey?: string; // needed for decrypting deezer songs
16
- createStream?: (track: Track, ext: DeezerExtractor) => Promise<ExtractorStreamable>
17
- }
18
-
19
- export type DeezerUserInfo = {
20
- cookie: string;
21
- licenseToken: string;
22
- csrfToken: string;
23
- mediaUrl: string;
24
- }
25
-
26
- export class DeezerExtractor extends BaseExtractor<DeezerExtractorOptions> {
27
- static identifier: string = "com.retrouser955.discord-player.deezr-ext"
28
- userInfo!: DeezerUserInfo
29
-
30
- async activate(): Promise<void> {
31
- if(!this.options.decryptionKey) process.emitWarning("Decryption Key missing! This is needed for extracting streams.")
32
- else {
33
- // extract deezer username
34
- // dynamically load crypto because some might not want streaming
35
- const crypto = await getCrypto()
36
- const randomToken = crypto.randomBytes(16).toString("hex")
37
- const deezerUsrDataUrl = `https://www.deezer.com/ajax/gw-light.php?method=deezer.getUserData&input=3&api_version=1.0&api_token=${randomToken}`
38
-
39
- const usrDataRes = await fetch(deezerUsrDataUrl)
40
- const cookie = usrDataRes.headers.get("set-cookie")!
41
- this.userInfo.cookie = cookie
42
- const usrData = await usrDataRes.json()
43
-
44
- const licenseToken = usrData.results.USER.OPTIONS.license_token
45
- if(typeof licenseToken !== "string") throw new Error("Unable to get licenseToken")
46
- this.userInfo.licenseToken = licenseToken
47
-
48
- const csrfToken = usrData.results.checkForm
49
- if(typeof csrfToken !== "string") throw new Error("Unable to get csrf token which is required for decryption")
50
-
51
- this.userInfo.mediaUrl = usrData.results.URL_MEDIA || "https://media.deezer.com"
52
- }
53
- }
54
-
55
- async validate(query: string): Promise<boolean> {
56
- return validate(query)
57
- }
58
-
59
- buildPlaylistData(data: DeezerPlaylist, handleContext: ExtractorSearchContext) {
60
- const raw: string[] = data.url.split("/")
61
- const identifier: string = raw[raw.length - 1].split("?")[0]
62
-
63
- return new Playlist(this.context.player, {
64
- title: data.name,
65
- thumbnail: data.thumbnail[0].url,
66
- author: {
67
- name: data.artist.name,
68
- url: data.artist.url
69
- },
70
- type: data.type,
71
- tracks: data.tracks.map((v) => this.buildTrack(v, handleContext)),
72
- description: "",
73
- source: "arbitrary",
74
- id: identifier,
75
- url: data.url
76
- })
77
- }
78
-
79
- async handle(query: string, context: ExtractorSearchContext): Promise<ExtractorInfo> {
80
- const metadata = await getData(query)
81
-
82
- if(metadata?.type === "song") return this.createResponse(null, [this.buildTrack(metadata, context)])
83
- if(metadata?.type === "playlist" || metadata?.type === "album") {
84
- const playlist = this.buildPlaylistData(metadata, context)
85
-
86
- return this.createResponse(playlist, playlist.tracks)
87
- }
88
-
89
- throw new Error("Unable to get data from Deezer")
90
- }
91
-
92
- buildTrack(track: DeezerTrack, handleContext: ExtractorSearchContext) {
93
- return new Track(this.context.player, {
94
- title: track.name,
95
- author: track.author.map((v) => v.name).join(", "),
96
- url: track.url,
97
- source: "arbitrary",
98
- thumbnail: track.thumbnail[0].url,
99
- duration: DPUtil.buildTimeCode(DPUtil.parseMS(track.duration)),
100
- requestedBy: handleContext.requestedBy
101
- })
102
- }
103
-
104
- stream(info: Track): Promise<ExtractorStreamable> {
105
- return streamTrack(info, this)
106
- }
107
- }
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./DeezerExtractor"
2
- export * from "./utils/util"
package/src/utils/util.ts DELETED
@@ -1,144 +0,0 @@
1
- import { Track } from "discord-player";
2
- import type { DeezerExtractor } from "../DeezerExtractor";
3
- import { Readable, PassThrough } from 'stream'
4
- import type { BinaryLike, CipherGCMTypes, CipherKey, Decipher } from "crypto";
5
-
6
- const IV = Buffer.from(Array.from({ length: 8 }, (_, x) => x))
7
-
8
- let rawCrypto: typeof import("crypto")
9
-
10
- export async function getCrypto() {
11
- if (!rawCrypto) {
12
- rawCrypto = await import("crypto")
13
- return rawCrypto
14
- }
15
-
16
- return rawCrypto
17
- }
18
-
19
- export async function streamTrack(track: Track, ext: DeezerExtractor) {
20
- const trackIdWithUrlParams = track.url.split("/").at(-1)
21
- if (!trackIdWithUrlParams || !validate(track.url)) throw new Error("INVALID TRACK") // not a deezer track
22
-
23
- const decryptionKey = ext.options.decryptionKey
24
- if (!decryptionKey) throw new Error("MISSING DEEZER DECRYPTION KEY") // cant decrypt due to missing key
25
-
26
- const crypto = await getCrypto()
27
- const trackId = trackIdWithUrlParams.split("?")[0]
28
-
29
- const trackHash = crypto.createHash("md5").update(trackId, "ascii").digest("hex")
30
- const trackKey = Buffer.alloc(16)
31
-
32
- for (let iter = 0; iter < 16; iter++)
33
- /* tslint:disable-next-line no-bitwise */
34
- trackKey.writeInt8(trackHash[iter].charCodeAt(0) ^ trackHash[iter + 16].charCodeAt(0) ^ decryptionKey[iter].charCodeAt(0), iter)
35
-
36
- const trackInfoRes = await fetch(`https://www.deezer.com/ajax/gw-light.php?method=song.getListData&input=3&api_version=1.0&api_token=${ext.userInfo.csrfToken}`, {
37
- method: "POST",
38
- headers: {
39
- Cookie: ext.userInfo.cookie,
40
- 'User-Agent': "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0",
41
- 'DNT': '1'
42
- },
43
- body: JSON.stringify({
44
- sng_ids: [trackId]
45
- })
46
- })
47
-
48
- const trackInfo = await trackInfoRes.json()
49
-
50
- // no streaming data found
51
- if (Array.isArray(trackInfo.error) && (trackInfo.error as unknown[]).length !== 0) throw new Error("Unable to extract track\n" + JSON.stringify(trackInfo.error))
52
- if (typeof trackInfo.error === "object" && Object.keys(trackInfo.error).length !== 0) throw new Error("Unable to extract track\n" + JSON.stringify(trackInfo.error))
53
-
54
- const info = trackInfo.data[0]
55
-
56
- const streamInfoRes = await fetch(`${ext.userInfo.mediaUrl}/v1/get-url`, {
57
- method: "POST",
58
- body: JSON.stringify({
59
- license_token: ext.userInfo.licenseToken,
60
- media: [{
61
- type: 'FULL',
62
- formats: [{
63
- cipher: 'BF_CBC_STRIPE',
64
- format: 'FLAC'
65
- }, {
66
- cipher: 'BF_CBC_STRIPE',
67
- format: 'MP3_256'
68
- }, {
69
- cipher: 'BF_CBC_STRIPE',
70
- format: 'MP3_128'
71
- }, {
72
- cipher: 'BF_CBC_STRIPE',
73
- format: 'MP3_MISC'
74
- }]
75
- }],
76
- track_tokens: [info.TRACK_TOKEN]
77
- })
78
- })
79
-
80
- const streamInfo = await streamInfoRes.json()
81
-
82
- const trackMediaUrl = streamInfo.data[0].media[0].sources[0].url
83
-
84
- const trackReq = await fetch(trackMediaUrl)
85
- // @ts-ignore
86
- const readable = Readable.fromWeb(trackReq.body)
87
- let buffer = Buffer.alloc(0)
88
- let i = 0
89
-
90
- const bufferSize = 2048 // 2mb
91
-
92
- const passThrough = new PassThrough()
93
-
94
- readable.on("readable", () => {
95
- let chunk = null;
96
- while (true) {
97
- chunk = readable.read(bufferSize)
98
-
99
- if (!chunk) {
100
- if (readable.readableLength) {
101
- chunk = readable.read(readable.readableLength)
102
- buffer = Buffer.concat([buffer, chunk])
103
- }
104
- break;
105
- } else {
106
- buffer = Buffer.concat([buffer, chunk])
107
- }
108
-
109
- while (buffer.length >= bufferSize) {
110
- const bufferSized = buffer.subarray(0, bufferSize)
111
-
112
- if (i % 3 === 0) {
113
- const decipher = crypto.createDecipheriv(
114
- 'bf-cbc' as unknown as CipherGCMTypes,
115
- trackKey as unknown as CipherKey,
116
- IV as unknown as BinaryLike
117
- ).setAutoPadding(false) as unknown as Decipher
118
-
119
- // @ts-ignore
120
- passThrough.write(decipher.update(bufferSized as unknown as ArrayBufferView))
121
- passThrough.write(decipher.final())
122
- } else {
123
- passThrough.write(bufferSized)
124
- }
125
-
126
- i++
127
-
128
- buffer = buffer.subarray(bufferSize)
129
- }
130
- }
131
- })
132
-
133
- return passThrough
134
- }
135
-
136
- export const deezerRegex = {
137
- track: /(^https:)\/\/(www\.)?deezer.com\/([a-zA-Z]+\/)?track\/[0-9]+/,
138
- playlistNalbums: /(^https:)\/\/(www\.)?deezer.com\/[a-zA-Z]+\/(playlist|album)\/[0-9]+(\?)?(.*)/,
139
- share: /(^https:)\/\/deezer\.page\.link\/[A-Za-z0-9]+/
140
- } as const;
141
-
142
- export function validate(query: string) {
143
- return deezerRegex.track.test(query) ?? deezerRegex.playlistNalbums.test(query) ?? deezerRegex.share.test(query)
144
- }