mirror of
https://github.com/ION606/selmerBot.git
synced 2026-05-14 21:26:54 +00:00
Transitioned all Misc, audio, Selmer Specific, admin, anime/manga, and inventory commands to Slash Command format. The RSS and reactionrole commands are still broken and all game commands are still in message format due to compications
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
const axios = require('axios');
|
||||
|
||||
/**
|
||||
* @param {String} purl
|
||||
* @returns {Promise<Array<String>>}
|
||||
*
|
||||
* @example
|
||||
* const purls = getPlaylistUrls(url);
|
||||
* purls.then((urls) => { console.log(urls); });
|
||||
*/
|
||||
async function getPlaylistUrls(bot, purl, isPremium) {
|
||||
const gApiKey = bot.youtubeAPIKey;
|
||||
const numSongs = (isPremium) ? 20 : 10;
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const pid = (purl.split("list=")[1]).replace("&feature=share", "");
|
||||
await axios.get(`https://www.googleapis.com/youtube/v3/playlistItems`, {
|
||||
params: {
|
||||
part: 'id,snippet',
|
||||
maxResults: numSongs,
|
||||
playlistId: pid,
|
||||
key: gApiKey
|
||||
}
|
||||
})
|
||||
.then((result) => {
|
||||
const l = [];
|
||||
result.data.items.forEach((vid, ind) => {
|
||||
const vurl = `https://www.youtube.com/watch?v=${vid.snippet.resourceId.videoId}`
|
||||
const pvurl = `https://www.youtube.com/watch?v=${vid.snippet.resourceId.videoId}&list=${pid}&index=${ind+1}`
|
||||
l.push({video_url: vurl, in_playlist_url: pvurl});
|
||||
});
|
||||
|
||||
resolve(l);
|
||||
}).catch((err) => { reject(err.message); });
|
||||
} catch (err) {
|
||||
reject(err.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
module.exports = { getPlaylistUrls }
|
||||
Reference in New Issue
Block a user