From 6748f1fb0353d8b78340dfdbca9fc8b05990a573 Mon Sep 17 00:00:00 2001 From: mudkipscience Date: Tue, 14 Apr 2020 19:44:02 +1000 Subject: [PATCH] playing from links *kinda* works now --- helpers/music.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/helpers/music.js b/helpers/music.js index 11ef0dd..33a8c0c 100644 --- a/helpers/music.js +++ b/helpers/music.js @@ -47,21 +47,16 @@ module.exports = client => { return guild } - client.music.isYouTubeLink = function (query) { - return query.startsWith('https://youtube.com/') || query.startsWith('http://youtube.com/') || query.startsWith('https://youtu.be/') || query.startsWith('http://youtu.be/') || query.startsWith('https://m.youtube.com/') || query.startsWith('http://m.youtube.com/') || query.startsWith('https://www.youtube.com/') || query.startsWith('http://www.youtube.com/') - } - client.music.getLinkFromID = function (id) { return 'https://www.youtube.com/watch?v=' + id } client.music.getVideoByQuery = async function (query) { - const isLink = client.music.isYouTubeLink(query) - let response - if (isLink) { - response = await fetch('https://www.googleapis.com/youtube/v3/search?key=' + client.config.keys.yt + '&part=id,snippet&maxResults=1&type=video&id=' + id) + if (ytdl.validateURL(query)) { + const id = await await ytdl.getURLVideoID(query) + response = await fetch('https://invidio.us/api/v1/videos/' + id) } else { // TODO: replace this workaround response = await fetch('https://invidio.us/api/v1/search?q=' + encodeURIComponent(query) + '**') @@ -69,7 +64,7 @@ module.exports = client => { const parsed = await response.json() - if (parsed[0]) { + if (parsed) { const videos = parsed if (videos) { @@ -137,8 +132,10 @@ module.exports = client => { } } - if (!video) { + if (!video && videos[0]) { video = videos[0] + } else { + video = videos } // Add video to queue