mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-23 09:15:29 +01:00
Revert incorrect changes
This commit is contained in:
parent
d8086be5cf
commit
5ce3f92023
|
@ -92,8 +92,7 @@ export default class implements Command {
|
||||||
// YouTube source
|
// YouTube source
|
||||||
if (url.searchParams.get('list')) {
|
if (url.searchParams.get('list')) {
|
||||||
// YouTube playlist
|
// YouTube playlist
|
||||||
const playlist = await this.getSongs.youtubePlaylist(url.searchParams.get('list')!, playlistLimit);
|
newSongs.push(...await this.getSongs.youtubePlaylist(url.searchParams.get('list')!));
|
||||||
newSongs.push(...playlist);
|
|
||||||
} else {
|
} else {
|
||||||
// Single video
|
// Single video
|
||||||
const song = await this.getSongs.youtubeVideo(url.href);
|
const song = await this.getSongs.youtubeVideo(url.href);
|
||||||
|
|
|
@ -97,7 +97,7 @@ export default class {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async youtubePlaylist(listId: string, limit: number): Promise<QueuedSongWithoutChannel[]> {
|
async youtubePlaylist(listId: string): Promise<QueuedSongWithoutChannel[]> {
|
||||||
// YouTube playlist
|
// YouTube playlist
|
||||||
const playlist = await this.cache.wrap(
|
const playlist = await this.cache.wrap(
|
||||||
this.youtube.playlists.get,
|
this.youtube.playlists.get,
|
||||||
|
@ -126,7 +126,7 @@ export default class {
|
||||||
const {items, nextPageToken} = await this.cache.wrap(
|
const {items, nextPageToken} = await this.cache.wrap(
|
||||||
this.youtube.playlists.items,
|
this.youtube.playlists.items,
|
||||||
listId,
|
listId,
|
||||||
{maxResults: limit, pageToken: nextToken},
|
{maxResults: '50', pageToken: nextToken},
|
||||||
{
|
{
|
||||||
expiresIn: ONE_MINUTE_IN_SECONDS,
|
expiresIn: ONE_MINUTE_IN_SECONDS,
|
||||||
},
|
},
|
||||||
|
@ -188,7 +188,7 @@ export default class {
|
||||||
return songsToReturn;
|
return songsToReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
async spotifySource(url: string, limit: number): Promise<[QueuedSongWithoutChannel[], number, number]> {
|
async spotifySource(url: string, playlistLimit: number): Promise<[QueuedSongWithoutChannel[], number, number]> {
|
||||||
const parsed = spotifyURI.parse(url);
|
const parsed = spotifyURI.parse(url);
|
||||||
|
|
||||||
let tracks: SpotifyApi.TrackObjectSimplified[] = [];
|
let tracks: SpotifyApi.TrackObjectSimplified[] = [];
|
||||||
|
@ -199,7 +199,7 @@ export default class {
|
||||||
case 'album': {
|
case 'album': {
|
||||||
const uri = parsed as spotifyURI.Album;
|
const uri = parsed as spotifyURI.Album;
|
||||||
|
|
||||||
const [{body: album}, {body: {items}}] = await Promise.all([this.spotify.getAlbum(uri.id), this.spotify.getAlbumTracks(uri.id, {limit})]);
|
const [{body: album}, {body: {items}}] = await Promise.all([this.spotify.getAlbum(uri.id), this.spotify.getAlbumTracks(uri.id, {limit: 50})]);
|
||||||
|
|
||||||
tracks.push(...items);
|
tracks.push(...items);
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ export default class {
|
||||||
case 'playlist': {
|
case 'playlist': {
|
||||||
const uri = parsed as spotifyURI.Playlist;
|
const uri = parsed as spotifyURI.Playlist;
|
||||||
|
|
||||||
let [{body: playlistResponse}, {body: tracksResponse}] = await Promise.all([this.spotify.getPlaylist(uri.id), this.spotify.getPlaylistTracks(uri.id, {limit})]);
|
let [{body: playlistResponse}, {body: tracksResponse}] = await Promise.all([this.spotify.getPlaylist(uri.id), this.spotify.getPlaylistTracks(uri.id, {limit: 50})]);
|
||||||
|
|
||||||
playlist = {title: playlistResponse.name, source: playlistResponse.href};
|
playlist = {title: playlistResponse.name, source: playlistResponse.href};
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ export default class {
|
||||||
while (tracksResponse.next) {
|
while (tracksResponse.next) {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
({body: tracksResponse} = await this.spotify.getPlaylistTracks(uri.id, {
|
({body: tracksResponse} = await this.spotify.getPlaylistTracks(uri.id, {
|
||||||
limit,
|
limit: parseInt(new URL(tracksResponse.next).searchParams.get('limit') ?? '50', 10),
|
||||||
offset: parseInt(new URL(tracksResponse.next).searchParams.get('offset') ?? '0', 10),
|
offset: parseInt(new URL(tracksResponse.next).searchParams.get('offset') ?? '0', 10),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -255,10 +255,10 @@ export default class {
|
||||||
// Get random songs if the playlist is larger than limit
|
// Get random songs if the playlist is larger than limit
|
||||||
const originalNSongs = tracks.length;
|
const originalNSongs = tracks.length;
|
||||||
|
|
||||||
if (tracks.length > limit) {
|
if (tracks.length > playlistLimit) {
|
||||||
const shuffled = shuffle(tracks);
|
const shuffled = shuffle(tracks);
|
||||||
|
|
||||||
tracks = shuffled.slice(0, limit);
|
tracks = shuffled.slice(0, playlistLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
let songs = await Promise.all(tracks.map(async track => this.spotifyToYouTube(track, playlist)));
|
let songs = await Promise.all(tracks.map(async track => this.spotifyToYouTube(track, playlist)));
|
||||||
|
|
Loading…
Reference in a new issue