Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const search = args.join(" ");
- // the pattern inside the link
- const pattern = /^.*(youtu.be\/|list=)([^#\&\?]*).*/gi;
- const url = args[0];
- const urlValid = pattern.test(args[0]);
- let playlist = null;
- let videos = [];
- // converter
- if (urlValid) { / /if its a valid url ..
- try {
- // trying to get infos about the playlist first
- playlist = await youtube.getPlaylist(url, { part: "snippet" });
- videos = await playlist.getVideos(MAX_PLAYLIST_SIZE || 50, { part: "snippet" });
- } catch (error) {
- console.error(error);
- return message.reply(i18n.__("playlist.errorNotFoundPlaylist")).catch(console.error);
- }
- // if it cant extract the songs from the playlist, it will only search the first song in the playlist
- } else {
- try {
- const results = await youtube.searchPlaylists(search, 1, { part: "id" });
- playlist = results[0];
- videos = await playlist.getVideos(MAX_PLAYLIST_SIZE, { part: "snippet" });
- } catch (error) {
- console.error(error);
- return message.reply(error.message).catch(console.error);
- }
- }
- // some filtering checks
- const newSongs = videos
- .filter((video) => video.title != "Private video" && video.title != "Deleted video")
- .map((video) => {
- return (song = {
- title: video.title,
- url: video.url,
- duration: video.durationSeconds
- });
- });
- // push the playlist into the queue, change the serverQueue and queueContruct to your code design
- serverQueue ? serverQueue.songs.push(...newSongs) : queueConstruct.songs.push(...newSongs);
- // playing first song message, just replace all of this with the message.channel.send() if you dont want embed
- let playlistEmbed = new MessageEmbed()
- .setTitle(`${playlist.title}`)
- .setDescription(newSongs.map((song, index) => `${index + 1}. ${song.title}`))
- .setURL(playlist.url)
- .setColor("#00FF22")
- .setTimestamp();
- if (playlistEmbed.description.length >= 2048)
- playlistEmbed.description =
- playlistEmbed.description.substr(0, 2007) + i18n.__("playlist.playlistCharLimit");
- // it sends the entire playlist with all the song name that it can extract, replace it with other response rather than using mine
- message.channel.send(i18n.__mf("playlist.startedPlaylist", { author: message.author }), playlistEmbed);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement