discord-player 5.2.1 → 6.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/LICENSE +21 -21
- package/README.md +3 -1
- package/dist/Player.js +279 -272
- package/dist/Structures/ExtractorModel.js +19 -24
- package/dist/Structures/Playlist.js +1 -2
- package/dist/Structures/Queue.js +259 -269
- package/dist/Structures/Track.js +11 -14
- package/dist/VoiceInterface/StreamDispatcher.js +34 -38
- package/dist/VoiceInterface/VoiceUtils.js +22 -25
- package/dist/{VolumeTransformer.js → VoiceInterface/VolumeTransformer.js} +35 -9
- package/dist/index.d.ts +12 -7
- package/dist/index.js +3 -1
- package/dist/smoothVolume.js +11 -3
- package/dist/utils/Util.js +34 -1
- package/package.json +28 -31
package/dist/Player.js
CHANGED
|
@@ -7,11 +7,11 @@ const tiny_typed_emitter_1 = require("tiny-typed-emitter");
|
|
|
7
7
|
const Queue_1 = require("./Structures/Queue");
|
|
8
8
|
const VoiceUtils_1 = require("./VoiceInterface/VoiceUtils");
|
|
9
9
|
const types_1 = require("./types/types");
|
|
10
|
-
const Track_1 =
|
|
10
|
+
const Track_1 = tslib_1.__importDefault(require("./Structures/Track"));
|
|
11
11
|
const QueryResolver_1 = require("./utils/QueryResolver");
|
|
12
|
-
const youtube_sr_1 =
|
|
12
|
+
const youtube_sr_1 = tslib_1.__importDefault(require("youtube-sr"));
|
|
13
13
|
const Util_1 = require("./utils/Util");
|
|
14
|
-
const spotify_url_info_1 =
|
|
14
|
+
const spotify_url_info_1 = tslib_1.__importDefault(require("spotify-url-info"));
|
|
15
15
|
const PlayerError_1 = require("./Structures/PlayerError");
|
|
16
16
|
const ytdl_core_1 = require("ytdl-core");
|
|
17
17
|
const soundcloud_scraper_1 = require("soundcloud-scraper");
|
|
@@ -26,7 +26,6 @@ class Player extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
26
26
|
* @param {PlayerInitOptions} [options={}] The player init options
|
|
27
27
|
*/
|
|
28
28
|
constructor(client, options = {}) {
|
|
29
|
-
var _a;
|
|
30
29
|
super();
|
|
31
30
|
this.options = {
|
|
32
31
|
autoRegisterExtractor: true,
|
|
@@ -44,8 +43,8 @@ class Player extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
44
43
|
* @type {Client}
|
|
45
44
|
*/
|
|
46
45
|
this.client = client;
|
|
47
|
-
if (!new discord_js_1.
|
|
48
|
-
throw new PlayerError_1.PlayerError('client is missing "
|
|
46
|
+
if (this.client?.options?.intents && !new discord_js_1.IntentsBitField(this.client?.options?.intents).has(discord_js_1.IntentsBitField.Flags.GuildVoiceStates)) {
|
|
47
|
+
throw new PlayerError_1.PlayerError('client is missing "GuildVoiceStates" intent');
|
|
49
48
|
}
|
|
50
49
|
/**
|
|
51
50
|
* The extractors collection
|
|
@@ -53,7 +52,7 @@ class Player extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
53
52
|
*/
|
|
54
53
|
this.options = Object.assign(this.options, options);
|
|
55
54
|
this.client.on("voiceStateUpdate", this._handleVoiceState.bind(this));
|
|
56
|
-
if (
|
|
55
|
+
if (this.options?.autoRegisterExtractor) {
|
|
57
56
|
let nv; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
58
57
|
if ((nv = Util_1.Util.require("@discord-player/extractor"))) {
|
|
59
58
|
["Attachment", "Facebook", "Reverbnation", "Vimeo"].forEach((ext) => void this.use(ext, nv[ext]));
|
|
@@ -72,9 +71,9 @@ class Player extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
72
71
|
if (!queue)
|
|
73
72
|
return;
|
|
74
73
|
if (oldState.channelId && newState.channelId && oldState.channelId !== newState.channelId) {
|
|
75
|
-
if (
|
|
74
|
+
if (queue?.connection && newState.member.id === newState.guild.members.me.id)
|
|
76
75
|
queue.connection.channel = newState.channel;
|
|
77
|
-
if (newState.member.id === newState.guild.me.id || (newState.member.id !== newState.guild.me.id && oldState.channelId === queue.connection.channel.id)) {
|
|
76
|
+
if (newState.member.id === newState.guild.members.me.id || (newState.member.id !== newState.guild.members.me.id && oldState.channelId === queue.connection.channel.id)) {
|
|
78
77
|
if (!Util_1.Util.isVoiceEmpty(queue.connection.channel))
|
|
79
78
|
return;
|
|
80
79
|
const timeout = setTimeout(() => {
|
|
@@ -88,23 +87,23 @@ class Player extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
88
87
|
}, queue.options.leaveOnEmptyCooldown || 0).unref();
|
|
89
88
|
queue._cooldownsTimeout.set(`empty_${oldState.guild.id}`, timeout);
|
|
90
89
|
}
|
|
91
|
-
if (!oldState.channelId && newState.channelId && newState.member.id === newState.guild.me.id) {
|
|
90
|
+
if (!oldState.channelId && newState.channelId && newState.member.id === newState.guild.members.me.id) {
|
|
92
91
|
if (newState.serverMute || !newState.serverMute) {
|
|
93
92
|
queue.setPaused(newState.serverMute);
|
|
94
93
|
}
|
|
95
94
|
else if (newState.suppress || !newState.suppress) {
|
|
96
95
|
if (newState.suppress)
|
|
97
|
-
newState.guild.me.voice.setRequestToSpeak(true).catch(Util_1.Util.noop);
|
|
96
|
+
newState.guild.members.me.voice.setRequestToSpeak(true).catch(Util_1.Util.noop);
|
|
98
97
|
queue.setPaused(newState.suppress);
|
|
99
98
|
}
|
|
100
99
|
}
|
|
101
|
-
if (oldState.channelId === newState.channelId && oldState.member.id === newState.guild.me.id) {
|
|
100
|
+
if (oldState.channelId === newState.channelId && oldState.member.id === newState.guild.members.me.id) {
|
|
102
101
|
if (oldState.serverMute !== newState.serverMute) {
|
|
103
102
|
queue.setPaused(newState.serverMute);
|
|
104
103
|
}
|
|
105
104
|
else if (oldState.suppress !== newState.suppress) {
|
|
106
105
|
if (newState.suppress)
|
|
107
|
-
newState.guild.me.voice.setRequestToSpeak(true).catch(Util_1.Util.noop);
|
|
106
|
+
newState.guild.members.me.voice.setRequestToSpeak(true).catch(Util_1.Util.noop);
|
|
108
107
|
queue.setPaused(newState.suppress);
|
|
109
108
|
}
|
|
110
109
|
}
|
|
@@ -149,7 +148,6 @@ class Player extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
149
148
|
* @returns {Queue}
|
|
150
149
|
*/
|
|
151
150
|
createQueue(guild, queueInitOptions = {}) {
|
|
152
|
-
var _a, _b;
|
|
153
151
|
guild = this.client.guilds.resolve(guild);
|
|
154
152
|
if (!guild)
|
|
155
153
|
throw new PlayerError_1.PlayerError("Unknown Guild", PlayerError_1.ErrorStatusCode.UNKNOWN_GUILD);
|
|
@@ -157,8 +155,8 @@ class Player extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
157
155
|
return this.queues.get(guild.id);
|
|
158
156
|
const _meta = queueInitOptions.metadata;
|
|
159
157
|
delete queueInitOptions["metadata"];
|
|
160
|
-
|
|
161
|
-
|
|
158
|
+
queueInitOptions.volumeSmoothness ?? (queueInitOptions.volumeSmoothness = 0.08);
|
|
159
|
+
queueInitOptions.ytdlOptions ?? (queueInitOptions.ytdlOptions = this.options.ytdlOptions);
|
|
162
160
|
const queue = new Queue_1.Queue(this, guild, queueInitOptions);
|
|
163
161
|
queue.metadata = _meta;
|
|
164
162
|
this.queues.set(guild.id, queue);
|
|
@@ -188,7 +186,7 @@ class Player extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
188
186
|
try {
|
|
189
187
|
prev.destroy();
|
|
190
188
|
}
|
|
191
|
-
catch
|
|
189
|
+
catch { } // eslint-disable-line no-empty
|
|
192
190
|
this.queues.delete(guild.id);
|
|
193
191
|
return prev;
|
|
194
192
|
}
|
|
@@ -203,281 +201,290 @@ class Player extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
203
201
|
* @param {SearchOptions} options The search options
|
|
204
202
|
* @returns {Promise<PlayerSearchResult>}
|
|
205
203
|
*/
|
|
206
|
-
search(query, options) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
options.
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
|
|
204
|
+
async search(query, options) {
|
|
205
|
+
if (query instanceof Track_1.default)
|
|
206
|
+
return { playlist: query.playlist || null, tracks: [query] };
|
|
207
|
+
if (!options)
|
|
208
|
+
throw new PlayerError_1.PlayerError("DiscordPlayer#search needs search options!", PlayerError_1.ErrorStatusCode.INVALID_ARG_TYPE);
|
|
209
|
+
options.requestedBy = this.client.users.resolve(options.requestedBy);
|
|
210
|
+
if (!("searchEngine" in options))
|
|
211
|
+
options.searchEngine = types_1.QueryType.AUTO;
|
|
212
|
+
if (typeof options.searchEngine === "string" && this.extractors.has(options.searchEngine)) {
|
|
213
|
+
const extractor = this.extractors.get(options.searchEngine);
|
|
214
|
+
if (!extractor.validate(query))
|
|
215
|
+
return { playlist: null, tracks: [] };
|
|
216
|
+
const data = await extractor.handle(query);
|
|
217
|
+
if (data && data.data.length) {
|
|
218
|
+
const playlist = !data.playlist
|
|
219
|
+
? null
|
|
220
|
+
: new Playlist_1.Playlist(this, {
|
|
221
|
+
...data.playlist,
|
|
222
|
+
tracks: []
|
|
223
|
+
});
|
|
224
|
+
const tracks = data.data.map((m) => new Track_1.default(this, {
|
|
225
|
+
...m,
|
|
226
|
+
requestedBy: options.requestedBy,
|
|
227
|
+
duration: Util_1.Util.buildTimeCode(Util_1.Util.parseMS(m.duration)),
|
|
228
|
+
playlist: playlist
|
|
229
|
+
}));
|
|
230
|
+
if (playlist)
|
|
231
|
+
playlist.tracks = tracks;
|
|
232
|
+
return { playlist: playlist, tracks: tracks };
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
236
|
+
for (const [_, extractor] of this.extractors) {
|
|
237
|
+
if (options.blockExtractor)
|
|
238
|
+
break;
|
|
239
|
+
if (!extractor.validate(query))
|
|
240
|
+
continue;
|
|
241
|
+
const data = await extractor.handle(query);
|
|
242
|
+
if (data && data.data.length) {
|
|
243
|
+
const playlist = !data.playlist
|
|
244
|
+
? null
|
|
245
|
+
: new Playlist_1.Playlist(this, {
|
|
246
|
+
...data.playlist,
|
|
247
|
+
tracks: []
|
|
248
|
+
});
|
|
249
|
+
const tracks = data.data.map((m) => new Track_1.default(this, {
|
|
250
|
+
...m,
|
|
251
|
+
requestedBy: options.requestedBy,
|
|
252
|
+
duration: Util_1.Util.buildTimeCode(Util_1.Util.parseMS(m.duration)),
|
|
253
|
+
playlist: playlist
|
|
254
|
+
}));
|
|
255
|
+
if (playlist)
|
|
256
|
+
playlist.tracks = tracks;
|
|
257
|
+
return { playlist: playlist, tracks: tracks };
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const qt = options.searchEngine === types_1.QueryType.AUTO ? QueryResolver_1.QueryResolver.resolve(query) : options.searchEngine;
|
|
261
|
+
switch (qt) {
|
|
262
|
+
case types_1.QueryType.YOUTUBE_VIDEO: {
|
|
263
|
+
const info = await (0, ytdl_core_1.getInfo)(query, this.options.ytdlOptions).catch(Util_1.Util.noop);
|
|
264
|
+
if (!info)
|
|
219
265
|
return { playlist: null, tracks: [] };
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
266
|
+
const track = new Track_1.default(this, {
|
|
267
|
+
title: info.videoDetails.title,
|
|
268
|
+
description: info.videoDetails.description,
|
|
269
|
+
author: info.videoDetails.author?.name,
|
|
270
|
+
url: info.videoDetails.video_url,
|
|
271
|
+
requestedBy: options.requestedBy,
|
|
272
|
+
thumbnail: Util_1.Util.last(info.videoDetails.thumbnails)?.url,
|
|
273
|
+
views: parseInt(info.videoDetails.viewCount.replace(/[^0-9]/g, "")) || 0,
|
|
274
|
+
duration: Util_1.Util.buildTimeCode(Util_1.Util.parseMS(parseInt(info.videoDetails.lengthSeconds) * 1000)),
|
|
275
|
+
source: "youtube",
|
|
276
|
+
raw: info
|
|
277
|
+
});
|
|
278
|
+
return { playlist: null, tracks: [track] };
|
|
230
279
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (!
|
|
236
|
-
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
:
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
280
|
+
case types_1.QueryType.YOUTUBE_SEARCH: {
|
|
281
|
+
const videos = await youtube_sr_1.default.search(query, {
|
|
282
|
+
type: "video"
|
|
283
|
+
}).catch(Util_1.Util.noop);
|
|
284
|
+
if (!videos)
|
|
285
|
+
return { playlist: null, tracks: [] };
|
|
286
|
+
const tracks = videos.map((m) => {
|
|
287
|
+
m.source = "youtube"; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
288
|
+
return new Track_1.default(this, {
|
|
289
|
+
title: m.title,
|
|
290
|
+
description: m.description,
|
|
291
|
+
author: m.channel?.name,
|
|
292
|
+
url: m.url,
|
|
293
|
+
requestedBy: options.requestedBy,
|
|
294
|
+
thumbnail: m.thumbnail?.displayThumbnailURL("maxresdefault"),
|
|
295
|
+
views: m.views,
|
|
296
|
+
duration: m.durationFormatted,
|
|
297
|
+
source: "youtube",
|
|
298
|
+
raw: m
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
return { playlist: null, tracks };
|
|
247
302
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
303
|
+
case types_1.QueryType.SOUNDCLOUD_TRACK:
|
|
304
|
+
case types_1.QueryType.SOUNDCLOUD_SEARCH: {
|
|
305
|
+
const result = QueryResolver_1.QueryResolver.resolve(query) === types_1.QueryType.SOUNDCLOUD_TRACK ? [{ url: query }] : await soundcloud.search(query, "track").catch(() => []);
|
|
306
|
+
if (!result || !result.length)
|
|
307
|
+
return { playlist: null, tracks: [] };
|
|
308
|
+
const res = [];
|
|
309
|
+
for (const r of result) {
|
|
310
|
+
const trackInfo = await soundcloud.getSongInfo(r.url).catch(Util_1.Util.noop);
|
|
311
|
+
if (!trackInfo)
|
|
312
|
+
continue;
|
|
254
313
|
const track = new Track_1.default(this, {
|
|
255
|
-
title:
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
314
|
+
title: trackInfo.title,
|
|
315
|
+
url: trackInfo.url,
|
|
316
|
+
duration: Util_1.Util.buildTimeCode(Util_1.Util.parseMS(trackInfo.duration)),
|
|
317
|
+
description: trackInfo.description,
|
|
318
|
+
thumbnail: trackInfo.thumbnail,
|
|
319
|
+
views: trackInfo.playCount,
|
|
320
|
+
author: trackInfo.author.name,
|
|
259
321
|
requestedBy: options.requestedBy,
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
duration: Util_1.Util.buildTimeCode(Util_1.Util.parseMS(parseInt(info.videoDetails.lengthSeconds) * 1000)),
|
|
263
|
-
source: "youtube",
|
|
264
|
-
raw: info
|
|
322
|
+
source: "soundcloud",
|
|
323
|
+
engine: trackInfo
|
|
265
324
|
});
|
|
266
|
-
|
|
325
|
+
res.push(track);
|
|
267
326
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
327
|
+
return { playlist: null, tracks: res };
|
|
328
|
+
}
|
|
329
|
+
case types_1.QueryType.SPOTIFY_SONG: {
|
|
330
|
+
const spotifyData = await (0, spotify_url_info_1.default)(Util_1.Util.getFetch()).getData(query).catch(Util_1.Util.noop);
|
|
331
|
+
if (!spotifyData)
|
|
332
|
+
return { playlist: null, tracks: [] };
|
|
333
|
+
const spotifyTrack = new Track_1.default(this, {
|
|
334
|
+
title: spotifyData.name,
|
|
335
|
+
description: spotifyData.description ?? "",
|
|
336
|
+
author: spotifyData.artists[0]?.name ?? "Unknown Artist",
|
|
337
|
+
url: spotifyData.external_urls?.spotify ?? query,
|
|
338
|
+
thumbnail: spotifyData.album?.images[0]?.url ?? spotifyData.preview_url?.length
|
|
339
|
+
? `https://i.scdn.co/image/${spotifyData.preview_url?.split("?cid=")[1]}`
|
|
340
|
+
: "https://www.scdn.co/i/_global/twitter_card-default.jpg",
|
|
341
|
+
duration: Util_1.Util.buildTimeCode(Util_1.Util.parseMS(spotifyData.duration_ms)),
|
|
342
|
+
views: 0,
|
|
343
|
+
requestedBy: options.requestedBy,
|
|
344
|
+
source: "spotify"
|
|
345
|
+
});
|
|
346
|
+
return { playlist: null, tracks: [spotifyTrack] };
|
|
347
|
+
}
|
|
348
|
+
case types_1.QueryType.SPOTIFY_PLAYLIST:
|
|
349
|
+
case types_1.QueryType.SPOTIFY_ALBUM: {
|
|
350
|
+
const spotifyPlaylist = await (0, spotify_url_info_1.default)(await Util_1.Util.getFetch())
|
|
351
|
+
.getData(query)
|
|
352
|
+
.catch(Util_1.Util.noop);
|
|
353
|
+
if (!spotifyPlaylist)
|
|
354
|
+
return { playlist: null, tracks: [] };
|
|
355
|
+
const playlist = new Playlist_1.Playlist(this, {
|
|
356
|
+
title: spotifyPlaylist.name ?? spotifyPlaylist.title,
|
|
357
|
+
description: spotifyPlaylist.description ?? "",
|
|
358
|
+
thumbnail: spotifyPlaylist.images[0]?.url ?? "https://www.scdn.co/i/_global/twitter_card-default.jpg",
|
|
359
|
+
type: spotifyPlaylist.type,
|
|
360
|
+
source: "spotify",
|
|
361
|
+
author: spotifyPlaylist.type !== "playlist"
|
|
362
|
+
? {
|
|
363
|
+
name: spotifyPlaylist.artists[0]?.name ?? "Unknown Artist",
|
|
364
|
+
url: spotifyPlaylist.artists[0]?.external_urls?.spotify ?? null
|
|
365
|
+
}
|
|
366
|
+
: {
|
|
367
|
+
name: spotifyPlaylist.owner?.display_name ?? spotifyPlaylist.owner?.id ?? "Unknown Artist",
|
|
368
|
+
url: spotifyPlaylist.owner?.external_urls?.spotify ?? null
|
|
369
|
+
},
|
|
370
|
+
tracks: [],
|
|
371
|
+
id: spotifyPlaylist.id,
|
|
372
|
+
url: spotifyPlaylist.external_urls?.spotify ?? query,
|
|
373
|
+
rawPlaylist: spotifyPlaylist
|
|
374
|
+
});
|
|
375
|
+
if (spotifyPlaylist.type !== "playlist") {
|
|
376
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
377
|
+
playlist.tracks = spotifyPlaylist.tracks.items.map((m) => {
|
|
378
|
+
const data = new Track_1.default(this, {
|
|
379
|
+
title: m.name ?? "",
|
|
380
|
+
description: m.description ?? "",
|
|
381
|
+
author: m.artists[0]?.name ?? "Unknown Artist",
|
|
382
|
+
url: m.external_urls?.spotify ?? query,
|
|
383
|
+
thumbnail: spotifyPlaylist.images[0]?.url ?? "https://www.scdn.co/i/_global/twitter_card-default.jpg",
|
|
384
|
+
duration: Util_1.Util.buildTimeCode(Util_1.Util.parseMS(m.duration_ms)),
|
|
385
|
+
views: 0,
|
|
282
386
|
requestedBy: options.requestedBy,
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
duration: m.durationFormatted,
|
|
286
|
-
source: "youtube",
|
|
287
|
-
raw: m
|
|
387
|
+
playlist,
|
|
388
|
+
source: "spotify"
|
|
288
389
|
});
|
|
390
|
+
return data;
|
|
289
391
|
});
|
|
290
|
-
return { playlist: null, tracks };
|
|
291
392
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
title: trackInfo.title,
|
|
304
|
-
url: trackInfo.url,
|
|
305
|
-
duration: Util_1.Util.buildTimeCode(Util_1.Util.parseMS(trackInfo.duration)),
|
|
306
|
-
description: trackInfo.description,
|
|
307
|
-
thumbnail: trackInfo.thumbnail,
|
|
308
|
-
views: trackInfo.playCount,
|
|
309
|
-
author: trackInfo.author.name,
|
|
393
|
+
else {
|
|
394
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
395
|
+
playlist.tracks = spotifyPlaylist.tracks.items.map((m) => {
|
|
396
|
+
const data = new Track_1.default(this, {
|
|
397
|
+
title: m.track.name ?? "",
|
|
398
|
+
description: m.track.description ?? "",
|
|
399
|
+
author: m.track.artists[0]?.name ?? "Unknown Artist",
|
|
400
|
+
url: m.track.external_urls?.spotify ?? query,
|
|
401
|
+
thumbnail: m.track.album?.images[0]?.url ?? "https://www.scdn.co/i/_global/twitter_card-default.jpg",
|
|
402
|
+
duration: Util_1.Util.buildTimeCode(Util_1.Util.parseMS(m.track.duration_ms)),
|
|
403
|
+
views: 0,
|
|
310
404
|
requestedBy: options.requestedBy,
|
|
311
|
-
|
|
312
|
-
|
|
405
|
+
playlist,
|
|
406
|
+
source: "spotify"
|
|
313
407
|
});
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
return { playlist: null, tracks: res };
|
|
317
|
-
}
|
|
318
|
-
case types_1.QueryType.SPOTIFY_SONG: {
|
|
319
|
-
const spotifyData = yield spotify_url_info_1.default.getData(query).catch(Util_1.Util.noop);
|
|
320
|
-
if (!spotifyData)
|
|
321
|
-
return { playlist: null, tracks: [] };
|
|
322
|
-
const spotifyTrack = new Track_1.default(this, {
|
|
323
|
-
title: spotifyData.name,
|
|
324
|
-
description: (_c = spotifyData.description) !== null && _c !== void 0 ? _c : "",
|
|
325
|
-
author: (_e = (_d = spotifyData.artists[0]) === null || _d === void 0 ? void 0 : _d.name) !== null && _e !== void 0 ? _e : "Unknown Artist",
|
|
326
|
-
url: (_g = (_f = spotifyData.external_urls) === null || _f === void 0 ? void 0 : _f.spotify) !== null && _g !== void 0 ? _g : query,
|
|
327
|
-
thumbnail: ((_k = (_j = (_h = spotifyData.album) === null || _h === void 0 ? void 0 : _h.images[0]) === null || _j === void 0 ? void 0 : _j.url) !== null && _k !== void 0 ? _k : (_l = spotifyData.preview_url) === null || _l === void 0 ? void 0 : _l.length)
|
|
328
|
-
? `https://i.scdn.co/image/${(_m = spotifyData.preview_url) === null || _m === void 0 ? void 0 : _m.split("?cid=")[1]}`
|
|
329
|
-
: "https://www.scdn.co/i/_global/twitter_card-default.jpg",
|
|
330
|
-
duration: Util_1.Util.buildTimeCode(Util_1.Util.parseMS(spotifyData.duration_ms)),
|
|
331
|
-
views: 0,
|
|
332
|
-
requestedBy: options.requestedBy,
|
|
333
|
-
source: "spotify"
|
|
408
|
+
return data;
|
|
334
409
|
});
|
|
335
|
-
return { playlist: null, tracks: [spotifyTrack] };
|
|
336
410
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
author: (_d = (_c = m.artists[0]) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : "Unknown Artist",
|
|
370
|
-
url: (_f = (_e = m.external_urls) === null || _e === void 0 ? void 0 : _e.spotify) !== null && _f !== void 0 ? _f : query,
|
|
371
|
-
thumbnail: (_h = (_g = spotifyPlaylist.images[0]) === null || _g === void 0 ? void 0 : _g.url) !== null && _h !== void 0 ? _h : "https://www.scdn.co/i/_global/twitter_card-default.jpg",
|
|
372
|
-
duration: Util_1.Util.buildTimeCode(Util_1.Util.parseMS(m.duration_ms)),
|
|
373
|
-
views: 0,
|
|
374
|
-
requestedBy: options.requestedBy,
|
|
375
|
-
playlist,
|
|
376
|
-
source: "spotify"
|
|
377
|
-
});
|
|
378
|
-
return data;
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
else {
|
|
382
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
383
|
-
playlist.tracks = spotifyPlaylist.tracks.items.map((m) => {
|
|
384
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
385
|
-
const data = new Track_1.default(this, {
|
|
386
|
-
title: (_a = m.track.name) !== null && _a !== void 0 ? _a : "",
|
|
387
|
-
description: (_b = m.track.description) !== null && _b !== void 0 ? _b : "",
|
|
388
|
-
author: (_d = (_c = m.track.artists[0]) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : "Unknown Artist",
|
|
389
|
-
url: (_f = (_e = m.track.external_urls) === null || _e === void 0 ? void 0 : _e.spotify) !== null && _f !== void 0 ? _f : query,
|
|
390
|
-
thumbnail: (_j = (_h = (_g = m.track.album) === null || _g === void 0 ? void 0 : _g.images[0]) === null || _h === void 0 ? void 0 : _h.url) !== null && _j !== void 0 ? _j : "https://www.scdn.co/i/_global/twitter_card-default.jpg",
|
|
391
|
-
duration: Util_1.Util.buildTimeCode(Util_1.Util.parseMS(m.track.duration_ms)),
|
|
392
|
-
views: 0,
|
|
393
|
-
requestedBy: options.requestedBy,
|
|
394
|
-
playlist,
|
|
395
|
-
source: "spotify"
|
|
396
|
-
});
|
|
397
|
-
return data;
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
return { playlist: playlist, tracks: playlist.tracks };
|
|
401
|
-
}
|
|
402
|
-
case types_1.QueryType.SOUNDCLOUD_PLAYLIST: {
|
|
403
|
-
const data = yield soundcloud.getPlaylist(query).catch(Util_1.Util.noop);
|
|
404
|
-
if (!data)
|
|
405
|
-
return { playlist: null, tracks: [] };
|
|
406
|
-
const res = new Playlist_1.Playlist(this, {
|
|
407
|
-
title: data.title,
|
|
408
|
-
description: (_6 = data.description) !== null && _6 !== void 0 ? _6 : "",
|
|
409
|
-
thumbnail: (_7 = data.thumbnail) !== null && _7 !== void 0 ? _7 : "https://soundcloud.com/pwa-icon-192.png",
|
|
410
|
-
type: "playlist",
|
|
411
|
+
return { playlist: playlist, tracks: playlist.tracks };
|
|
412
|
+
}
|
|
413
|
+
case types_1.QueryType.SOUNDCLOUD_PLAYLIST: {
|
|
414
|
+
const data = await soundcloud.getPlaylist(query).catch(Util_1.Util.noop);
|
|
415
|
+
if (!data)
|
|
416
|
+
return { playlist: null, tracks: [] };
|
|
417
|
+
const res = new Playlist_1.Playlist(this, {
|
|
418
|
+
title: data.title,
|
|
419
|
+
description: data.description ?? "",
|
|
420
|
+
thumbnail: data.thumbnail ?? "https://soundcloud.com/pwa-icon-192.png",
|
|
421
|
+
type: "playlist",
|
|
422
|
+
source: "soundcloud",
|
|
423
|
+
author: {
|
|
424
|
+
name: data.author?.name ?? data.author?.username ?? "Unknown Artist",
|
|
425
|
+
url: data.author?.profile
|
|
426
|
+
},
|
|
427
|
+
tracks: [],
|
|
428
|
+
id: `${data.id}`,
|
|
429
|
+
url: data.url,
|
|
430
|
+
rawPlaylist: data
|
|
431
|
+
});
|
|
432
|
+
for (const song of data.tracks) {
|
|
433
|
+
const track = new Track_1.default(this, {
|
|
434
|
+
title: song.title,
|
|
435
|
+
description: song.description ?? "",
|
|
436
|
+
author: song.author?.username ?? song.author?.name ?? "Unknown Artist",
|
|
437
|
+
url: song.url,
|
|
438
|
+
thumbnail: song.thumbnail,
|
|
439
|
+
duration: Util_1.Util.buildTimeCode(Util_1.Util.parseMS(song.duration)),
|
|
440
|
+
views: song.playCount ?? 0,
|
|
441
|
+
requestedBy: options.requestedBy,
|
|
442
|
+
playlist: res,
|
|
411
443
|
source: "soundcloud",
|
|
412
|
-
|
|
413
|
-
name: (_11 = (_9 = (_8 = data.author) === null || _8 === void 0 ? void 0 : _8.name) !== null && _9 !== void 0 ? _9 : (_10 = data.author) === null || _10 === void 0 ? void 0 : _10.username) !== null && _11 !== void 0 ? _11 : "Unknown Artist",
|
|
414
|
-
url: (_12 = data.author) === null || _12 === void 0 ? void 0 : _12.profile
|
|
415
|
-
},
|
|
416
|
-
tracks: [],
|
|
417
|
-
id: `${data.id}`,
|
|
418
|
-
url: data.url,
|
|
419
|
-
rawPlaylist: data
|
|
444
|
+
engine: song
|
|
420
445
|
});
|
|
421
|
-
|
|
422
|
-
const track = new Track_1.default(this, {
|
|
423
|
-
title: song.title,
|
|
424
|
-
description: (_13 = song.description) !== null && _13 !== void 0 ? _13 : "",
|
|
425
|
-
author: (_17 = (_15 = (_14 = song.author) === null || _14 === void 0 ? void 0 : _14.username) !== null && _15 !== void 0 ? _15 : (_16 = song.author) === null || _16 === void 0 ? void 0 : _16.name) !== null && _17 !== void 0 ? _17 : "Unknown Artist",
|
|
426
|
-
url: song.url,
|
|
427
|
-
thumbnail: song.thumbnail,
|
|
428
|
-
duration: Util_1.Util.buildTimeCode(Util_1.Util.parseMS(song.duration)),
|
|
429
|
-
views: (_18 = song.playCount) !== null && _18 !== void 0 ? _18 : 0,
|
|
430
|
-
requestedBy: options.requestedBy,
|
|
431
|
-
playlist: res,
|
|
432
|
-
source: "soundcloud",
|
|
433
|
-
engine: song
|
|
434
|
-
});
|
|
435
|
-
res.tracks.push(track);
|
|
436
|
-
}
|
|
437
|
-
return { playlist: res, tracks: res.tracks };
|
|
446
|
+
res.tracks.push(track);
|
|
438
447
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
const playlist = new Playlist_1.Playlist(this, {
|
|
445
|
-
title: ytpl.title,
|
|
446
|
-
thumbnail: ytpl.thumbnail,
|
|
447
|
-
description: "",
|
|
448
|
-
type: "playlist",
|
|
449
|
-
source: "youtube",
|
|
450
|
-
author: {
|
|
451
|
-
name: ytpl.channel.name,
|
|
452
|
-
url: ytpl.channel.url
|
|
453
|
-
},
|
|
454
|
-
tracks: [],
|
|
455
|
-
id: ytpl.id,
|
|
456
|
-
url: ytpl.url,
|
|
457
|
-
rawPlaylist: ytpl
|
|
458
|
-
});
|
|
459
|
-
playlist.tracks = ytpl.videos.map((video) => {
|
|
460
|
-
var _a;
|
|
461
|
-
return new Track_1.default(this, {
|
|
462
|
-
title: video.title,
|
|
463
|
-
description: video.description,
|
|
464
|
-
author: (_a = video.channel) === null || _a === void 0 ? void 0 : _a.name,
|
|
465
|
-
url: video.url,
|
|
466
|
-
requestedBy: options.requestedBy,
|
|
467
|
-
thumbnail: video.thumbnail.url,
|
|
468
|
-
views: video.views,
|
|
469
|
-
duration: video.durationFormatted,
|
|
470
|
-
raw: video,
|
|
471
|
-
playlist: playlist,
|
|
472
|
-
source: "youtube"
|
|
473
|
-
});
|
|
474
|
-
});
|
|
475
|
-
return { playlist: playlist, tracks: playlist.tracks };
|
|
476
|
-
}
|
|
477
|
-
default:
|
|
448
|
+
return { playlist: res, tracks: res.tracks };
|
|
449
|
+
}
|
|
450
|
+
case types_1.QueryType.YOUTUBE_PLAYLIST: {
|
|
451
|
+
const ytpl = await youtube_sr_1.default.getPlaylist(query).catch(Util_1.Util.noop);
|
|
452
|
+
if (!ytpl)
|
|
478
453
|
return { playlist: null, tracks: [] };
|
|
454
|
+
await ytpl.fetch().catch(Util_1.Util.noop);
|
|
455
|
+
const playlist = new Playlist_1.Playlist(this, {
|
|
456
|
+
title: ytpl.title,
|
|
457
|
+
thumbnail: ytpl.thumbnail,
|
|
458
|
+
description: "",
|
|
459
|
+
type: "playlist",
|
|
460
|
+
source: "youtube",
|
|
461
|
+
author: {
|
|
462
|
+
name: ytpl.channel.name,
|
|
463
|
+
url: ytpl.channel.url
|
|
464
|
+
},
|
|
465
|
+
tracks: [],
|
|
466
|
+
id: ytpl.id,
|
|
467
|
+
url: ytpl.url,
|
|
468
|
+
rawPlaylist: ytpl
|
|
469
|
+
});
|
|
470
|
+
playlist.tracks = ytpl.videos.map((video) => new Track_1.default(this, {
|
|
471
|
+
title: video.title,
|
|
472
|
+
description: video.description,
|
|
473
|
+
author: video.channel?.name,
|
|
474
|
+
url: video.url,
|
|
475
|
+
requestedBy: options.requestedBy,
|
|
476
|
+
thumbnail: video.thumbnail.url,
|
|
477
|
+
views: video.views,
|
|
478
|
+
duration: video.durationFormatted,
|
|
479
|
+
raw: video,
|
|
480
|
+
playlist: playlist,
|
|
481
|
+
source: "youtube"
|
|
482
|
+
}));
|
|
483
|
+
return { playlist: playlist, tracks: playlist.tracks };
|
|
479
484
|
}
|
|
480
|
-
|
|
485
|
+
default:
|
|
486
|
+
return { playlist: null, tracks: [] };
|
|
487
|
+
}
|
|
481
488
|
}
|
|
482
489
|
/**
|
|
483
490
|
* Registers extractor
|