mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-05-13 04:51:35 +02:00
Read playlist song limit from Settings
This commit is contained in:
parent
96dcc4a536
commit
c9cc9a17b1
3 changed files with 27 additions and 14 deletions
|
@ -97,7 +97,7 @@ export default class {
|
|||
}
|
||||
}
|
||||
|
||||
async youtubePlaylist(listId: string): Promise<QueuedSongWithoutChannel[]> {
|
||||
async youtubePlaylist(listId: string, limit: number): Promise<QueuedSongWithoutChannel[]> {
|
||||
// YouTube playlist
|
||||
const playlist = await this.cache.wrap(
|
||||
this.youtube.playlists.get,
|
||||
|
@ -126,7 +126,7 @@ export default class {
|
|||
const {items, nextPageToken} = await this.cache.wrap(
|
||||
this.youtube.playlists.items,
|
||||
listId,
|
||||
{maxResults: '50', pageToken: nextToken},
|
||||
{maxResults: `${limit}`, pageToken: nextToken},
|
||||
{
|
||||
expiresIn: ONE_MINUTE_IN_SECONDS,
|
||||
},
|
||||
|
@ -188,7 +188,7 @@ export default class {
|
|||
return songsToReturn;
|
||||
}
|
||||
|
||||
async spotifySource(url: string): Promise<[QueuedSongWithoutChannel[], number, number]> {
|
||||
async spotifySource(url: string, limit: number): Promise<[QueuedSongWithoutChannel[], number, number]> {
|
||||
const parsed = spotifyURI.parse(url);
|
||||
|
||||
let tracks: SpotifyApi.TrackObjectSimplified[] = [];
|
||||
|
@ -199,7 +199,7 @@ export default class {
|
|||
case '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: 50})]);
|
||||
const [{body: album}, {body: {items}}] = await Promise.all([this.spotify.getAlbum(uri.id), this.spotify.getAlbumTracks(uri.id, {limit})]);
|
||||
|
||||
tracks.push(...items);
|
||||
|
||||
|
@ -210,7 +210,7 @@ export default class {
|
|||
case '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: 50})]);
|
||||
let [{body: playlistResponse}, {body: tracksResponse}] = await Promise.all([this.spotify.getPlaylist(uri.id), this.spotify.getPlaylistTracks(uri.id, {limit})]);
|
||||
|
||||
playlist = {title: playlistResponse.name, source: playlistResponse.href};
|
||||
|
||||
|
@ -219,7 +219,7 @@ export default class {
|
|||
while (tracksResponse.next) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
({body: tracksResponse} = await this.spotify.getPlaylistTracks(uri.id, {
|
||||
limit: parseInt(new URL(tracksResponse.next).searchParams.get('limit') ?? '50', 10),
|
||||
limit: parseInt(new URL(tracksResponse.next).searchParams.get('limit') ?? `${limit}`, 10),
|
||||
offset: parseInt(new URL(tracksResponse.next).searchParams.get('offset') ?? '0', 10),
|
||||
}));
|
||||
|
||||
|
@ -252,13 +252,13 @@ export default class {
|
|||
}
|
||||
}
|
||||
|
||||
// Get 50 random songs if many
|
||||
// Get random songs if the playlist is larger than limit
|
||||
const originalNSongs = tracks.length;
|
||||
|
||||
if (tracks.length > 50) {
|
||||
if (tracks.length > limit) {
|
||||
const shuffled = shuffle(tracks);
|
||||
|
||||
tracks = shuffled.slice(0, 50);
|
||||
tracks = shuffled.slice(0, limit);
|
||||
}
|
||||
|
||||
let songs = await Promise.all(tracks.map(async track => this.spotifyToYouTube(track, playlist)));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue