1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-11-10 05:10:17 +00:00

Update play.js

This commit is contained in:
MatteZ02 2020-07-03 11:23:26 +03:00
parent 2fb6267dd9
commit ba3d17bb2a

View File

@ -58,8 +58,7 @@ module.exports = {
); );
} else if (url.includes("album")) { } else if (url.includes("album")) {
const albumId = url.split("/album/")[1].split("?")[0]; const albumId = url.split("/album/")[1].split("?")[0];
spotify.getAlbumTracks(albumId) spotify.getAlbumTracks(albumId).then(
.then(
async function (data) { async function (data) {
searchAlbum(data, client, msg, voiceChannel); searchAlbum(data, client, msg, voiceChannel);
}, },
@ -77,17 +76,23 @@ module.exports = {
}, function (err) { }, function (err) {
console.log('Something went wrong!', err); console.log('Something went wrong!', err);
});*/ });*/
} else msg.channel.send(client.messages.invalidSpotifyUrl) } else msg.channel.send(client.messages.invalidSpotifyUrl);
} else if ( } else if (
url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/) url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)
) { ) {
const lmsg = await msg.channel.send(client.messages.loadingSongs); const lmsg = await msg.channel.send(client.messages.loadingSongs);
const playlist = await youtube.getPlaylist(url); const playlist = await youtube.getPlaylist(url).catch((err) => {
const videos = await playlist.getVideos(); console.log("err1");
});
const videos = await playlist.getVideos().catch((err) => {
console.log("err2");
});
for (const video of Object.values(videos)) { for (const video of Object.values(videos)) {
const video2 = await youtube.getVideoByID(video.id); const video2 = await youtube.getVideoByID(video.id).catch((err) => {
spotify.searchTracks(`track:${video2.name}`) console.log("err3");
.then(function (data) { });
spotify.searchTracks(`track:${video2.name}`).then(
function (data) {
client.funcs.handleVideo( client.funcs.handleVideo(
video2.url, video2.url,
msg, msg,
@ -97,10 +102,11 @@ module.exports = {
"ytdl", "ytdl",
data.body.tracks.items[0] data.body.tracks.items[0]
); );
}, function (err) { },
console.log('Something went wrong!', err); function (err) {
}); console.log("Something went wrong!", err);
}
);
} }
const message = client.messages.playlistAdded.replace( const message = client.messages.playlistAdded.replace(
"%TITLE%", "%TITLE%",
@ -109,15 +115,18 @@ module.exports = {
return lmsg.edit(message); return lmsg.edit(message);
} else { } else {
ytsr( ytsr(
searchString, { searchString,
{
limit: 5, limit: 5,
}, },
function (err, res) { function (err, res) {
if (err) console.log(err); if (err) console.log(err);
if (!res.items[0]) return msg.channel.send(client.messages.noResults); if (!res.items[0]) return msg.channel.send(client.messages.noResults);
const videoResults = res.items.filter(item => item.type === "video"); const videoResults = res.items.filter(
spotify.searchTracks(`track:${searchString}`) (item) => item.type === "video"
.then(function (data) { );
spotify.searchTracks(`track:${searchString}`).then(
function (data) {
client.funcs.handleVideo( client.funcs.handleVideo(
videoResults[0].link, videoResults[0].link,
msg, msg,
@ -127,9 +136,11 @@ module.exports = {
"ytdl", "ytdl",
data.body.tracks.items[0] data.body.tracks.items[0]
); );
}, function (err) { },
console.log('Something went wrong!', err); function (err) {
}); console.log("Something went wrong!", err);
}
);
} }
); );
} }
@ -143,21 +154,24 @@ async function searchPlaylist(data, client, msg, voiceChannel) {
const track = await data.body.tracks.items[i].track; const track = await data.body.tracks.items[i].track;
await client.funcs.sleep(250); await client.funcs.sleep(250);
ytsr( ytsr(
`${track.artists[0].name} ${track.name} audio`, { `${track.artists[0].name} ${track.name} audio`,
{
limit: 5, limit: 5,
}, },
async function (err, res) { async function (err, res) {
if (err) return console.log(err); if (err) return console.log(err);
if (!res.items[0]) { if (!res.items[0]) {
ytsr( ytsr(
`${track.artists[0].name} ${track.name} lyrics`, { `${track.artists[0].name} ${track.name} lyrics`,
{
limit: 5, limit: 5,
}, },
async function (err, res) { async function (err, res) {
if (err) return console.log(err); if (err) return console.log(err);
if (!res.items[0]) { if (!res.items[0]) {
ytsr( ytsr(
`${track.artists[0].name} ${track.name}`, { `${track.artists[0].name} ${track.name}`,
{
limit: 5, limit: 5,
}, },
async function (err, res) { async function (err, res) {
@ -165,7 +179,9 @@ async function searchPlaylist(data, client, msg, voiceChannel) {
if (!res.items[0]) { if (!res.items[0]) {
failed++; failed++;
} }
const videoResults = res.items.filter(item => item.type === "video"); const videoResults = res.items.filter(
(item) => item.type === "video"
);
client.funcs.handleVideo( client.funcs.handleVideo(
videoResults[0].link, videoResults[0].link,
msg, msg,
@ -179,7 +195,9 @@ async function searchPlaylist(data, client, msg, voiceChannel) {
); );
return; return;
} }
const videoResults = res.items.filter(item => item.type === "video"); const videoResults = res.items.filter(
(item) => item.type === "video"
);
await client.funcs.handleVideo( await client.funcs.handleVideo(
videoResults[0].link, videoResults[0].link,
msg, msg,
@ -194,7 +212,7 @@ async function searchPlaylist(data, client, msg, voiceChannel) {
failed++; failed++;
return; return;
} }
const videoResults = res.items.filter(item => item.type === "video"); const videoResults = res.items.filter((item) => item.type === "video");
await client.funcs.handleVideo( await client.funcs.handleVideo(
videoResults[0].link, videoResults[0].link,
msg, msg,
@ -226,21 +244,24 @@ async function searchAlbum(data, client, msg, voiceChannel) {
const track = await data.body.items[i]; const track = await data.body.items[i];
await client.funcs.sleep(250); await client.funcs.sleep(250);
ytsr( ytsr(
`${track.artists[0].name} ${track.name} audio`, { `${track.artists[0].name} ${track.name} audio`,
{
limit: 5, limit: 5,
}, },
async function (err, res) { async function (err, res) {
if (err) return console.log(err); if (err) return console.log(err);
if (!res.items[0]) { if (!res.items[0]) {
ytsr( ytsr(
`${track.artists[0].name} ${track.name} lyrics`, { `${track.artists[0].name} ${track.name} lyrics`,
{
limit: 5, limit: 5,
}, },
async function (err, res) { async function (err, res) {
if (err) return console.log(err); if (err) return console.log(err);
if (!res.items[0]) { if (!res.items[0]) {
ytsr( ytsr(
`${track.artists[0].name} ${track.name}`, { `${track.artists[0].name} ${track.name}`,
{
limit: 5, limit: 5,
}, },
async function (err, res) { async function (err, res) {
@ -248,7 +269,9 @@ async function searchAlbum(data, client, msg, voiceChannel) {
if (!res.items[0]) { if (!res.items[0]) {
failed++; failed++;
} }
const videoResults = res.items.filter(item => item.type === "video"); const videoResults = res.items.filter(
(item) => item.type === "video"
);
client.funcs.handleVideo( client.funcs.handleVideo(
videoResults[0].link, videoResults[0].link,
msg, msg,
@ -262,7 +285,9 @@ async function searchAlbum(data, client, msg, voiceChannel) {
); );
return; return;
} }
const videoResults = res.items.filter(item => item.type === "video"); const videoResults = res.items.filter(
(item) => item.type === "video"
);
await client.funcs.handleVideo( await client.funcs.handleVideo(
videoResults[0].link, videoResults[0].link,
msg, msg,
@ -277,7 +302,7 @@ async function searchAlbum(data, client, msg, voiceChannel) {
failed++; failed++;
return; return;
} }
const videoResults = res.items.filter(item => item.type === "video"); const videoResults = res.items.filter((item) => item.type === "video");
await client.funcs.handleVideo( await client.funcs.handleVideo(
videoResults[0].link, videoResults[0].link,
msg, msg,
@ -292,7 +317,10 @@ async function searchAlbum(data, client, msg, voiceChannel) {
} }
let message; let message;
if (failed === 0) { if (failed === 0) {
message = client.messages.albumAdded.replace("%TITLE%", "yes taht palylist"); message = client.messages.albumAdded.replace(
"%TITLE%",
"yes taht palylist"
);
} else { } else {
message = `${client.messages.albumAdded.replace( message = `${client.messages.albumAdded.replace(
"%TITLE%", "%TITLE%",
@ -309,21 +337,24 @@ async function searchSong(data, client, msg, voiceChannel) {
const track = await data.body.tracks.items[i].track; const track = await data.body.tracks.items[i].track;
await client.funcs.sleep(250); await client.funcs.sleep(250);
ytsr( ytsr(
`${track.artists[0].name} ${track.name} audio`, { `${track.artists[0].name} ${track.name} audio`,
{
limit: 5, limit: 5,
}, },
async function (err, res) { async function (err, res) {
if (err) return console.log(err); if (err) return console.log(err);
if (!res.items[0]) { if (!res.items[0]) {
ytsr( ytsr(
`${track.artists[0].name} ${track.name} lyrics`, { `${track.artists[0].name} ${track.name} lyrics`,
{
limit: 5, limit: 5,
}, },
async function (err, res) { async function (err, res) {
if (err) return console.log(err); if (err) return console.log(err);
if (!res.items[0]) { if (!res.items[0]) {
ytsr( ytsr(
`${track.artists[0].name} ${track.name}`, { `${track.artists[0].name} ${track.name}`,
{
limit: 5, limit: 5,
}, },
async function (err, res) { async function (err, res) {
@ -331,7 +362,9 @@ async function searchSong(data, client, msg, voiceChannel) {
if (!res.items[0]) { if (!res.items[0]) {
failed++; failed++;
} }
const videoResults = res.items.filter(item => item.type === "video"); const videoResults = res.items.filter(
(item) => item.type === "video"
);
client.funcs.handleVideo( client.funcs.handleVideo(
videoResults[0].link, videoResults[0].link,
msg, msg,
@ -345,7 +378,9 @@ async function searchSong(data, client, msg, voiceChannel) {
); );
return; return;
} }
const videoResults = res.items.filter(item => item.type === "video"); const videoResults = res.items.filter(
(item) => item.type === "video"
);
await client.funcs.handleVideo( await client.funcs.handleVideo(
videoResults[0].link, videoResults[0].link,
msg, msg,
@ -360,7 +395,7 @@ async function searchSong(data, client, msg, voiceChannel) {
failed++; failed++;
return; return;
} }
const videoResults = res.items.filter(item => item.type === "video"); const videoResults = res.items.filter((item) => item.type === "video");
await client.funcs.handleVideo( await client.funcs.handleVideo(
videoResults[0].link, videoResults[0].link,
msg, msg,