discord-player-play-dl/src/Util.js

57 lines
1.7 KiB
JavaScript
Raw Normal View History

const ytsr = require('youtube-sr')
2020-08-14 17:57:32 +05:00
const soundcloud = require('soundcloud-scraper')
2021-01-10 21:13:10 +05:00
const chalk = require('chalk')
2020-08-13 18:21:42 +05:00
const spotifySongRegex = (/https?:\/\/(?:embed\.|open\.)(?:spotify\.com\/)(?:track\/|\?uri=spotify:track:)((\w|-){22})/)
const spotifyPlaylistRegex = (/https?:\/\/(?:embed\.|open\.)(?:spotify\.com\/)(?:playlist\/|\?uri=spotify:playlist:)((\w|-){22})/)
const spotifyAlbumRegex = (/https?:\/\/(?:embed\.|open\.)(?:spotify\.com\/)(?:album\/|\?uri=spotify:album:)((\w|-){22})/)
2020-08-13 18:21:42 +05:00
module.exports = class Util {
constructor () {
throw new Error(`The ${this.constructor.name} class may not be instantiated.`)
}
2021-01-10 21:13:10 +05:00
static checkFFMPEG () {
try {
const prism = require('prism-media')
prism.FFmpeg.getInfo()
return true;
} catch (e) {
this.alertFFMPEG();
return false;
}
}
static alertFFMPEG () {
console.log(chalk.red('ERROR:'), 'FFMPEG is not installed. Install with "npm install ffmpeg-static" or download it here: https://ffmpeg.org/download.html.');
}
2020-08-14 02:07:54 +05:00
static isVoiceEmpty (channel) {
return channel.members.filter((member) => !member.user.bot).size === 0
}
static isSoundcloudLink (query) {
2020-08-14 17:57:32 +05:00
return soundcloud.validateURL(query)
}
2020-08-13 18:21:42 +05:00
static isSpotifyLink (query) {
return spotifySongRegex.test(query)
}
static isSpotifyPLLink (query) {
return spotifyPlaylistRegex.test(query)
}
static isSpotifyAlbumLink(query) {
return spotifyAlbumRegex.test(query)
}
2020-08-13 18:21:42 +05:00
static isYTPlaylistLink (query) {
return ytsr.validate(query, 'PLAYLIST')
2020-08-13 18:21:42 +05:00
}
static isYTVideoLink (query) {
return ytsr.validate(query, 'VIDEO')
2020-08-13 18:21:42 +05:00
}
}