cache youtube links for spotify
This commit is contained in:
parent
139a7aeb68
commit
76b76a27cc
2 changed files with 17 additions and 13 deletions
|
@ -1279,17 +1279,16 @@ export class Player extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
let newStream: any;
|
let newStream: any;
|
||||||
let clonedTrack = queue.playing;
|
|
||||||
|
|
||||||
// modify spotify
|
// modify spotify
|
||||||
if (clonedTrack.raw.source === 'spotify') {
|
if (queue.playing.raw.source === 'spotify' && !(queue.playing as any).backupLink) {
|
||||||
const searchQueryString = this.options.disableArtistSearch
|
const searchQueryString = this.options.disableArtistSearch
|
||||||
? clonedTrack.title
|
? queue.playing.title
|
||||||
: `${clonedTrack.title}${' - ' + clonedTrack.author}`;
|
: `${queue.playing.title}${' - ' + queue.playing.author}`;
|
||||||
const yteqv = await Util.ytSearch(searchQueryString, {
|
const yteqv = await Util.ytSearch(searchQueryString, {
|
||||||
player: this,
|
player: this,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
user: clonedTrack.requestedBy
|
user: queue.playing.requestedBy
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
|
|
||||||
if (!yteqv || !yteqv.length)
|
if (!yteqv || !yteqv.length)
|
||||||
|
@ -1301,13 +1300,18 @@ export class Player extends EventEmitter {
|
||||||
new PlayerError('Could not find alternative track on youtube!', 'SpotifyTrackError')
|
new PlayerError('Could not find alternative track on youtube!', 'SpotifyTrackError')
|
||||||
);
|
);
|
||||||
|
|
||||||
clonedTrack = yteqv[0];
|
Object.defineProperty(queue.playing, 'backupLink', {
|
||||||
|
value: yteqv[0].url,
|
||||||
|
writable: true,
|
||||||
|
enumerable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clonedTrack.raw.source === 'youtube') {
|
if (queue.playing.raw.source === 'youtube' || queue.playing.raw.source === 'spotify') {
|
||||||
newStream = ytdl(clonedTrack.url, {
|
newStream = ytdl((queue.playing as any).backupLink ?? queue.playing.url, {
|
||||||
opusEncoded: true,
|
opusEncoded: true,
|
||||||
encoderArgs: clonedTrack.raw.live ? [] : encoderArgs,
|
encoderArgs: queue.playing.raw.live ? [] : encoderArgs,
|
||||||
seek: seekTime / 1000,
|
seek: seekTime / 1000,
|
||||||
// tslint:disable-next-line:no-bitwise
|
// tslint:disable-next-line:no-bitwise
|
||||||
highWaterMark: 1 << 25,
|
highWaterMark: 1 << 25,
|
||||||
|
@ -1315,9 +1319,9 @@ export class Player extends EventEmitter {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
newStream = ytdl.arbitraryStream(
|
newStream = ytdl.arbitraryStream(
|
||||||
clonedTrack.raw.source === 'soundcloud'
|
queue.playing.raw.source === 'soundcloud'
|
||||||
? await clonedTrack.raw.engine.downloadProgressive()
|
? await queue.playing.raw.engine.downloadProgressive()
|
||||||
: clonedTrack.raw.engine,
|
: queue.playing.raw.engine,
|
||||||
{
|
{
|
||||||
opusEncoded: true,
|
opusEncoded: true,
|
||||||
encoderArgs,
|
encoderArgs,
|
||||||
|
|
|
@ -133,7 +133,7 @@ export class Track {
|
||||||
.map((m, i) => parseInt(m) * times(60, i))
|
.map((m, i) => parseInt(m) * times(60, i))
|
||||||
.reduce((a, c) => a + c, 0);
|
.reduce((a, c) => a + c, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns source of this track
|
* Returns source of this track
|
||||||
* @type {TrackSource}
|
* @type {TrackSource}
|
||||||
|
|
Loading…
Reference in a new issue