discord-player
Advanced tools
Comparing version 4.0.6 to 4.0.7
@@ -22,3 +22,13 @@ /// <reference types="node" /> | ||
queues: Collection<string, Queue>; | ||
/** | ||
* Collection of results collectors | ||
* @type {DiscordCollection<DiscordCollector<DiscordSnowflake, DiscordMessage>>} | ||
* @private | ||
*/ | ||
private _resultsCollectors; | ||
/** | ||
* Collection of cooldowns timeout | ||
* @type {DiscordCollection<Timeout>} | ||
* @private | ||
*/ | ||
private _cooldownsTimeout; | ||
@@ -50,2 +60,10 @@ /** | ||
unuse(extractorName: string): boolean; | ||
/** | ||
* Internal method to search tracks | ||
* @param {DiscordMessage} message The message | ||
* @param {string} query The query | ||
* @param {boolean} [firstResult=false] If it should return the first result | ||
* @returns {Promise<Track>} | ||
* @private | ||
*/ | ||
private _searchTracks; | ||
@@ -56,3 +74,3 @@ /** | ||
* @param {string|Track} query Search query, can be `Player.Track` instance | ||
* @param {Boolean} [firstResult] If it should play the first result | ||
* @param {Boolean} [firstResult=false] If it should play the first result | ||
* @example await player.play(message, "never gonna give you up", true) | ||
@@ -222,7 +240,50 @@ * @returns {Promise<void>} | ||
jump(message: Message, track: Track | number): boolean; | ||
/** | ||
* Internal method to handle VoiceStateUpdate events | ||
* @param {DiscordVoiceState} oldState The old voice state | ||
* @param {DiscordVoiceState} newState The new voice state | ||
* @returns {void} | ||
* @private | ||
*/ | ||
private _handleVoiceStateUpdate; | ||
private _addTrackToQueue; | ||
private _addTracksToQueue; | ||
/** | ||
* Internal method used to add tracks to the queue | ||
* @param {DiscordMessage} message The discord message | ||
* @param {Track} track The track | ||
* @returns {Queue} | ||
* @private | ||
*/ | ||
_addTrackToQueue(message: Message, track: Track): Queue; | ||
/** | ||
* Same as `_addTrackToQueue` but used for multiple tracks | ||
* @param {DiscordMessage} message Discord message | ||
* @param {Track[]} tracks The tracks | ||
* @returns {Queue} | ||
* @private | ||
*/ | ||
_addTracksToQueue(message: Message, tracks: Track[]): Queue; | ||
/** | ||
* Internal method used to create queue | ||
* @param {DiscordMessage} message The message | ||
* @param {Track} track The track | ||
* @returns {Promise<Queue>} | ||
* @private | ||
*/ | ||
private _createQueue; | ||
/** | ||
* Internal method used to init stream playing | ||
* @param {Queue} queue The queue | ||
* @param {boolean} firstPlay If this is a first play | ||
* @returns {Promise<void>} | ||
* @private | ||
*/ | ||
private _playTrack; | ||
/** | ||
* Internal method to play audio | ||
* @param {Queue} queue The queue | ||
* @param {boolean} updateFilter If this method was called for audio filter update | ||
* @param {number} [seek] Time in ms to seek to | ||
* @returns {Promise<void>} | ||
* @private | ||
*/ | ||
private _playStream; | ||
@@ -307,3 +368,4 @@ toString(): string; | ||
/** | ||
* Emitted when an error is triggered | ||
* Emitted when an error is triggered. | ||
* <warn>This event should handled properly by the users otherwise it might crash the process!</warn> | ||
* @event Player#error | ||
@@ -337,2 +399,3 @@ * @param {String} error It can be `NotConnected`, `UnableToJoin`, `NotPlaying`, `ParseError`, `LiveVideo` or `VideoUnavailable`. | ||
* @property {Boolean} [disableAutoRegister=false] If it should disable auto-registeration of `@discord-player/extractor` | ||
* @property {Boolean} [disableArtistSearch=false] If it should disable artist search for spotify | ||
*/ | ||
@@ -339,0 +402,0 @@ /** |
@@ -50,3 +50,13 @@ "use strict"; | ||
this.queues = new discord_js_1.Collection(); | ||
/** | ||
* Collection of results collectors | ||
* @type {DiscordCollection<DiscordCollector<DiscordSnowflake, DiscordMessage>>} | ||
* @private | ||
*/ | ||
this._resultsCollectors = new discord_js_1.Collection(); | ||
/** | ||
* Collection of cooldowns timeout | ||
* @type {DiscordCollection<Timeout>} | ||
* @private | ||
*/ | ||
this._cooldownsTimeout = new discord_js_1.Collection(); | ||
@@ -120,5 +130,13 @@ /** | ||
} | ||
/** | ||
* Internal method to search tracks | ||
* @param {DiscordMessage} message The message | ||
* @param {string} query The query | ||
* @param {boolean} [firstResult=false] If it should return the first result | ||
* @returns {Promise<Track>} | ||
* @private | ||
*/ | ||
_searchTracks(message, query, firstResult) { | ||
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; | ||
let tracks = []; | ||
@@ -134,3 +152,3 @@ const queryType = Util_1.default.getQueryType(query); | ||
url: data.url, | ||
duration: Util_1.default.buildTimeCode(Util_1.default.parseMS(data.duration / 1000)), | ||
duration: Util_1.default.buildTimeCode(Util_1.default.parseMS(data.duration)), | ||
description: data.description, | ||
@@ -155,3 +173,6 @@ thumbnail: data.thumbnail, | ||
if (spotifyData) { | ||
tracks = yield Util_1.default.ytSearch(`${spotifyData.artist} - ${spotifyData.title}`, { | ||
const searchString = this.options.disableArtistSearch | ||
? spotifyData.title | ||
: `${spotifyData.artist} - ${spotifyData.title}`; | ||
tracks = yield Util_1.default.ytSearch(searchString, { | ||
user: message.author, | ||
@@ -165,3 +186,2 @@ player: this, | ||
break; | ||
// todo: make spotify playlist/album load faster | ||
case 'spotify_album': | ||
@@ -173,8 +193,12 @@ case 'spotify_playlist': { | ||
return void this.emit(Constants_1.PlayerEvents.NO_RESULTS, message, query); | ||
// tslint:disable:no-shadowed-variable | ||
const tracks = []; | ||
for (const item of playlist.tracks.items) { | ||
// tslint:disable-next-line:no-shadowed-variable | ||
let tracks = yield Promise.all(playlist.tracks.items.map((item) => __awaiter(this, void 0, void 0, function* () { | ||
var _l, _m; | ||
const sq = queryType === 'spotify_album' | ||
? `${item.artists[0].name} - ${item.name}` | ||
: `${item.track.artists[0].name} - ${item.name}`; | ||
? `${this.options.disableArtistSearch | ||
? item.artists[0].name | ||
: `${item.artists[0].name} - `}${(_l = item.name) !== null && _l !== void 0 ? _l : item.track.name}` | ||
: `${this.options.disableArtistSearch | ||
? item.track.artists[0].name | ||
: `${item.track.artists[0].name} - `}${(_m = item.name) !== null && _m !== void 0 ? _m : item.track.name}`; | ||
const data = yield Util_1.default.ytSearch(sq, { | ||
@@ -186,8 +210,9 @@ limit: 1, | ||
}); | ||
if (data[0]) | ||
tracks.push(data[0]); | ||
} | ||
if (data.length) | ||
return data[0]; | ||
}))); | ||
tracks = tracks.filter((f) => !!f); | ||
if (!tracks.length) | ||
return void this.emit(Constants_1.PlayerEvents.NO_RESULTS, message, query); | ||
const pl = Object.assign(Object.assign({}, playlist), { tracks, duration: tracks.reduce((a, c) => a + c.durationMS, 0), thumbnail: (_b = (_a = playlist.images[0]) === null || _a === void 0 ? void 0 : _a.url) !== null && _b !== void 0 ? _b : tracks[0].thumbnail }); | ||
const pl = Object.assign(Object.assign({}, playlist), { tracks, duration: (_a = tracks === null || tracks === void 0 ? void 0 : tracks.reduce((a, c) => { var _a; return a + ((_a = c === null || c === void 0 ? void 0 : c.durationMS) !== null && _a !== void 0 ? _a : 0); }, 0)) !== null && _a !== void 0 ? _a : 0, thumbnail: (_c = (_b = playlist.images[0]) === null || _b === void 0 ? void 0 : _b.url) !== null && _c !== void 0 ? _c : tracks[0].thumbnail, title: (_e = (_d = playlist.title) !== null && _d !== void 0 ? _d : playlist.name) !== null && _e !== void 0 ? _e : '' }); | ||
this.emit(Constants_1.PlayerEvents.PLAYLIST_PARSE_END, pl, message); | ||
@@ -201,2 +226,3 @@ if (this.isPlaying(message)) { | ||
const queue = (yield this._createQueue(message, track).catch((e) => void this.emit(Constants_1.PlayerEvents.ERROR, e, message))); | ||
this.emit(Constants_1.PlayerEvents.PLAYLIST_ADD, message, queue, pl); | ||
this.emit(Constants_1.PlayerEvents.TRACK_START, message, queue.tracks[0], queue); | ||
@@ -231,7 +257,11 @@ this._addTracksToQueue(message, tracks); | ||
// @ts-ignore | ||
playlist.thumbnail = (_d = (_c = playlist.thumbnail) === null || _c === void 0 ? void 0 : _c.url) !== null && _d !== void 0 ? _d : playlist.videos[0].thumbnail; | ||
playlist.thumbnail = (_g = (_f = playlist.thumbnail) === null || _f === void 0 ? void 0 : _f.url) !== null && _g !== void 0 ? _g : playlist.videos[0].thumbnail; | ||
// @ts-ignore | ||
playlist.requestedBy = message.author; | ||
Object.defineProperty(playlist, 'tracks', { | ||
get: () => { var _a; return (_a = playlist.videos) !== null && _a !== void 0 ? _a : []; } | ||
}); | ||
this.emit(Constants_1.PlayerEvents.PLAYLIST_PARSE_END, playlist, message); | ||
// @ts-ignore | ||
// tslint:disable-next-line:no-shadowed-variable | ||
const tracks = playlist.videos; | ||
@@ -269,7 +299,7 @@ if (this.isPlaying(message)) { | ||
url: song.url, | ||
duration: Util_1.default.buildTimeCode(Util_1.default.parseMS(song.duration / 1000)), | ||
duration: Util_1.default.buildTimeCode(Util_1.default.parseMS(song.duration)), | ||
description: song.description, | ||
thumbnail: (_e = song.thumbnail) !== null && _e !== void 0 ? _e : 'https://soundcloud.com/pwa-icon-192.png', | ||
views: (_f = song.playCount) !== null && _f !== void 0 ? _f : 0, | ||
author: (_g = song.author) !== null && _g !== void 0 ? _g : data.author, | ||
thumbnail: (_h = song.thumbnail) !== null && _h !== void 0 ? _h : 'https://soundcloud.com/pwa-icon-192.png', | ||
views: (_j = song.playCount) !== null && _j !== void 0 ? _j : 0, | ||
author: (_k = song.author) !== null && _k !== void 0 ? _k : data.author, | ||
requestedBy: message.author, | ||
@@ -341,3 +371,3 @@ fromPlaylist: true, | ||
* @param {string|Track} query Search query, can be `Player.Track` instance | ||
* @param {Boolean} [firstResult] If it should play the first result | ||
* @param {Boolean} [firstResult=false] If it should play the first result | ||
* @example await player.play(message, "never gonna give you up", true) | ||
@@ -852,2 +882,3 @@ * @returns {Promise<void>} | ||
connections: this.client.voice.connections.size, | ||
// tslint:disable:no-shadowed-variable | ||
users: this.client.voice.connections.reduce((a, c) => a + c.channel.members.filter((a) => a.user.id !== this.client.user.id).size, 0), | ||
@@ -889,2 +920,9 @@ queues: this.queues.size, | ||
} | ||
/** | ||
* Internal method to handle VoiceStateUpdate events | ||
* @param {DiscordVoiceState} oldState The old voice state | ||
* @param {DiscordVoiceState} newState The new voice state | ||
* @returns {void} | ||
* @private | ||
*/ | ||
_handleVoiceStateUpdate(oldState, newState) { | ||
@@ -905,2 +943,3 @@ const queue = this.queues.find((g) => g.guildID === oldState.guild.id); | ||
const emptyTimeout = this._cooldownsTimeout.get(`empty_${oldState.guild.id}`); | ||
// @todo: stage channels | ||
const channelEmpty = Util_1.default.isVoiceEmpty(queue.voiceConnection.channel); | ||
@@ -927,2 +966,9 @@ if (!channelEmpty && emptyTimeout) { | ||
} | ||
/** | ||
* Internal method used to add tracks to the queue | ||
* @param {DiscordMessage} message The discord message | ||
* @param {Track} track The track | ||
* @returns {Queue} | ||
* @private | ||
*/ | ||
_addTrackToQueue(message, track) { | ||
@@ -937,2 +983,9 @@ const queue = this.getQueue(message); | ||
} | ||
/** | ||
* Same as `_addTrackToQueue` but used for multiple tracks | ||
* @param {DiscordMessage} message Discord message | ||
* @param {Track[]} tracks The tracks | ||
* @returns {Queue} | ||
* @private | ||
*/ | ||
_addTracksToQueue(message, tracks) { | ||
@@ -945,2 +998,9 @@ const queue = this.getQueue(message); | ||
} | ||
/** | ||
* Internal method used to create queue | ||
* @param {DiscordMessage} message The message | ||
* @param {Track} track The track | ||
* @returns {Promise<Queue>} | ||
* @private | ||
*/ | ||
_createQueue(message, track) { | ||
@@ -972,2 +1032,9 @@ return new Promise((resolve) => { | ||
} | ||
/** | ||
* Internal method used to init stream playing | ||
* @param {Queue} queue The queue | ||
* @param {boolean} firstPlay If this is a first play | ||
* @returns {Promise<void>} | ||
* @private | ||
*/ | ||
_playTrack(queue, firstPlay) { | ||
@@ -1024,2 +1091,10 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
/** | ||
* Internal method to play audio | ||
* @param {Queue} queue The queue | ||
* @param {boolean} updateFilter If this method was called for audio filter update | ||
* @param {number} [seek] Time in ms to seek to | ||
* @returns {Promise<void>} | ||
* @private | ||
*/ | ||
_playStream(queue, updateFilter, seek) { | ||
@@ -1178,3 +1253,4 @@ return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () { | ||
/** | ||
* Emitted when an error is triggered | ||
* Emitted when an error is triggered. | ||
* <warn>This event should handled properly by the users otherwise it might crash the process!</warn> | ||
* @event Player#error | ||
@@ -1208,2 +1284,3 @@ * @param {String} error It can be `NotConnected`, `UnableToJoin`, `NotPlaying`, `ParseError`, `LiveVideo` or `VideoUnavailable`. | ||
* @property {Boolean} [disableAutoRegister=false] If it should disable auto-registeration of `@discord-player/extractor` | ||
* @property {Boolean} [disableArtistSearch=false] If it should disable artist search for spotify | ||
*/ | ||
@@ -1210,0 +1287,0 @@ /** |
@@ -126,3 +126,8 @@ "use strict"; | ||
var _a, _b; | ||
return ((_b = (_a = this.voiceConnection) === null || _a === void 0 ? void 0 : _a.dispatcher) === null || _b === void 0 ? void 0 : _b.streamTime) + this.additionalStreamTime || 0; | ||
const NC = this.filters.nightcore ? 1.25 : null; | ||
const VW = this.filters.vaporwave ? 0.8 : null; | ||
const streamTime = ((_b = (_a = this.voiceConnection) === null || _a === void 0 ? void 0 : _a.dispatcher) === null || _b === void 0 ? void 0 : _b.streamTime) + this.additionalStreamTime || 0; | ||
if (NC && VW) | ||
return streamTime * (NC + VW); | ||
return NC ? streamTime * NC : VW ? streamTime * VW : streamTime; | ||
} | ||
@@ -129,0 +134,0 @@ /** |
@@ -16,2 +16,3 @@ /// <reference types="node" /> | ||
disableAutoRegister?: boolean; | ||
disableArtistSearch?: boolean; | ||
} | ||
@@ -18,0 +19,0 @@ export declare type FiltersName = keyof QueueFilters; |
import { PlayerOptions as DP_OPTIONS } from '../types/types'; | ||
export declare const PlayerEvents: { | ||
BOT_DISCONNECT: string; | ||
CHANNEL_EMPTY: string; | ||
CONNECTION_CREATE: string; | ||
ERROR: string; | ||
MUSIC_STOP: string; | ||
NO_RESULTS: string; | ||
PLAYLIST_ADD: string; | ||
PLAYLIST_PARSE_END: string; | ||
PLAYLIST_PARSE_START: string; | ||
QUEUE_CREATE: string; | ||
QUEUE_END: string; | ||
SEARCH_CANCEL: string; | ||
SEARCH_INVALID_RESPONSE: string; | ||
SEARCH_RESULTS: string; | ||
TRACK_ADD: string; | ||
TRACK_START: string; | ||
}; | ||
export declare const PlayerErrorEventCodes: { | ||
LIVE_VIDEO: string; | ||
NOT_CONNECTED: string; | ||
UNABLE_TO_JOIN: string; | ||
NOT_PLAYING: string; | ||
PARSE_ERROR: string; | ||
VIDEO_UNAVAILABLE: string; | ||
MUSIC_STARTING: string; | ||
}; | ||
export declare enum PlayerEvents { | ||
BOT_DISCONNECT = "botDisconnect", | ||
CHANNEL_EMPTY = "channelEmpty", | ||
CONNECTION_CREATE = "connectionCreate", | ||
ERROR = "error", | ||
MUSIC_STOP = "musicStop", | ||
NO_RESULTS = "noResults", | ||
PLAYLIST_ADD = "playlistAdd", | ||
PLAYLIST_PARSE_END = "playlistParseEnd", | ||
PLAYLIST_PARSE_START = "playlistParseStart", | ||
QUEUE_CREATE = "queueCreate", | ||
QUEUE_END = "queueEnd", | ||
SEARCH_CANCEL = "searchCancel", | ||
SEARCH_INVALID_RESPONSE = "searchInvalidResponse", | ||
SEARCH_RESULTS = "searchResults", | ||
TRACK_ADD = "trackAdd", | ||
TRACK_START = "trackStart" | ||
} | ||
export declare enum PlayerErrorEventCodes { | ||
LIVE_VIDEO = "LiveVideo", | ||
NOT_CONNECTED = "NotConnected", | ||
UNABLE_TO_JOIN = "UnableToJoin", | ||
NOT_PLAYING = "NotPlaying", | ||
PARSE_ERROR = "ParseError", | ||
VIDEO_UNAVAILABLE = "VideoUnavailable", | ||
MUSIC_STARTING = "MusicStarting" | ||
} | ||
export declare const PlayerOptions: DP_OPTIONS; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PlayerOptions = exports.PlayerErrorEventCodes = exports.PlayerEvents = void 0; | ||
exports.PlayerEvents = { | ||
BOT_DISCONNECT: 'botDisconnect', | ||
CHANNEL_EMPTY: 'channelEmpty', | ||
CONNECTION_CREATE: 'connectionCreate', | ||
ERROR: 'error', | ||
MUSIC_STOP: 'musicStop', | ||
NO_RESULTS: 'noResults', | ||
PLAYLIST_ADD: 'playlistAdd', | ||
PLAYLIST_PARSE_END: 'playlistParseEnd', | ||
PLAYLIST_PARSE_START: 'playlistParseStart', | ||
QUEUE_CREATE: 'queueCreate', | ||
QUEUE_END: 'queueEnd', | ||
SEARCH_CANCEL: 'searchCancel', | ||
SEARCH_INVALID_RESPONSE: 'searchInvalidResponse', | ||
SEARCH_RESULTS: 'searchResults', | ||
TRACK_ADD: 'trackAdd', | ||
TRACK_START: 'trackStart' | ||
}; | ||
exports.PlayerErrorEventCodes = { | ||
LIVE_VIDEO: 'LiveVideo', | ||
NOT_CONNECTED: 'NotConnected', | ||
UNABLE_TO_JOIN: 'UnableToJoin', | ||
NOT_PLAYING: 'NotPlaying', | ||
PARSE_ERROR: 'ParseError', | ||
VIDEO_UNAVAILABLE: 'VideoUnavailable', | ||
MUSIC_STARTING: 'MusicStarting' | ||
}; | ||
var PlayerEvents; | ||
(function (PlayerEvents) { | ||
PlayerEvents["BOT_DISCONNECT"] = "botDisconnect"; | ||
PlayerEvents["CHANNEL_EMPTY"] = "channelEmpty"; | ||
PlayerEvents["CONNECTION_CREATE"] = "connectionCreate"; | ||
PlayerEvents["ERROR"] = "error"; | ||
PlayerEvents["MUSIC_STOP"] = "musicStop"; | ||
PlayerEvents["NO_RESULTS"] = "noResults"; | ||
PlayerEvents["PLAYLIST_ADD"] = "playlistAdd"; | ||
PlayerEvents["PLAYLIST_PARSE_END"] = "playlistParseEnd"; | ||
PlayerEvents["PLAYLIST_PARSE_START"] = "playlistParseStart"; | ||
PlayerEvents["QUEUE_CREATE"] = "queueCreate"; | ||
PlayerEvents["QUEUE_END"] = "queueEnd"; | ||
PlayerEvents["SEARCH_CANCEL"] = "searchCancel"; | ||
PlayerEvents["SEARCH_INVALID_RESPONSE"] = "searchInvalidResponse"; | ||
PlayerEvents["SEARCH_RESULTS"] = "searchResults"; | ||
PlayerEvents["TRACK_ADD"] = "trackAdd"; | ||
PlayerEvents["TRACK_START"] = "trackStart"; | ||
})(PlayerEvents = exports.PlayerEvents || (exports.PlayerEvents = {})); | ||
var PlayerErrorEventCodes; | ||
(function (PlayerErrorEventCodes) { | ||
PlayerErrorEventCodes["LIVE_VIDEO"] = "LiveVideo"; | ||
PlayerErrorEventCodes["NOT_CONNECTED"] = "NotConnected"; | ||
PlayerErrorEventCodes["UNABLE_TO_JOIN"] = "UnableToJoin"; | ||
PlayerErrorEventCodes["NOT_PLAYING"] = "NotPlaying"; | ||
PlayerErrorEventCodes["PARSE_ERROR"] = "ParseError"; | ||
PlayerErrorEventCodes["VIDEO_UNAVAILABLE"] = "VideoUnavailable"; | ||
PlayerErrorEventCodes["MUSIC_STARTING"] = "MusicStarting"; | ||
})(PlayerErrorEventCodes = exports.PlayerErrorEventCodes || (exports.PlayerErrorEventCodes = {})); | ||
exports.PlayerOptions = { | ||
@@ -32,0 +34,0 @@ leaveOnEnd: true, |
{ | ||
"name": "discord-player", | ||
"version": "4.0.6", | ||
"version": "4.0.7", | ||
"description": "Complete framework to facilitate music commands using discord.js", | ||
@@ -51,6 +51,6 @@ "main": "lib/index.js", | ||
}, | ||
"homepage": "https://github.com/Androz2091/discord-player#readme", | ||
"homepage": "https://discord-player.js.org", | ||
"dependencies": { | ||
"discord-ytdl-core": "^5.0.3", | ||
"soundcloud-scraper": "^4.0.3", | ||
"soundcloud-scraper": "^4.0.4", | ||
"spotify-url-info": "^2.2.0", | ||
@@ -57,0 +57,0 @@ "youtube-sr": "^4.0.6", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
131312
3139
Updatedsoundcloud-scraper@^4.0.4