discord-player-deezer 2.2.0-dev.0 → 2.2.1-dev.2

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, Player } from 'discord-player';
1
+ import { Track, ExtractorStreamable, BaseExtractor, SearchQueryType, 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';
@@ -30,7 +30,8 @@ declare class DeezerExtractor extends BaseExtractor<DeezerExtractorOptions> {
30
30
  static identifier: string;
31
31
  userInfo: DeezerUserInfo;
32
32
  activate(): Promise<void>;
33
- validate(query: string): Promise<boolean>;
33
+ deactivate(): Promise<void>;
34
+ validate(query: string, type: SearchQueryType & "deezer"): Promise<boolean>;
34
35
  buildPlaylistData(data: Playlist, handleContext: ExtractorSearchContext): Playlist$1;
35
36
  handle(query: string, context: ExtractorSearchContext): Promise<ExtractorInfo>;
36
37
  buildTrack(track: Track$1, { requestedBy }: ExtractorSearchContext): Track<unknown>;
package/dist/index.js CHANGED
@@ -28,8 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
33
  DeezerExtractor: () => DeezerExtractor,
34
34
  Warnings: () => Warnings,
35
35
  buildTrackFromSearch: () => buildTrackFromSearch,
@@ -42,7 +42,7 @@ __export(src_exports, {
42
42
  streamTrack: () => streamTrack,
43
43
  validate: () => validate
44
44
  });
45
- module.exports = __toCommonJS(src_exports);
45
+ module.exports = __toCommonJS(index_exports);
46
46
 
47
47
  // src/DeezerExtractor.ts
48
48
  var import_discord_player2 = require("discord-player");
@@ -161,6 +161,8 @@ async function streamTrack(track, ext) {
161
161
  let buffer = Buffer.alloc(0);
162
162
  let i = 0;
163
163
  const bufferSize = 2048;
164
+ const blowfishDecrypter = new import_blowfish_node.default(new Uint8Array(trackKey), import_blowfish_node.default.MODE.CBC, import_blowfish_node.default.PADDING.NULL);
165
+ blowfishDecrypter.setIv(new Uint8Array(IV));
164
166
  const passThrough = new import_stream.PassThrough();
165
167
  readable.on("readable", () => {
166
168
  let chunk = null;
@@ -175,8 +177,6 @@ async function streamTrack(track, ext) {
175
177
  } else {
176
178
  buffer = Buffer.concat([buffer, chunk]);
177
179
  }
178
- const blowfishDecrypter = new import_blowfish_node.default(new Uint8Array(trackKey), import_blowfish_node.default.MODE.CBC, import_blowfish_node.default.PADDING.NULL);
179
- blowfishDecrypter.setIv(new Uint8Array(IV));
180
180
  while (buffer.length >= bufferSize) {
181
181
  const bufferSized = buffer.subarray(0, bufferSize);
182
182
  if (i % 3 === 0) {
@@ -207,6 +207,7 @@ var Warnings = {
207
207
  };
208
208
  var DeezerExtractor = class extends import_discord_player2.BaseExtractor {
209
209
  async activate() {
210
+ this.protocols = ["deezer"];
210
211
  if (!this.options.decryptionKey) process.emitWarning(Warnings.MissingDecryption);
211
212
  else {
212
213
  const crypto = await getCrypto();
@@ -227,8 +228,11 @@ var DeezerExtractor = class extends import_discord_player2.BaseExtractor {
227
228
  this.context.player.debug("USER INFO EXT: " + JSON.stringify(this.userInfo));
228
229
  }
229
230
  }
230
- async validate(query) {
231
- return validate(query);
231
+ async deactivate() {
232
+ this.protocols = [];
233
+ }
234
+ async validate(query, type) {
235
+ return validate(query) || type === "deezer";
232
236
  }
233
237
  buildPlaylistData(data, handleContext) {
234
238
  const raw = data.url.split("/");
@@ -249,13 +253,10 @@ var DeezerExtractor = class extends import_discord_player2.BaseExtractor {
249
253
  });
250
254
  }
251
255
  async handle(query, context) {
252
- if (!isUrl(query)) {
253
- try {
254
- const tracks = buildTrackFromSearch(await search(query, this.options.searchLimit), this.context.player, context.requestedBy);
255
- return this.createResponse(null, tracks);
256
- } catch {
257
- return this.createResponse();
258
- }
256
+ if (context.protocol === "deezer" && !isUrl(query)) {
257
+ const rawSearch = await search(query);
258
+ const tracks = buildTrackFromSearch(rawSearch, this.context.player, context.requestedBy);
259
+ return this.createResponse(null, tracks);
259
260
  }
260
261
  if (deezerRegex.share.test(query)) {
261
262
  const redirect = await fetch(query);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "discord-player-deezer",
3
- "version": "2.2.0-dev.0",
3
+ "version": "2.2.1-dev.2",
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",
@@ -10,8 +10,9 @@
10
10
  "blowfish-node": "^1.1.4"
11
11
  },
12
12
  "devDependencies": {
13
- "@discord-player/extractor": "^4.5.1",
14
- "discord-player": "^6.7.1",
13
+ "@discord-player/extractor": "^7.1.0",
14
+ "@types/node": "^22.10.10",
15
+ "discord-player": "^7.1.0",
15
16
  "prettier": "^3.4.2",
16
17
  "tslint": "^6.1.3",
17
18
  "tslint-config-prettier": "^1.18.0",
@@ -26,10 +27,9 @@
26
27
  },
27
28
  "repository": {
28
29
  "type": "git",
29
- "url": "https://github.com/retrouser955/discord-player-deezer/"
30
+ "url": "git+https://github.com/retrouser955/discord-player-deezer.git"
30
31
  },
31
32
  "bugs": {
32
33
  "url": "https://github.com/retrouser955/discord-player-deezer/issues"
33
- },
34
- "packageManager": "yarn@4.5.1+sha512.341db9396b6e289fecc30cd7ab3af65060e05ebff4b3b47547b278b9e67b08f485ecd8c79006b405446262142c7a38154445ef7f17c1d5d1de7d90bf9ce7054d"
34
+ }
35
35
  }
@@ -1,4 +1,4 @@
1
- import { BaseExtractor, ExtractorSearchContext, ExtractorStreamable, Track, Playlist, Util as DPUtil, ExtractorInfo } from "discord-player"
1
+ import { BaseExtractor, ExtractorSearchContext, ExtractorStreamable, Track, Playlist, Util as DPUtil, ExtractorInfo, SearchQueryType } from "discord-player"
2
2
  import { Playlist as DeezerPlaylist, Track as DeezerTrack, getData } from "@mithron/deezer-music-metadata";
3
3
  import { buildTrackFromSearch, deezerRegex, getCrypto, isUrl, search, searchOneTrack, streamTrack, validate } from "./utils/util";
4
4
 
@@ -34,6 +34,7 @@ export class DeezerExtractor extends BaseExtractor<DeezerExtractorOptions> {
34
34
  userInfo!: DeezerUserInfo
35
35
 
36
36
  async activate(): Promise<void> {
37
+ this.protocols = ["deezer"]
37
38
  if(!this.options.decryptionKey) process.emitWarning(Warnings.MissingDecryption)
38
39
  else {
39
40
  // extract deezer username
@@ -62,8 +63,12 @@ export class DeezerExtractor extends BaseExtractor<DeezerExtractorOptions> {
62
63
  }
63
64
  }
64
65
 
65
- async validate(query: string): Promise<boolean> {
66
- return validate(query)
66
+ async deactivate() {
67
+ this.protocols = []
68
+ }
69
+
70
+ async validate(query: string, type: SearchQueryType & "deezer"): Promise<boolean> {
71
+ return validate(query) || type === "deezer"
67
72
  }
68
73
 
69
74
  buildPlaylistData(data: DeezerPlaylist, handleContext: ExtractorSearchContext) {
@@ -87,16 +92,10 @@ export class DeezerExtractor extends BaseExtractor<DeezerExtractorOptions> {
87
92
  }
88
93
 
89
94
  async handle(query: string, context: ExtractorSearchContext): Promise<ExtractorInfo> {
90
- if(!isUrl(query)) {
91
- // Player is using deezer protocol
92
- try {
93
- const tracks = buildTrackFromSearch(await search(query, this.options.searchLimit), this.context.player, context.requestedBy);
94
-
95
- return this.createResponse(null, tracks);
96
- } catch {
97
- // deezer didnt return a good api response
98
- return this.createResponse()
99
- }
95
+ if(context.protocol === "deezer" && !isUrl(query)) {
96
+ const rawSearch = await search(query)
97
+ const tracks = buildTrackFromSearch(rawSearch, this.context.player, context.requestedBy)
98
+ return this.createResponse(null, tracks)
100
99
  }
101
100
 
102
101
  if (deezerRegex.share.test(query)) {
package/src/utils/util.ts CHANGED
@@ -18,7 +18,7 @@ export async function getCrypto() {
18
18
 
19
19
  export async function isUrl(query: string) {
20
20
  try {
21
- /* tslint:disable-next-line */
21
+ /* tslint:disable-next-line no-unused-expression */
22
22
  new URL(query)
23
23
  return true
24
24
  } catch {
@@ -165,6 +165,8 @@ export async function streamTrack(track: Track, ext: DeezerExtractor) {
165
165
  let i = 0
166
166
 
167
167
  const bufferSize = 2048 // 2mb
168
+ const blowfishDecrypter = new Blowfish(new Uint8Array(trackKey), Blowfish.MODE.CBC, Blowfish.PADDING.NULL)
169
+ blowfishDecrypter.setIv(new Uint8Array(IV))
168
170
 
169
171
  const passThrough = new PassThrough()
170
172
 
@@ -183,9 +185,6 @@ export async function streamTrack(track: Track, ext: DeezerExtractor) {
183
185
  buffer = Buffer.concat([buffer, chunk])
184
186
  }
185
187
 
186
- const blowfishDecrypter = new Blowfish(new Uint8Array(trackKey), Blowfish.MODE.CBC, Blowfish.PADDING.NULL)
187
- blowfishDecrypter.setIv(new Uint8Array(IV))
188
-
189
188
  while (buffer.length >= bufferSize) {
190
189
  const bufferSized = buffer.subarray(0, bufferSize)
191
190