2023-02-01 16:09:40 +01:00
|
|
|
const command = {
|
|
|
|
name: "yts",
|
|
|
|
desc: "search youtube for a video",
|
2023-02-02 23:37:42 +01:00
|
|
|
restricted: false,
|
2023-02-02 23:58:58 +01:00
|
|
|
mod: false,
|
2023-02-01 16:09:40 +01:00
|
|
|
run: async (client, msg, splitted) => {
|
|
|
|
if (splitted[2] === undefined) {
|
2023-02-11 13:48:05 +01:00
|
|
|
await client.say(
|
|
|
|
msg.channelName,
|
|
|
|
`${msg.displayName}, supply a search PoroSad`
|
|
|
|
);
|
2023-02-01 16:09:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const data = await fetch(
|
2023-02-06 15:02:34 +01:00
|
|
|
`https://invidious.epicsite.xyz/api/v1/search?type=video&q=${encodeURIComponent(
|
|
|
|
splitted.slice(2).join(" ")
|
|
|
|
)}`
|
2023-02-01 16:09:40 +01:00
|
|
|
)
|
|
|
|
.then((res) => res.json())
|
2023-02-02 23:37:42 +01:00
|
|
|
.then((data) => data[0])
|
2023-02-11 13:48:05 +01:00
|
|
|
.catch((err) =>
|
|
|
|
console.log("Error fetching from invidious: " + err.message)
|
|
|
|
);
|
2023-02-01 16:09:40 +01:00
|
|
|
|
2023-02-11 13:56:21 +01:00
|
|
|
if (!data) {
|
|
|
|
await client.say(msg.channelName, `${msg.displayName}, nothing found`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-02-11 13:48:05 +01:00
|
|
|
await client.say(
|
|
|
|
msg.channelName,
|
|
|
|
`${msg.displayName}, YouTube video with search term: ${splitted
|
|
|
|
.slice(2)
|
|
|
|
.join(" ")}; ${data.title} by ${data.author}, Link: youtu.be/watch?v=${
|
|
|
|
data.videoId
|
|
|
|
}`
|
|
|
|
);
|
2023-02-01 16:09:40 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-02-01 22:11:48 +01:00
|
|
|
module.exports = { command };
|