✨ Add support for soundcloud
This commit is contained in:
parent
3ac073059c
commit
78114ec36d
3 changed files with 20 additions and 13 deletions
|
@ -32,7 +32,7 @@
|
||||||
"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": "^1.0.1",
|
"soundcloud-scraper": "^1.0.2",
|
||||||
"spotify-url-info": "^1.3.1",
|
"spotify-url-info": "^1.3.1",
|
||||||
"ytpl": "^0.2.4",
|
"ytpl": "^0.2.4",
|
||||||
"ytsr": "^0.1.19"
|
"ytsr": "^0.1.19"
|
||||||
|
|
|
@ -3,6 +3,7 @@ const Discord = require('discord.js')
|
||||||
const ytsr = require('ytsr')
|
const ytsr = require('ytsr')
|
||||||
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 moment = require('moment')
|
const moment = require('moment')
|
||||||
const Queue = require('./Queue')
|
const Queue = require('./Queue')
|
||||||
const Track = require('./Track')
|
const Track = require('./Track')
|
||||||
|
@ -120,6 +121,8 @@ class Player extends EventEmitter {
|
||||||
return 'youtube-playlist'
|
return 'youtube-playlist'
|
||||||
} else if (this.util.isYTVideoLink(query)) {
|
} else if (this.util.isYTVideoLink(query)) {
|
||||||
return 'youtube-video'
|
return 'youtube-video'
|
||||||
|
} else if (this.util.isSoundcloudLink(query)) {
|
||||||
|
return 'soundcloud-song'
|
||||||
} else {
|
} else {
|
||||||
return 'youtube-video-keywords'
|
return 'youtube-video-keywords'
|
||||||
}
|
}
|
||||||
|
@ -133,25 +136,29 @@ class Player extends EventEmitter {
|
||||||
_searchTracks (message, query) {
|
_searchTracks (message, query) {
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
const tracks = []
|
const tracks = []
|
||||||
|
let updatedQuery = null
|
||||||
|
|
||||||
const queryType = this.resolveQueryType(query)
|
let queryType = this.resolveQueryType(query)
|
||||||
|
|
||||||
if (queryType === 'spotify-song') {
|
if (queryType === 'spotify-song') {
|
||||||
const matchSpotifyURL = query.match(/https?:\/\/(?:embed\.|open\.)(?:spotify\.com\/)(?:track\/|\?uri=spotify:track:)((\w|-){22})/)
|
const matchSpotifyURL = query.match(/https?:\/\/(?:embed\.|open\.)(?:spotify\.com\/)(?:track\/|\?uri=spotify:track:)((\w|-){22})/)
|
||||||
if (matchSpotifyURL) {
|
if (matchSpotifyURL) {
|
||||||
const spotifyData = await spotify.getPreview(query).catch(() => {})
|
const spotifyData = await spotify.getPreview(query).catch(() => {})
|
||||||
if (spotifyData) {
|
if (spotifyData) {
|
||||||
const YTQuery = `${spotifyData.artist} - ${spotifyData.track}`
|
updatedQuery = `${spotifyData.artist} - ${spotifyData.track}`
|
||||||
const results = await ytsr(YTQuery)
|
queryType = 'youtube-video-keywords'
|
||||||
|
|
||||||
if (results.items.length !== 0) {
|
|
||||||
const resultsVideo = results.items.filter((i) => i.type === 'video')
|
|
||||||
tracks.push(...resultsVideo.map((r) => new Track(r, message.author, null)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (queryType === 'youtube-video-keywords') {
|
} else if (queryType === 'soundcloud-song') {
|
||||||
await ytsr(query).then((results) => {
|
const soundcloudData = await soundcloud.getSongInfo(query).catch(() => {})
|
||||||
|
if (soundcloudData) {
|
||||||
|
updatedQuery = `${soundcloudData.author} - ${soundcloudData.title}`
|
||||||
|
queryType = 'youtube-video-keywords'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (queryType === 'youtube-video-keywords') {
|
||||||
|
await ytsr(updatedQuery || query).then((results) => {
|
||||||
if (results.items.length !== 0) {
|
if (results.items.length !== 0) {
|
||||||
const resultsVideo = results.items.filter((i) => i.type === 'video')
|
const resultsVideo = results.items.filter((i) => i.type === 'video')
|
||||||
tracks.push(...resultsVideo.map((r) => new Track(r, message.author, null)))
|
tracks.push(...resultsVideo.map((r) => new Track(r, message.author, null)))
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const ytpl = require('ytpl')
|
const ytpl = require('ytpl')
|
||||||
const scraper = require('soundcloud-scraper')
|
const soundcloud = require('soundcloud-scraper')
|
||||||
const Discord = require('discord.js')
|
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})/)
|
||||||
|
@ -15,7 +15,7 @@ module.exports = class Util {
|
||||||
}
|
}
|
||||||
|
|
||||||
static isSoundcloudLink (query) {
|
static isSoundcloudLink (query) {
|
||||||
return scraper.validateURL(query)
|
return soundcloud.validateURL(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
static isSpotifyLink (query) {
|
static isSpotifyLink (query) {
|
||||||
|
|
Loading…
Reference in a new issue