From cd2ac779d94f024b8968b7aaf82eaab747b5b2e5 Mon Sep 17 00:00:00 2001 From: Casper Date: Sun, 28 Feb 2021 08:20:20 +0100 Subject: [PATCH 01/13] add missing types & docs (#308) --- src/Queue.js | 16 ++++++++++++++++ typings/index.d.ts | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Queue.js b/src/Queue.js index a800a99..5b2442d 100644 --- a/src/Queue.js +++ b/src/Queue.js @@ -90,18 +90,34 @@ class Queue extends EventEmitter { this.firstMessage = message } + /** + * The current playing track + * @type {Track} + */ get playing () { return this.tracks[0] } + /** + * The calculated volume of the queue + * @type {number} + */ get calculatedVolume () { return this.filters.bassboost ? this.volume + 50 : this.volume } + /** + * Returns the total time of the queue in milliseconds + * @type {number} + */ get totalTime () { return this.tracks.length > 0 ? this.tracks.map((t) => t.durationMS).reduce((p, c) => p + c) : 0 } + /** + * The current stream time + * @type {number} + */ get currentStreamTime () { return this.voiceConnection.dispatcher ? this.voiceConnection.dispatcher.streamTime + this.additionalStreamTime diff --git a/typings/index.d.ts b/typings/index.d.ts index 4b1fc7f..8842fe1 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -115,7 +115,7 @@ declare module 'discord-player' { requestedBy: User; } type Playlist = YTSRPlaylist & CustomPlaylist; - type PlayerError = 'NotConnected' | 'UnableToJoin' | 'NotPlaying' | 'LiveVideo' | 'ParseError' | 'VideoUnavailable'; + type PlayerError = 'NotConnected' | 'UnableToJoin' | 'NotPlaying' | 'LiveVideo' | 'ParseError' | 'VideoUnavailable' | 'MusicStarting'; interface PlayerEvents { searchResults: [Message, string, Track[]]; searchInvalidResponse: [Message, string, Track[], string, MessageCollector]; @@ -155,6 +155,7 @@ declare module 'discord-player' { public playing: Track; public calculatedVolume: number; public currentStreamTime: number; + public totalTime: number; } class Track { constructor(videoData: object, user: User, player: Player); From 6548c966f25e361b0dee8261dfbbea31b913c3ba Mon Sep 17 00:00:00 2001 From: Snowflake107 Date: Fri, 30 Apr 2021 21:43:30 +0545 Subject: [PATCH 02/13] emit playlistAdd when queue is empty --- src/Player.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Player.ts b/src/Player.ts index a46af6e..bb32690 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -269,6 +269,7 @@ export class Player extends EventEmitter { const queue = (await this._createQueue(message, track).catch( (e) => void this.emit(PlayerEvents.ERROR, e, message) )) as Queue; + this.emit(PlayerEvents.PLAYLIST_ADD, message, queue, playlist); this.emit(PlayerEvents.TRACK_START, message, queue.tracks[0], queue); this._addTracksToQueue(message, tracks); } From 81843d42dfb2487020e389e133bdc7f1daae6e73 Mon Sep 17 00:00:00 2001 From: Snowflake107 Date: Fri, 30 Apr 2021 21:43:52 +0545 Subject: [PATCH 03/13] chore: prettier --- src/utils/AudioFilters.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/utils/AudioFilters.ts b/src/utils/AudioFilters.ts index ff21b68..52b600a 100644 --- a/src/utils/AudioFilters.ts +++ b/src/utils/AudioFilters.ts @@ -70,11 +70,15 @@ const FilterList = { }, get names() { - return Object.keys(this).filter((p) => !['names', 'length'].includes(p) && typeof this[p as FiltersName] !== 'function'); + return Object.keys(this).filter( + (p) => !['names', 'length'].includes(p) && typeof this[p as FiltersName] !== 'function' + ); }, get length() { - return Object.keys(this).filter((p) => !['names', 'length'].includes(p) && typeof this[p as FiltersName] !== 'function').length; + return Object.keys(this).filter( + (p) => !['names', 'length'].includes(p) && typeof this[p as FiltersName] !== 'function' + ).length; }, toString() { From c713401a975ff931d6d1933fdd8a0b44e1d164eb Mon Sep 17 00:00:00 2001 From: Snowflake107 Date: Fri, 30 Apr 2021 21:54:00 +0545 Subject: [PATCH 04/13] emit playlist add for soundcloud as well --- src/Player.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Player.ts b/src/Player.ts index bb32690..66dd1c6 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -324,6 +324,7 @@ export class Player extends EventEmitter { const queue = (await this._createQueue(message, track).catch( (e) => void this.emit(PlayerEvents.ERROR, e, message) )) as Queue; + this.emit(PlayerEvents.PLAYLIST_ADD, message, queue, res); this.emit(PlayerEvents.TRACK_START, message, queue.tracks[0], queue); this._addTracksToQueue(message, res.tracks); } From 71f5df301c785a83a12f42e5d1ee01841ceaefb1 Mon Sep 17 00:00:00 2001 From: ToledoSDL Date: Fri, 30 Apr 2021 13:52:53 -0300 Subject: [PATCH 05/13] New createProgressBar options! --- src/Player.ts | 4 ++-- src/types/types.ts | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Player.ts b/src/Player.ts index 66dd1c6..3fd32b8 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -881,8 +881,8 @@ export class Player extends EventEmitter { : 15; const index = Math.round((currentStreamTime / totalTime) * length); - const indicator = '🔘'; - const line = '▬'; + const indicator = typeof options?.indicator === 'string' ? options?.indicator.length > 0 ? options?.indicator : '🔘' : '🔘'; + const line = typeof options?.line === 'string' ? options?.line.length > 0 ? options?.line : '▬' : '▬'; if (index >= 1 && index <= length) { const bar = line.repeat(length - 1).split(''); diff --git a/src/types/types.ts b/src/types/types.ts index 81ee970..9e57e90 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -96,6 +96,8 @@ export interface PlayerProgressbarOptions { timecodes?: boolean; queue?: boolean; length?: number; + line?: string; + indicator?: string; } export interface LyricsData { From 585b1ef17cbe0d7874080b5455627aac0b70ef1d Mon Sep 17 00:00:00 2001 From: Snowflake107 Date: Sat, 1 May 2021 13:32:23 +0545 Subject: [PATCH 06/13] indicator --- src/Player.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Player.ts b/src/Player.ts index 3fd32b8..7c7b0e1 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -881,7 +881,7 @@ export class Player extends EventEmitter { : 15; const index = Math.round((currentStreamTime / totalTime) * length); - const indicator = typeof options?.indicator === 'string' ? options?.indicator.length > 0 ? options?.indicator : '🔘' : '🔘'; + const indicator = typeof options?.indicator === 'string' && options?.indicator.length > 0 ? options?.indicator : '🔘'; const line = typeof options?.line === 'string' ? options?.line.length > 0 ? options?.line : '▬' : '▬'; if (index >= 1 && index <= length) { From 41490b56374a2f6d4921e0ade7510149187dd015 Mon Sep 17 00:00:00 2001 From: Snowflake107 Date: Sat, 1 May 2021 13:32:47 +0545 Subject: [PATCH 07/13] progressbar track --- src/Player.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Player.ts b/src/Player.ts index 7c7b0e1..d9e13fb 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -882,7 +882,7 @@ export class Player extends EventEmitter { const index = Math.round((currentStreamTime / totalTime) * length); const indicator = typeof options?.indicator === 'string' && options?.indicator.length > 0 ? options?.indicator : '🔘'; - const line = typeof options?.line === 'string' ? options?.line.length > 0 ? options?.line : '▬' : '▬'; + const line = typeof options?.line === 'string' && options?.line.length > 0 ? options?.line : '▬'; if (index >= 1 && index <= length) { const bar = line.repeat(length - 1).split(''); From e5d77b006f4253b50c231d51e6dbc28a09652156 Mon Sep 17 00:00:00 2001 From: Snowflake107 Date: Sat, 1 May 2021 13:33:26 +0545 Subject: [PATCH 08/13] prettier --- src/Player.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Player.ts b/src/Player.ts index d9e13fb..a48b96a 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -881,7 +881,8 @@ export class Player extends EventEmitter { : 15; const index = Math.round((currentStreamTime / totalTime) * length); - const indicator = typeof options?.indicator === 'string' && options?.indicator.length > 0 ? options?.indicator : '🔘'; + const indicator = + typeof options?.indicator === 'string' && options?.indicator.length > 0 ? options?.indicator : '🔘'; const line = typeof options?.line === 'string' && options?.line.length > 0 ? options?.line : '▬'; if (index >= 1 && index <= length) { From c428335a56827cd7e78d394af3504ee75558a5ab Mon Sep 17 00:00:00 2001 From: Snowflake107 Date: Sat, 8 May 2021 15:32:46 +0545 Subject: [PATCH 09/13] remove --- src/Player.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Player.ts b/src/Player.ts index a48b96a..d1abeee 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -822,9 +822,9 @@ export class Player extends EventEmitter { queue.tracks = queue.tracks.filter((t) => t !== trackFound); } } else { - trackFound = queue.tracks.find((s) => s === track); + trackFound = queue.tracks.find((s) => s.url === track.url); if (trackFound) { - queue.tracks = queue.tracks.filter((s) => s !== trackFound); + queue.tracks = queue.tracks.filter((s) => s.url !== trackFound.url); } } From a154f48582c4a490aeeb8b73707db457d84947ed Mon Sep 17 00:00:00 2001 From: Snowflake107 Date: Sat, 8 May 2021 15:37:58 +0545 Subject: [PATCH 10/13] bump deps --- package.json | 6 +++--- src/Player.ts | 4 +++- yarn.lock | 28 ++++++++++++++-------------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 7e94075..aab60bc 100644 --- a/package.json +++ b/package.json @@ -50,11 +50,11 @@ }, "homepage": "https://github.com/Androz2091/discord-player#readme", "dependencies": { - "discord-ytdl-core": "^5.0.2", + "discord-ytdl-core": "^5.0.3", "soundcloud-scraper": "^4.0.3", "spotify-url-info": "^2.2.0", - "youtube-sr": "^4.0.4", - "ytdl-core": "^4.5.0" + "youtube-sr": "^4.0.6", + "ytdl-core": "^4.7.0" }, "devDependencies": { "@babel/cli": "^7.13.16", diff --git a/src/Player.ts b/src/Player.ts index d1abeee..85242d3 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -82,11 +82,13 @@ export class Player extends EventEmitter { */ this.filters = AudioFilters; - this.client.on('voiceStateUpdate', (o, n) => void this._handleVoiceStateUpdate(o, n)); + this.client.on('voiceStateUpdate', this._handleVoiceStateUpdate.bind(this)); // auto detect @discord-player/extractor if (!this.options.disableAutoRegister) { let nv: any; + + // tslint:disable:no-conditional-assignment if ((nv = Util.require('@discord-player/extractor'))) { ['Attachment', 'Facebook', 'Reverbnation', 'Vimeo'].forEach((ext) => void this.use(ext, nv[ext])); } diff --git a/yarn.lock b/yarn.lock index 8b2d9c3..14800c2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1785,12 +1785,12 @@ diff@^4.0.1: resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== -discord-ytdl-core@^5.0.2: - version "5.0.2" - resolved "https://registry.yarnpkg.com/discord-ytdl-core/-/discord-ytdl-core-5.0.2.tgz#28fb8712af8b5fda34f20800d2226b556e700422" - integrity sha512-tuu+skr0cA89Li7sCH+L1p3TwdfSOunmC9BFzSa0Jj567B1F2leVVbjKQ5ZKpsW1cXKv0fh0PdQA2/Fnu6WcQA== +discord-ytdl-core@^5.0.3: + version "5.0.3" + resolved "https://registry.yarnpkg.com/discord-ytdl-core/-/discord-ytdl-core-5.0.3.tgz#a31560f0bede41d6fc969377083ae958deac2b72" + integrity sha512-q4GOEFiV19l0OcPezXnkDWualf+n96LcbTEWReceiDHdx4xxn5CXZX9PR4iDTXQR3Kv2VUkwB8RO8dI50d88vQ== dependencies: - prism-media "^1.2.7" + prism-media "^1.2.9" discord.js-docgen@discordjs/docgen#ts-patch: version "0.9.0" @@ -3476,7 +3476,7 @@ prettier@^2.2.1: resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5" integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q== -prism-media@^1.2.7, prism-media@^1.2.9: +prism-media@^1.2.9: version "1.2.9" resolved "https://registry.yarnpkg.com/prism-media/-/prism-media-1.2.9.tgz#8d4f97b36efdfc82483eb8d3db64020767866f36" integrity sha512-UHCYuqHipbTR1ZsXr5eg4JUmHER8Ss4YEb9Azn+9zzJ7/jlTtD1h0lc4g6tNx3eMlB8Mp6bfll0LPMAV4R6r3Q== @@ -4627,18 +4627,18 @@ yargs@^14.0.0: y18n "^4.0.0" yargs-parser "^15.0.1" -youtube-sr@^4.0.4: - version "4.0.4" - resolved "https://registry.yarnpkg.com/youtube-sr/-/youtube-sr-4.0.4.tgz#48369b0cb1c53bd84c366a5420bb8f35b1db2329" - integrity sha512-Wf6YlANcCjAweY2MQuqJqusmMcGzaSDWE6ZTD8vifb9i9oFyKQpWuV58fnebJCFJE8G8pTLidmj5aRV7x384EQ== +youtube-sr@^4.0.6: + version "4.0.6" + resolved "https://registry.yarnpkg.com/youtube-sr/-/youtube-sr-4.0.6.tgz#e27c8fadb51361a6223ba0552b300f131c903fe9" + integrity sha512-nRrqgWl0xYfMhwLTqjF7G6s+36IHIdOMtZaSrz0Cpk4uSIqoeKEJgLiAZrYIGWGNYtS8/mzZYRzYxaIA/gW1Ig== dependencies: node-fetch "^2.6.1" simple-youtube-api "^5.2.1" -ytdl-core@^4.5.0: - version "4.5.0" - resolved "https://registry.yarnpkg.com/ytdl-core/-/ytdl-core-4.5.0.tgz#f07733387c548e5c3a5614c93ef55bde666eeaf4" - integrity sha512-e8r6skrakWNixsVlNPBMoRM1HrdW1swE97If9nenDUjF65uogYk4DvxIuqlmqRfBWKe+6aIZwqedNxUU9XLYJA== +ytdl-core@^4.7.0: + version "4.7.0" + resolved "https://registry.yarnpkg.com/ytdl-core/-/ytdl-core-4.7.0.tgz#2c92023536484d8a2760d1aa504df2778f87ae21" + integrity sha512-G09HeYsyLMsUCPEuK2asDqmLnOx+n5SxVV3QqGJd+iYuw5Z/qiwx7x0gxZTiAkHBsbG3WuluJWBPswZyrygKmQ== dependencies: m3u8stream "^0.8.3" miniget "^4.0.0" From 9b1d0e72d0befdde96f440df98f2731c35425bca Mon Sep 17 00:00:00 2001 From: Snowflake107 Date: Sat, 8 May 2021 15:53:38 +0545 Subject: [PATCH 11/13] docs --- docs/faq/custom_filters.md | 11 +++++++++++ docs/faq/live_video.md | 10 ++++++++++ docs/faq/pause_resume.md | 13 +++++++++++++ docs/index.yml | 8 ++++++++ 4 files changed, 42 insertions(+) create mode 100644 docs/faq/custom_filters.md create mode 100644 docs/faq/live_video.md create mode 100644 docs/faq/pause_resume.md diff --git a/docs/faq/custom_filters.md b/docs/faq/custom_filters.md new file mode 100644 index 0000000..bf7dbda --- /dev/null +++ b/docs/faq/custom_filters.md @@ -0,0 +1,11 @@ +# How to add custom audio filters +Audio filters in **Discord Player** are **[FFmpeg audio filters](http://ffmpeg.org/ffmpeg-all.html#Audio-Filters)**. You can add your own audio filter like this: + +```js +const { AudioFilters } = require("discord-player"); + +AudioFilters.define("3D", "apulsator=hz=0.128"); + +// later, it can be used like this +player.setFilters(message, { "3D": true }); +``` \ No newline at end of file diff --git a/docs/faq/live_video.md b/docs/faq/live_video.md new file mode 100644 index 0000000..c8966b3 --- /dev/null +++ b/docs/faq/live_video.md @@ -0,0 +1,10 @@ +# How to play live videos +You cannot play live videos by default. If you need to play the live video, just add this option: + +```js +const player = new Player(client, { + enableLive: true // enables livestream +}); +``` + +However, you cannot use audio filters with livestreams using this library! \ No newline at end of file diff --git a/docs/faq/pause_resume.md b/docs/faq/pause_resume.md new file mode 100644 index 0000000..6334d0a --- /dev/null +++ b/docs/faq/pause_resume.md @@ -0,0 +1,13 @@ +# Pause and Resume is not working properly +This is a bug in **[discord.js#5300](https://github.com/discordjs/discord.js/issues/5300)**. + +# Fix +You have to update your command something like this: + +```diff +- client.player.resume(message); + ++ client.player.resume(message); ++ client.player.pause(message); ++ client.player.resume(message); +``` \ No newline at end of file diff --git a/docs/index.yml b/docs/index.yml index f367636..3ab6cd4 100644 --- a/docs/index.yml +++ b/docs/index.yml @@ -6,6 +6,14 @@ files: - name: Extractors API path: extractor.md +- name: FAQ + files: + - name: Custom Filters + path: custom_filters.md + - name: Livestreams + path: live_video.md + - name: Pause & Resume + path: pause_resume.md - name: YouTube files: - name: Using Cookies From ba040fc5a1b20c43c845170d7259bf1d40364445 Mon Sep 17 00:00:00 2001 From: Snowflake107 Date: Sat, 8 May 2021 15:57:27 +0545 Subject: [PATCH 12/13] v4.0.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index aab60bc..69cea7b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord-player", - "version": "4.0.5", + "version": "4.0.6", "description": "Complete framework to facilitate music commands using discord.js", "main": "lib/index.js", "types": "lib/index.d.ts", From cdd182f67419cbdae5753bf436fa96d6f2ad2560 Mon Sep 17 00:00:00 2001 From: Snowflake107 Date: Sat, 8 May 2021 16:16:00 +0545 Subject: [PATCH 13/13] formatting --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- docs/faq/custom_filters.md | 1 + docs/faq/live_video.md | 1 + docs/faq/pause_resume.md | 2 ++ 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 325fe93..fb7e111 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -25,7 +25,7 @@ Steps to reproduce the behavior: **Please complete the following information:** - Node Version: [x.x.x] - - Library Version: [x.x.x] + - Discord Player Version: [x.x.x] - Discord.js Version: [x.x.x] **Additional context** diff --git a/docs/faq/custom_filters.md b/docs/faq/custom_filters.md index bf7dbda..35b39e5 100644 --- a/docs/faq/custom_filters.md +++ b/docs/faq/custom_filters.md @@ -1,4 +1,5 @@ # How to add custom audio filters + Audio filters in **Discord Player** are **[FFmpeg audio filters](http://ffmpeg.org/ffmpeg-all.html#Audio-Filters)**. You can add your own audio filter like this: ```js diff --git a/docs/faq/live_video.md b/docs/faq/live_video.md index c8966b3..1882bd4 100644 --- a/docs/faq/live_video.md +++ b/docs/faq/live_video.md @@ -1,4 +1,5 @@ # How to play live videos + You cannot play live videos by default. If you need to play the live video, just add this option: ```js diff --git a/docs/faq/pause_resume.md b/docs/faq/pause_resume.md index 6334d0a..d0cbc54 100644 --- a/docs/faq/pause_resume.md +++ b/docs/faq/pause_resume.md @@ -1,7 +1,9 @@ # Pause and Resume is not working properly + This is a bug in **[discord.js#5300](https://github.com/discordjs/discord.js/issues/5300)**. # Fix + You have to update your command something like this: ```diff