fix youtube playlist not playing

This commit is contained in:
Snowflake107 2021-06-14 13:13:31 +05:45
parent d5e3f6225c
commit 7f34fbd786
3 changed files with 10 additions and 10 deletions

View file

@ -305,9 +305,9 @@ class DiscordPlayer extends EventEmitter<PlayerEvents> {
// @todo: better way of handling large playlists // @todo: better way of handling large playlists
await ytpl.fetch().catch(() => {}); await ytpl.fetch().catch(() => {});
const playlist = new Playlist(this, { const playlist: Playlist = new Playlist(this, {
title: ytpl.title, title: ytpl.title,
thumbnail: ytpl.thumbnail?.displayThumbnailURL("maxresdefault"), thumbnail: ytpl.thumbnail as unknown as string,
description: "", description: "",
type: "playlist", type: "playlist",
source: "youtube", source: "youtube",
@ -321,22 +321,22 @@ class DiscordPlayer extends EventEmitter<PlayerEvents> {
rawPlaylist: ytpl rawPlaylist: ytpl
}); });
for (const video of ytpl) { playlist.tracks = ytpl.videos.map(
playlist.tracks.push( (video) =>
new Track(this, { new Track(this, {
title: video.title, title: video.title,
description: video.description, description: video.description,
author: video.channel?.name, author: video.channel?.name,
url: video.url, url: video.url,
requestedBy: options.requestedBy, requestedBy: options.requestedBy,
thumbnail: video.thumbnail?.displayThumbnailURL("maxresdefault"), thumbnail: video.thumbnail.url,
views: video.views, views: video.views,
duration: video.durationFormatted, duration: video.durationFormatted,
raw: video, raw: video,
playlist: playlist playlist: playlist,
source: "youtube"
}) })
); );
}
return { playlist: playlist, tracks: playlist.tracks }; return { playlist: playlist, tracks: playlist.tracks };
} }

View file

@ -106,7 +106,7 @@ class Track {
this.playlist = data.playlist; this.playlist = data.playlist;
// raw // raw
Object.defineProperty(this, "raw", { get: () => data.raw ?? data, enumerable: false }); Object.defineProperty(this, "raw", { get: () => Object.assign({}, { source: data.raw?.source ?? data.source }, data.raw ?? data), enumerable: false });
} }
/** /**

View file

@ -19,8 +19,8 @@ class QueryResolver {
static resolve(query: string): QueryType { static resolve(query: string): QueryType {
if (SoundcloudValidateURL(query, "track")) return QueryType.SOUNDCLOUD_TRACK; if (SoundcloudValidateURL(query, "track")) return QueryType.SOUNDCLOUD_TRACK;
if (SoundcloudValidateURL(query, "playlist") || query.includes("/sets/")) return QueryType.SOUNDCLOUD_PLAYLIST; if (SoundcloudValidateURL(query, "playlist") || query.includes("/sets/")) return QueryType.SOUNDCLOUD_PLAYLIST;
if (YouTube.isPlaylist(query)) return QueryType.YOUTUBE_PLAYLIST;
if (validateID(query) || validateURL(query)) return QueryType.YOUTUBE_SEARCH; if (validateID(query) || validateURL(query)) return QueryType.YOUTUBE_SEARCH;
if (YouTube.validate(query, "PLAYLIST_ID")) return QueryType.YOUTUBE_PLAYLIST;
if (spotifySongRegex.test(query)) return QueryType.SPOTIFY_SONG; if (spotifySongRegex.test(query)) return QueryType.SPOTIFY_SONG;
if (spotifyPlaylistRegex.test(query)) return QueryType.SPOTIFY_PLAYLIST; if (spotifyPlaylistRegex.test(query)) return QueryType.SPOTIFY_PLAYLIST;
if (spotifyAlbumRegex.test(query)) return QueryType.SPOTIFY_ALBUM; if (spotifyAlbumRegex.test(query)) return QueryType.SPOTIFY_ALBUM;