mirror of
https://github.com/musix-org/musix-oss
synced 2024-12-23 00:23:17 +00:00
updated video search
This commit is contained in:
parent
71250a8cf3
commit
e0087d5b5f
@ -43,8 +43,8 @@
|
||||
"soundcloud-api-client": "0.0.9",
|
||||
"spotify-web-api-node": "^4.0.0",
|
||||
"utf-8-validate": "^5.0.2",
|
||||
"yt-search": "^1.1.2",
|
||||
"ytdl-core": "^3.1.0",
|
||||
"ytsr": "^0.1.15",
|
||||
"zlib-sync": "^0.1.6"
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
const YouTube = require("simple-youtube-api");
|
||||
const SpotifyApi = require("spotify-web-api-node");
|
||||
const search = require("yt-search");
|
||||
const ytdl = require("ytdl-core")
|
||||
const ytdl = require("ytdl-core");
|
||||
const ytsr = require("ytsr");
|
||||
const ms = require("ms");
|
||||
|
||||
module.exports = {
|
||||
name: "play",
|
||||
@ -43,25 +44,18 @@ module.exports = {
|
||||
if (!voiceChannel.speakable)
|
||||
return msg.channel.send(client.messages.noPermsSpeak);
|
||||
if (ytdl.validateURL(url)) {
|
||||
client.funcs.handleVideo({
|
||||
url: url
|
||||
},
|
||||
msg,
|
||||
voiceChannel,
|
||||
client,
|
||||
false,
|
||||
"ytdl"
|
||||
);
|
||||
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)
|
||||
searchVideos(data, client, msg, voiceChannel);
|
||||
},
|
||||
function (err) {
|
||||
console.log(err);
|
||||
msg.channel.send(client.messages.noResultsSpotify);
|
||||
});
|
||||
}
|
||||
);
|
||||
} else if (
|
||||
url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)
|
||||
) {
|
||||
@ -71,7 +65,7 @@ module.exports = {
|
||||
for (const video of Object.values(videos)) {
|
||||
const video2 = await youtube.getVideoByID(video.id);
|
||||
await client.funcs.handleVideo(
|
||||
video2,
|
||||
video2.url,
|
||||
msg,
|
||||
voiceChannel,
|
||||
client,
|
||||
@ -85,19 +79,24 @@ module.exports = {
|
||||
);
|
||||
return lmsg.edit(message);
|
||||
} else {
|
||||
search(searchString, function (err, res) {
|
||||
if (err) return console.log(err);
|
||||
if (res.videos.length === 0)
|
||||
return msg.channel.send(client.messages.noResults);
|
||||
ytsr(
|
||||
searchString, {
|
||||
limit: 5,
|
||||
},
|
||||
function (err, res) {
|
||||
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(
|
||||
res.videos[0],
|
||||
videoResults[0].link,
|
||||
msg,
|
||||
voiceChannel,
|
||||
client,
|
||||
false,
|
||||
"ytdl"
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
@ -108,38 +107,45 @@ async function searchVideos(data, client, msg, voiceChannel) {
|
||||
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);
|
||||
search(
|
||||
`${track.artists[0].name} ${track.name} audio`,
|
||||
ytsr(
|
||||
`${track.artists[0].name} ${track.name} audio`, {
|
||||
limit: 5,
|
||||
},
|
||||
async function (err, res) {
|
||||
if (err) return console.log(err);
|
||||
if (res.videos.length === 0) {
|
||||
search(
|
||||
`${track.artists[0].name} ${track.name} lyrics`,
|
||||
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.videos.length === 0) {
|
||||
search(
|
||||
`${track.artists[0].name} ${track.name}`,
|
||||
if (!res.items[0]) {
|
||||
ytsr(
|
||||
`${track.artists[0].name} ${track.name}`, {
|
||||
limit: 5,
|
||||
},
|
||||
async function (err, res) {
|
||||
if (err) return console.log(err);
|
||||
if (res.videos.length === 0) {
|
||||
if (err) console.log(err);
|
||||
if (!res.items[0]) {
|
||||
failed++;
|
||||
return;
|
||||
}
|
||||
await client.funcs.handleVideo(
|
||||
res.videos[0],
|
||||
const videoResults = res.items.filter(item => item.type === "video");
|
||||
client.funcs.handleVideo(
|
||||
videoResults[0].link,
|
||||
msg,
|
||||
voiceChannel,
|
||||
client,
|
||||
true,
|
||||
false,
|
||||
"ytdl"
|
||||
);
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
const videoResults = res.items.filter(item => item.type === "video");
|
||||
await client.funcs.handleVideo(
|
||||
res.videos[0],
|
||||
videoResults[0].link,
|
||||
msg,
|
||||
voiceChannel,
|
||||
client,
|
||||
@ -151,8 +157,9 @@ async function searchVideos(data, client, msg, voiceChannel) {
|
||||
failed++;
|
||||
return;
|
||||
}
|
||||
const videoResults = res.items.filter(item => item.type === "video");
|
||||
await client.funcs.handleVideo(
|
||||
res.videos[0],
|
||||
videoResults[0].link,
|
||||
msg,
|
||||
voiceChannel,
|
||||
client,
|
||||
@ -164,10 +171,7 @@ async function searchVideos(data, client, msg, voiceChannel) {
|
||||
}
|
||||
let message;
|
||||
if (failed === 0) {
|
||||
message = client.messages.playlistAdded.replace(
|
||||
"%TITLE%",
|
||||
data.body.name
|
||||
);
|
||||
message = client.messages.playlistAdded.replace("%TITLE%", data.body.name);
|
||||
} else {
|
||||
message = `${client.messages.playlistAdded.replace(
|
||||
"%TITLE%",
|
||||
|
@ -1,4 +1,4 @@
|
||||
const yts = require('yt-search');
|
||||
const ytsr = require('ytsr');
|
||||
const he = require('he');
|
||||
|
||||
module.exports = {
|
||||
@ -22,10 +22,13 @@ module.exports = {
|
||||
if (voiceChannel.full) return msg.channel.send(client.messages.channelFull);
|
||||
if (!voiceChannel.joinable) return msg.channel.send(client.messages.noPermsConnect);
|
||||
if (!voiceChannel.speakable) return msg.channel.send(client.messages.noPermsSpeak);
|
||||
yts(searchString, async function (err, res) {
|
||||
ytsr(searchString, {
|
||||
limit: 20,
|
||||
}, async function (err, res) {
|
||||
if (err) return console.log(err);
|
||||
if (res.videos.length === 0) return msg.channel.send(client.messages.noResults);
|
||||
const videos = res.videos.slice(0, 10);
|
||||
if (!res.items[0]) return msg.channel.send(client.messages.noResults);
|
||||
const videoResults = res.items.filter(item => item.type === "video");
|
||||
const videos = videoResults.slice(0, 10);
|
||||
let index = 0;
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.setTitle(client.messages.songSelection)
|
||||
@ -44,7 +47,7 @@ module.exports = {
|
||||
return msg.channel.send(client.messages.cancellingVideoSelection);
|
||||
}
|
||||
const videoIndex = parseInt(response.first().content) - 1;
|
||||
return client.funcs.handleVideo(videos[videoIndex], msg, voiceChannel, client, false, "ytdl");
|
||||
return client.funcs.handleVideo(videos[videoIndex].link, msg, voiceChannel, client, false, "ytdl");
|
||||
})
|
||||
}
|
||||
};
|
@ -49,9 +49,8 @@ module.exports = {
|
||||
if (songs.length !== 0) {
|
||||
const lmsg = await msg.channel.send(client.messages.loadingSongs);
|
||||
for (let i = 0; i < songs.length; i++) {
|
||||
client.funcs.handleVideo({
|
||||
url: `https://www.youtube.com/watch?v=${songs[i].youtubeId}`
|
||||
}, msg, voiceChannel, client, true, "ytdl");
|
||||
client.funcs.handleVideo(
|
||||
`https://www.youtube.com/watch?v=${songs[i].youtubeId}`, msg, voiceChannel, client, true, "ytdl");
|
||||
}
|
||||
const message = client.messages.songsAdded.replace(
|
||||
"%AMOUNT%",
|
||||
|
@ -9,10 +9,10 @@ module.exports = async function (
|
||||
playlist,
|
||||
type
|
||||
) {
|
||||
const songInfo = await ytdl.getInfo(resource.url).catch(err => console.log(err));
|
||||
const songInfo = await ytdl.getInfo(resource).catch(err => console.log(err));
|
||||
const song = {
|
||||
title: Discord.Util.escapeMarkdown(songInfo.videoDetails.title),
|
||||
url: resource.url,
|
||||
url: resource,
|
||||
author: msg.author,
|
||||
type: type,
|
||||
info: songInfo.videoDetails
|
||||
|
@ -5,7 +5,7 @@ module.exports = async function (client, msg, youtube, voiceChannel, url) {
|
||||
const videos = await playlist.getVideos();
|
||||
for (const video of Object.values(videos)) {
|
||||
const video2 = await youtube.getVideoByID(video.id);
|
||||
await client.funcs.handleVideo(video2, msg, voiceChannel, client, true);
|
||||
await client.funcs.handleVideo(video2.url, msg, voiceChannel, client, true);
|
||||
}
|
||||
let message;
|
||||
message = client.messages.playlistAdded.replace("%TITLE%", playlist.title);
|
||||
|
Loading…
Reference in New Issue
Block a user