From edb517c8c6499e81b9dcbbb346126492b4679ed3 Mon Sep 17 00:00:00 2001 From: DevAndromeda <46562212+DevAndromeda@users.noreply.github.com> Date: Sun, 17 Oct 2021 13:04:10 +0545 Subject: [PATCH] feat(Queue): add spotifyBridge option --- src/Structures/Queue.ts | 7 ++++--- src/types/types.ts | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Structures/Queue.ts b/src/Structures/Queue.ts index b391ea7..01d243e 100644 --- a/src/Structures/Queue.ts +++ b/src/Structures/Queue.ts @@ -105,7 +105,8 @@ class Queue { highWaterMark: 1 << 25 }, initialVolume: 100, - bufferingTimeout: 3000 + bufferingTimeout: 3000, + spotifyBridge: true } as PlayerOptions, options ); @@ -638,7 +639,7 @@ class Queue { const customDownloader = typeof this.onBeforeCreateStream === "function"; if (["youtube", "spotify"].includes(track.raw.source)) { - if (track.raw.source === "spotify" && !track.raw.engine) { + if (this.options.spotifyBridge && track.raw.source === "spotify" && !track.raw.engine) { track.raw.engine = await YouTube.search(`${track.author} ${track.title}`, { type: "video" }) .then((x) => x[0].url) .catch(() => null); @@ -647,7 +648,7 @@ class Queue { if (!link) return void this.play(this.tracks.shift(), { immediate: true }); if (customDownloader) { - stream = (await this.onBeforeCreateStream(track, "youtube", this)) ?? null; + stream = (await this.onBeforeCreateStream(track, track.raw.source || "youtube", this)) ?? null; if (stream) stream = ytdl .arbitraryStream(stream, { diff --git a/src/types/types.ts b/src/types/types.ts index 694b0ee..1715260 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -128,6 +128,7 @@ export interface PlayerProgressbarOptions { * @property {YTDLDownloadOptions} [ytdlOptions={}] The youtube download options * @property {number} [initialVolume=100] The initial player volume * @property {number} [bufferingTimeout=3000] Buffering timeout for the stream + * @property {boolean} [spotifyBridge=true] If player should bridge spotify source to youtube * @property {Function} [onBeforeCreateStream] Runs before creating stream */ export interface PlayerOptions { @@ -139,6 +140,7 @@ export interface PlayerOptions { ytdlOptions?: downloadOptions; initialVolume?: number; bufferingTimeout?: number; + spotifyBridge?: boolean; onBeforeCreateStream?: (track: Track, source: TrackSource, queue: Queue) => Promise; }