From fdbd2b5839d4fa526998fc8232abe12c000a8598 Mon Sep 17 00:00:00 2001 From: Androz2091 Date: Mon, 23 Nov 2020 21:17:09 +0100 Subject: [PATCH] :fire: Remove ytpl and use youtube-sr --- package.json | 3 +-- src/Player.js | 15 ++------------- src/Util.js | 3 +-- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index d004a25..d7fae1d 100644 --- a/package.json +++ b/package.json @@ -37,8 +37,7 @@ "soundcloud-scraper": "^4.0.0", "spotify-url-info": "^2.2.0", "youtube-sr": "^2.0.1", - "ytdl-core": "^4.0.6", - "ytpl": "^1.0.1" + "ytdl-core": "^4.0.6" }, "devDependencies": { "@discordjs/opus": "^0.3.2", diff --git a/src/Player.js b/src/Player.js index 635019d..3961c5a 100644 --- a/src/Player.js +++ b/src/Player.js @@ -1,7 +1,6 @@ const ytdl = require('discord-ytdl-core') const Discord = require('discord.js') const ytsr = require('youtube-sr') -const ytpl = require('ytpl') const spotify = require('spotify-url-info') const soundcloud = require('soundcloud-scraper') const moment = require('moment') @@ -291,19 +290,9 @@ class Player extends EventEmitter { * @param {String} query */ async _handlePlaylist (message, query) { - const playlist = await ytpl(query).catch(() => {}) + const playlist = await ytsr.getPlaylist(query) if (!playlist) return this.emit('noResults', message, query) - playlist.tracks = playlist.items.map((item) => new Track({ - title: item.title, - description: item.description, - views: item.views, - durationFormatted: item.duration, - url: item.url, - thumbnail: item.thumbnail, - channel: { - name: item.author.name - } - }, message.author)) + playlist.tracks = playlist.videos.map((item) => new Track(item, message.author)) playlist.duration = playlist.tracks.reduce((prev, next) => prev + next.duration, 0) playlist.thumbnail = playlist.tracks[0].thumbnail playlist.requestedBy = message.author diff --git a/src/Util.js b/src/Util.js index 206ceb0..0a06769 100644 --- a/src/Util.js +++ b/src/Util.js @@ -1,9 +1,8 @@ -const ytpl = require('ytpl') const { Util: { PlaylistURLRegex: playlistURLRegex } } = require('youtube-sr') const soundcloud = require('soundcloud-scraper') const Discord = require('discord.js') -const youtubeVideoRegex = (/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/) +const youtubeVideoRegex = (/(?:youtube\.com\/(?:[^/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?/\s]{11})/) const spotifySongRegex = (/https?:\/\/(?:embed\.|open\.)(?:spotify\.com\/)(?:track\/|\?uri=spotify:track:)((\w|-){22})/) module.exports = class Util {