🐛 Fix everything
This commit is contained in:
parent
6ff0d6ad42
commit
50d086bb5c
3 changed files with 26 additions and 16 deletions
|
@ -28,14 +28,14 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/Androz2091/discord-player#readme",
|
"homepage": "https://github.com/Androz2091/discord-player#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord-ytdl-core": "^4.0.2",
|
"discord-ytdl-core": "^4.1.3",
|
||||||
"merge-options": "^2.0.0",
|
"merge-options": "^2.0.0",
|
||||||
"moment": "^2.27.0",
|
"moment": "^2.27.0",
|
||||||
"node-fetch": "^2.6.0",
|
"node-fetch": "^2.6.0",
|
||||||
"soundcloud-scraper": "^2.0.0",
|
"soundcloud-scraper": "^2.0.0",
|
||||||
"spotify-url-info": "^1.3.1",
|
"spotify-url-info": "^1.3.1",
|
||||||
"ytpl": "^1.0.1",
|
"youtube-sr": "^1.0.4",
|
||||||
"ytsr": "^1.0.1"
|
"ytpl": "^1.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@discordjs/opus": "^0.3.2",
|
"@discordjs/opus": "^0.3.2",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const ytdl = require('discord-ytdl-core')
|
const ytdl = require('discord-ytdl-core')
|
||||||
const Discord = require('discord.js')
|
const Discord = require('discord.js')
|
||||||
const ytsr = require('ytsr')
|
const ytsr = require('youtube-sr')
|
||||||
const ytpl = require('ytpl')
|
const ytpl = require('ytpl')
|
||||||
const spotify = require('spotify-url-info')
|
const spotify = require('spotify-url-info')
|
||||||
const soundcloud = require('soundcloud-scraper')
|
const soundcloud = require('soundcloud-scraper')
|
||||||
|
@ -141,7 +141,7 @@ class Player extends EventEmitter {
|
||||||
*/
|
*/
|
||||||
_searchTracks (message, query) {
|
_searchTracks (message, query) {
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
const tracks = []
|
let tracks = []
|
||||||
let updatedQuery = null
|
let updatedQuery = null
|
||||||
|
|
||||||
let queryType = this.resolveQueryType(query)
|
let queryType = this.resolveQueryType(query)
|
||||||
|
@ -164,10 +164,9 @@ class Player extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queryType === 'youtube-video-keywords') {
|
if (queryType === 'youtube-video-keywords') {
|
||||||
await ytsr(updatedQuery || query).then((results) => {
|
await ytsr.search(updatedQuery || query, { type: 'video' }).then((results) => {
|
||||||
if (results.items.length !== 0) {
|
if (results.length !== 0) {
|
||||||
const resultsVideo = results.items.filter((i) => i.type === 'video')
|
tracks = results.map((r) => new Track(r, message.author, null))
|
||||||
tracks.push(...resultsVideo.map((r) => new Track(r, message.author, null)))
|
|
||||||
}
|
}
|
||||||
}).catch(() => {})
|
}).catch(() => {})
|
||||||
}
|
}
|
||||||
|
@ -292,7 +291,17 @@ class Player extends EventEmitter {
|
||||||
async _handlePlaylist (message, query) {
|
async _handlePlaylist (message, query) {
|
||||||
const playlist = await ytpl(query).catch(() => {})
|
const playlist = await ytpl(query).catch(() => {})
|
||||||
if (!playlist) return this.emit('noResults', message, query)
|
if (!playlist) return this.emit('noResults', message, query)
|
||||||
playlist.tracks = playlist.items.map((item) => new Track(item, message.author))
|
playlist.tracks = playlist.items.map((item) => new Track({
|
||||||
|
title: item.title,
|
||||||
|
description: item.description,
|
||||||
|
views: item.views,
|
||||||
|
duration: item.duration,
|
||||||
|
url: item.url,
|
||||||
|
thumbnail: item.thumbnail,
|
||||||
|
channel: {
|
||||||
|
name: item.author.name
|
||||||
|
}
|
||||||
|
}, message.author))
|
||||||
playlist.duration = playlist.tracks.reduce((prev, next) => prev + next.duration, 0)
|
playlist.duration = playlist.tracks.reduce((prev, next) => prev + next.duration, 0)
|
||||||
playlist.thumbnail = playlist.tracks[0].thumbnail
|
playlist.thumbnail = playlist.tracks[0].thumbnail
|
||||||
playlist.requestedBy = message.author
|
playlist.requestedBy = message.author
|
||||||
|
@ -300,8 +309,9 @@ class Player extends EventEmitter {
|
||||||
const queue = this._addTracksToQueue(message, playlist.tracks)
|
const queue = this._addTracksToQueue(message, playlist.tracks)
|
||||||
this.emit('playlistAdd', message, queue, playlist)
|
this.emit('playlistAdd', message, queue, playlist)
|
||||||
} else {
|
} else {
|
||||||
const track = new Track(playlist.tracks.shift(), message.author)
|
const track = playlist.tracks.shift()
|
||||||
const queue = await this._createQueue(message, track).catch((e) => this.emit('error', message, e))
|
const queue = await this._createQueue(message, track).catch((e) => this.emit('error', message, e))
|
||||||
|
this.emit('trackStart', message, queue.tracks[0])
|
||||||
this._addTracksToQueue(message, playlist.tracks)
|
this._addTracksToQueue(message, playlist.tracks)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
src/Track.js
10
src/Track.js
|
@ -26,12 +26,12 @@ class Track {
|
||||||
* The Youtube URL of the track
|
* The Youtube URL of the track
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.url = videoData.link ?? videoData.url
|
this.url = videoData.url
|
||||||
/**
|
/**
|
||||||
* The video duration (formatted).
|
* The video duration (formatted).
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.duration = videoData.duration
|
this.duration = videoData.duration || videoData.durationFormatted
|
||||||
/**
|
/**
|
||||||
* The video description
|
* The video description
|
||||||
* @type {string}
|
* @type {string}
|
||||||
|
@ -41,17 +41,17 @@ class Track {
|
||||||
* The video thumbnail
|
* The video thumbnail
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.thumbnail = videoData.thumbnail
|
this.thumbnail = typeof videoData.thumbnail === 'object' ? videoData.thumbnail.url : videoData.thumbnail
|
||||||
/**
|
/**
|
||||||
* The video views
|
* The video views
|
||||||
* @type {?number}
|
* @type {?number}
|
||||||
*/
|
*/
|
||||||
this.views = videoData.views
|
this.views = parseInt(videoData.views)
|
||||||
/**
|
/**
|
||||||
* The video channel
|
* The video channel
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.author = videoData.author.name
|
this.author = videoData.channel.name
|
||||||
/**
|
/**
|
||||||
* The user who requested the track
|
* The user who requested the track
|
||||||
* @type {Discord.User?}
|
* @type {Discord.User?}
|
||||||
|
|
Loading…
Reference in a new issue