mirror of
https://github.com/musix-org/musix-oss
synced 2025-07-07 01:20:48 +00:00
Chore update 3.7
This commit is contained in:
@ -2,7 +2,6 @@ const YouTube = require("simple-youtube-api");
|
||||
const SpotifyApi = require("spotify-web-api-node");
|
||||
const ytdl = require("ytdl-core");
|
||||
const ytsr = require("ytsr");
|
||||
const ms = require("ms");
|
||||
|
||||
module.exports = {
|
||||
name: "play",
|
||||
@ -46,16 +45,39 @@ module.exports = {
|
||||
if (ytdl.validateURL(url)) {
|
||||
client.funcs.handleVideo(url, msg, voiceChannel, client, false, "ytdl");
|
||||
} else if (url.match(/^https?:\/\/(open.spotify.com|spotify.com)(.*)$/)) {
|
||||
const playlistId = url.split("/playlist/")[1].split("?")[0];
|
||||
spotify.getPlaylist(playlistId).then(
|
||||
async function (data) {
|
||||
searchVideos(data, client, msg, voiceChannel);
|
||||
},
|
||||
function (err) {
|
||||
console.log(err);
|
||||
msg.channel.send(client.messages.noResultsSpotify);
|
||||
}
|
||||
);
|
||||
if (url.includes("playlist")) {
|
||||
const playlistId = url.split("/playlist/")[1].split("?")[0];
|
||||
spotify.getPlaylist(playlistId).then(
|
||||
async function (data) {
|
||||
searchPlaylist(data, client, msg, voiceChannel);
|
||||
},
|
||||
function (err) {
|
||||
console.log(err);
|
||||
msg.channel.send(client.messages.noResultsSpotify);
|
||||
}
|
||||
);
|
||||
} else if (url.includes("album")) {
|
||||
const albumId = url.split("/album/")[1].split("?")[0];
|
||||
spotify.getAlbumTracks(albumId)
|
||||
.then(
|
||||
async function (data) {
|
||||
searchAlbum(data, client, msg, voiceChannel);
|
||||
},
|
||||
function (err) {
|
||||
console.log(err);
|
||||
msg.channel.send(client.messages.noResultsSpotify);
|
||||
}
|
||||
);
|
||||
} else if (url.includes("track")) {
|
||||
return msg.channel.send(client.messages.disabledSpotifySongs);
|
||||
/*const trackId = url.split("/track/")[1].split("?")[0];
|
||||
spotify.searchTracks(trackId)
|
||||
.then(function (data) {
|
||||
console.log(data.body)
|
||||
}, function (err) {
|
||||
console.log('Something went wrong!', err);
|
||||
});*/
|
||||
} else msg.channel.send(client.messages.invalidSpotifyUrl)
|
||||
} else if (
|
||||
url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)
|
||||
) {
|
||||
@ -64,14 +86,21 @@ module.exports = {
|
||||
const videos = await playlist.getVideos();
|
||||
for (const video of Object.values(videos)) {
|
||||
const video2 = await youtube.getVideoByID(video.id);
|
||||
await client.funcs.handleVideo(
|
||||
video2.url,
|
||||
msg,
|
||||
voiceChannel,
|
||||
client,
|
||||
true,
|
||||
"ytdl"
|
||||
);
|
||||
spotify.searchTracks(`track:${video2.name}`)
|
||||
.then(function (data) {
|
||||
client.funcs.handleVideo(
|
||||
video2.url,
|
||||
msg,
|
||||
voiceChannel,
|
||||
client,
|
||||
true,
|
||||
"ytdl",
|
||||
data.body.tracks.items[0]
|
||||
);
|
||||
}, function (err) {
|
||||
console.log('Something went wrong!', err);
|
||||
});
|
||||
|
||||
}
|
||||
const message = client.messages.playlistAdded.replace(
|
||||
"%TITLE%",
|
||||
@ -87,21 +116,27 @@ module.exports = {
|
||||
if (err) console.log(err);
|
||||
if (!res.items[0]) return msg.channel.send(client.messages.noResults);
|
||||
const videoResults = res.items.filter(item => item.type === "video");
|
||||
client.funcs.handleVideo(
|
||||
videoResults[0].link,
|
||||
msg,
|
||||
voiceChannel,
|
||||
client,
|
||||
false,
|
||||
"ytdl"
|
||||
);
|
||||
spotify.searchTracks(`track:${searchString}`)
|
||||
.then(function (data) {
|
||||
client.funcs.handleVideo(
|
||||
videoResults[0].link,
|
||||
msg,
|
||||
voiceChannel,
|
||||
client,
|
||||
false,
|
||||
"ytdl",
|
||||
data.body.tracks.items[0]
|
||||
);
|
||||
}, function (err) {
|
||||
console.log('Something went wrong!', err);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
async function searchVideos(data, client, msg, voiceChannel) {
|
||||
async function searchPlaylist(data, client, msg, voiceChannel) {
|
||||
const lmsg = await msg.channel.send(client.messages.loadingSongs);
|
||||
let failed = 0;
|
||||
for (let i = 0; data.body.tracks.items.length > i; i++) {
|
||||
@ -137,7 +172,8 @@ async function searchVideos(data, client, msg, voiceChannel) {
|
||||
voiceChannel,
|
||||
client,
|
||||
false,
|
||||
"ytdl"
|
||||
"spotify",
|
||||
track
|
||||
);
|
||||
}
|
||||
);
|
||||
@ -150,7 +186,8 @@ async function searchVideos(data, client, msg, voiceChannel) {
|
||||
voiceChannel,
|
||||
client,
|
||||
true,
|
||||
"ytdl"
|
||||
"spotify",
|
||||
track
|
||||
);
|
||||
}
|
||||
);
|
||||
@ -164,7 +201,174 @@ async function searchVideos(data, client, msg, voiceChannel) {
|
||||
voiceChannel,
|
||||
client,
|
||||
true,
|
||||
"ytdl"
|
||||
"spotify",
|
||||
track
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
let message;
|
||||
if (failed === 0) {
|
||||
message = client.messages.playlistAdded.replace("%TITLE%", data.body.name);
|
||||
} else {
|
||||
message = `${client.messages.playlistAdded.replace(
|
||||
"%TITLE%",
|
||||
data.body.name
|
||||
)}\n${client.messages.failedToLoad + failed}`;
|
||||
}
|
||||
lmsg.edit(message);
|
||||
}
|
||||
|
||||
async function searchAlbum(data, client, msg, voiceChannel) {
|
||||
const lmsg = await msg.channel.send(client.messages.loadingSongs);
|
||||
let failed = 0;
|
||||
for (let i = 0; data.body.items.length > i; i++) {
|
||||
const track = await data.body.items[i];
|
||||
await client.funcs.sleep(250);
|
||||
ytsr(
|
||||
`${track.artists[0].name} ${track.name} audio`, {
|
||||
limit: 5,
|
||||
},
|
||||
async function (err, res) {
|
||||
if (err) return console.log(err);
|
||||
if (!res.items[0]) {
|
||||
ytsr(
|
||||
`${track.artists[0].name} ${track.name} lyrics`, {
|
||||
limit: 5,
|
||||
},
|
||||
async function (err, res) {
|
||||
if (err) return console.log(err);
|
||||
if (!res.items[0]) {
|
||||
ytsr(
|
||||
`${track.artists[0].name} ${track.name}`, {
|
||||
limit: 5,
|
||||
},
|
||||
async function (err, res) {
|
||||
if (err) console.log(err);
|
||||
if (!res.items[0]) {
|
||||
failed++;
|
||||
}
|
||||
const videoResults = res.items.filter(item => item.type === "video");
|
||||
client.funcs.handleVideo(
|
||||
videoResults[0].link,
|
||||
msg,
|
||||
voiceChannel,
|
||||
client,
|
||||
false,
|
||||
"spotify",
|
||||
track
|
||||
);
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
const videoResults = res.items.filter(item => item.type === "video");
|
||||
await client.funcs.handleVideo(
|
||||
videoResults[0].link,
|
||||
msg,
|
||||
voiceChannel,
|
||||
client,
|
||||
true,
|
||||
"spotify",
|
||||
track
|
||||
);
|
||||
}
|
||||
);
|
||||
failed++;
|
||||
return;
|
||||
}
|
||||
const videoResults = res.items.filter(item => item.type === "video");
|
||||
await client.funcs.handleVideo(
|
||||
videoResults[0].link,
|
||||
msg,
|
||||
voiceChannel,
|
||||
client,
|
||||
true,
|
||||
"spotify",
|
||||
track
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
let message;
|
||||
if (failed === 0) {
|
||||
message = client.messages.albumAdded.replace("%TITLE%", "yes taht palylist");
|
||||
} else {
|
||||
message = `${client.messages.albumAdded.replace(
|
||||
"%TITLE%",
|
||||
"yes taht palylist"
|
||||
)}\n${client.messages.failedToLoad + failed}`;
|
||||
}
|
||||
lmsg.edit(message);
|
||||
}
|
||||
|
||||
async function searchSong(data, client, msg, voiceChannel) {
|
||||
const lmsg = await msg.channel.send(client.messages.loadingSongs);
|
||||
let failed = 0;
|
||||
for (let i = 0; data.body.tracks.items.length > i; i++) {
|
||||
const track = await data.body.tracks.items[i].track;
|
||||
await client.funcs.sleep(250);
|
||||
ytsr(
|
||||
`${track.artists[0].name} ${track.name} audio`, {
|
||||
limit: 5,
|
||||
},
|
||||
async function (err, res) {
|
||||
if (err) return console.log(err);
|
||||
if (!res.items[0]) {
|
||||
ytsr(
|
||||
`${track.artists[0].name} ${track.name} lyrics`, {
|
||||
limit: 5,
|
||||
},
|
||||
async function (err, res) {
|
||||
if (err) return console.log(err);
|
||||
if (!res.items[0]) {
|
||||
ytsr(
|
||||
`${track.artists[0].name} ${track.name}`, {
|
||||
limit: 5,
|
||||
},
|
||||
async function (err, res) {
|
||||
if (err) console.log(err);
|
||||
if (!res.items[0]) {
|
||||
failed++;
|
||||
}
|
||||
const videoResults = res.items.filter(item => item.type === "video");
|
||||
client.funcs.handleVideo(
|
||||
videoResults[0].link,
|
||||
msg,
|
||||
voiceChannel,
|
||||
client,
|
||||
false,
|
||||
"spotify",
|
||||
track
|
||||
);
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
const videoResults = res.items.filter(item => item.type === "video");
|
||||
await client.funcs.handleVideo(
|
||||
videoResults[0].link,
|
||||
msg,
|
||||
voiceChannel,
|
||||
client,
|
||||
true,
|
||||
"spotify",
|
||||
track
|
||||
);
|
||||
}
|
||||
);
|
||||
failed++;
|
||||
return;
|
||||
}
|
||||
const videoResults = res.items.filter(item => item.type === "video");
|
||||
await client.funcs.handleVideo(
|
||||
videoResults[0].link,
|
||||
msg,
|
||||
voiceChannel,
|
||||
client,
|
||||
true,
|
||||
"spotify",
|
||||
track
|
||||
);
|
||||
}
|
||||
);
|
||||
|
Reference in New Issue
Block a user