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

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.
Files changed (2) hide show
  1. package/dist/index.js +10 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -64,7 +64,7 @@ var DeezerAPIRoutes = {
64
64
  }
65
65
  };
66
66
  function buildTrackFromSearch(track, player, requestedBy) {
67
- return track.data.map((v) => new import_discord_player.Track(player, {
67
+ const tracks = track.data.map((v) => new import_discord_player.Track(player, {
68
68
  source: "arbitrary",
69
69
  duration: import_discord_player.Util.buildTimeCode(import_discord_player.Util.parseMS(v.duration * 1e3)),
70
70
  author: Array.isArray(v.artist) ? v.artist.map((a) => a.name).join(", ") : v.artist.name,
@@ -74,6 +74,7 @@ function buildTrackFromSearch(track, player, requestedBy) {
74
74
  live: false,
75
75
  requestedBy
76
76
  }));
77
+ return tracks;
77
78
  }
78
79
  function extractTrackId(query) {
79
80
  if (!validate(query)) throw new Error("Invalid track url");
@@ -86,8 +87,7 @@ async function searchOneTrack(query) {
86
87
  const trackRes = await fetch(url);
87
88
  if (trackRes.status !== 200) throw new Error("Fetch failed");
88
89
  const trackData = await trackRes.json();
89
- const track = trackData;
90
- return track;
90
+ return trackData;
91
91
  }
92
92
  async function streamTrack(track, ext) {
93
93
  const decryptionKey = ext.options.decryptionKey;
@@ -195,15 +195,17 @@ var DeezerExtractor = class extends import_discord_player2.BaseExtractor {
195
195
  const randomToken = crypto.randomBytes(16).toString("hex");
196
196
  const deezerUsrDataUrl = `https://www.deezer.com/ajax/gw-light.php?method=deezer.getUserData&input=3&api_version=1.0&api_token=${randomToken}`;
197
197
  const usrDataRes = await fetch(deezerUsrDataUrl);
198
- const cookie = usrDataRes.headers.get("set-cookie");
199
- this.userInfo.cookie = cookie;
200
198
  const usrData = await usrDataRes.json();
201
199
  const licenseToken = usrData.results.USER.OPTIONS.license_token;
202
200
  if (typeof licenseToken !== "string") throw new Error("Unable to get licenseToken");
203
- this.userInfo.licenseToken = licenseToken;
204
201
  const csrfToken = usrData.results.checkForm;
205
202
  if (typeof csrfToken !== "string") throw new Error("Unable to get csrf token which is required for decryption");
206
- this.userInfo.mediaUrl = usrData.results.URL_MEDIA || "https://media.deezer.com";
203
+ this.userInfo = {
204
+ mediaUrl: usrData.results.URL_MEDIA || "https://media.deezer.com",
205
+ cookie: usrDataRes.headers.get("set-cookie"),
206
+ licenseToken,
207
+ csrfToken
208
+ };
207
209
  }
208
210
  }
209
211
  async validate(query) {
@@ -249,7 +251,7 @@ var DeezerExtractor = class extends import_discord_player2.BaseExtractor {
249
251
  }
250
252
  async bridge(track) {
251
253
  const deezerTrack = await searchOneTrack(`${track.author} ${track.source === "youtube" ? track.cleanTitle : track.title}`);
252
- if (!deezerTrack || !deezerTrack?.data[0]) return null;
254
+ if (!deezerTrack) return null;
253
255
  const dpTrack = buildTrackFromSearch(deezerTrack, this.context.player, track.requestedBy);
254
256
  const stream = this.stream(dpTrack[0]);
255
257
  return stream;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "discord-player-deezer",
3
- "version": "2.0.0-beta.3",
3
+ "version": "2.0.0-beta.5",
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",