distube 2.8.18 → 3.0.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -98
- package/dist/DisTube.d.ts +522 -0
- package/dist/DisTube.d.ts.map +1 -0
- package/dist/DisTube.js +794 -0
- package/dist/DisTube.js.map +1 -0
- package/dist/constant.d.ts +130 -0
- package/dist/constant.d.ts.map +1 -0
- package/dist/constant.js +150 -0
- package/dist/constant.js.map +1 -0
- package/dist/core/DisTubeBase.d.ts +55 -0
- package/dist/core/DisTubeBase.d.ts.map +1 -0
- package/dist/core/DisTubeBase.js +76 -0
- package/dist/core/DisTubeBase.js.map +1 -0
- package/dist/core/DisTubeHandler.d.ts +84 -0
- package/dist/core/DisTubeHandler.d.ts.map +1 -0
- package/dist/core/DisTubeHandler.js +311 -0
- package/dist/core/DisTubeHandler.js.map +1 -0
- package/dist/core/DisTubeOptions.d.ts +26 -0
- package/dist/core/DisTubeOptions.d.ts.map +1 -0
- package/dist/core/DisTubeOptions.js +93 -0
- package/dist/core/DisTubeOptions.js.map +1 -0
- package/dist/core/DisTubeStream.d.ts +52 -0
- package/dist/core/DisTubeStream.d.ts.map +1 -0
- package/dist/core/DisTubeStream.js +109 -0
- package/dist/core/DisTubeStream.js.map +1 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +19 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/manager/BaseManager.d.ts +18 -0
- package/dist/core/manager/BaseManager.d.ts.map +1 -0
- package/dist/core/manager/BaseManager.js +44 -0
- package/dist/core/manager/BaseManager.js.map +1 -0
- package/dist/core/manager/QueueManager.d.ts +60 -0
- package/dist/core/manager/QueueManager.d.ts.map +1 -0
- package/dist/core/manager/QueueManager.js +202 -0
- package/dist/core/manager/QueueManager.js.map +1 -0
- package/dist/core/manager/index.d.ts +3 -0
- package/dist/core/manager/index.d.ts.map +1 -0
- package/dist/core/manager/index.js +15 -0
- package/dist/core/manager/index.js.map +1 -0
- package/dist/core/voice/DJSAdapter.d.ts +4 -0
- package/dist/core/voice/DJSAdapter.d.ts.map +1 -0
- package/dist/core/voice/DJSAdapter.js +61 -0
- package/dist/core/voice/DJSAdapter.js.map +1 -0
- package/dist/core/voice/DisTubeVoice.d.ts +83 -0
- package/dist/core/voice/DisTubeVoice.d.ts.map +1 -0
- package/dist/core/voice/DisTubeVoice.js +236 -0
- package/dist/core/voice/DisTubeVoice.js.map +1 -0
- package/dist/core/voice/DisTubeVoiceManager.d.ts +41 -0
- package/dist/core/voice/DisTubeVoiceManager.d.ts.map +1 -0
- package/dist/core/voice/DisTubeVoiceManager.js +67 -0
- package/dist/core/voice/DisTubeVoiceManager.js.map +1 -0
- package/dist/core/voice/index.d.ts +4 -0
- package/dist/core/voice/index.d.ts.map +1 -0
- package/dist/core/voice/index.js +16 -0
- package/dist/core/voice/index.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin/http.d.ts +8 -0
- package/dist/plugin/http.d.ts.map +1 -0
- package/dist/plugin/http.js +20 -0
- package/dist/plugin/http.js.map +1 -0
- package/dist/plugin/https.d.ts +14 -0
- package/dist/plugin/https.d.ts.map +1 -0
- package/dist/plugin/https.js +50 -0
- package/dist/plugin/https.js.map +1 -0
- package/dist/plugin/index.d.ts +4 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +16 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/youtube-dl.d.ts +11 -0
- package/dist/plugin/youtube-dl.d.ts.map +1 -0
- package/dist/plugin/youtube-dl.js +75 -0
- package/dist/plugin/youtube-dl.js.map +1 -0
- package/dist/struct/CustomPlugin.d.ts +27 -0
- package/dist/struct/CustomPlugin.d.ts.map +1 -0
- package/dist/struct/CustomPlugin.js +35 -0
- package/dist/struct/CustomPlugin.js.map +1 -0
- package/dist/struct/DisTubeError.d.ts +54 -0
- package/dist/struct/DisTubeError.d.ts.map +1 -0
- package/dist/struct/DisTubeError.js +72 -0
- package/dist/struct/DisTubeError.js.map +1 -0
- package/dist/struct/ExtractorPlugin.d.ts +29 -0
- package/dist/struct/ExtractorPlugin.d.ts.map +1 -0
- package/dist/struct/ExtractorPlugin.js +32 -0
- package/dist/struct/ExtractorPlugin.js.map +1 -0
- package/dist/struct/Playlist.d.ts +42 -0
- package/dist/struct/Playlist.d.ts.map +1 -0
- package/dist/struct/Playlist.js +104 -0
- package/dist/struct/Playlist.js.map +1 -0
- package/dist/struct/Plugin.d.ts +82 -0
- package/dist/struct/Plugin.d.ts.map +1 -0
- package/dist/struct/Plugin.js +108 -0
- package/dist/struct/Plugin.js.map +1 -0
- package/dist/struct/Queue.d.ts +217 -0
- package/dist/struct/Queue.d.ts.map +1 -0
- package/dist/struct/Queue.js +480 -0
- package/dist/struct/Queue.js.map +1 -0
- package/dist/struct/SearchResult.d.ts +28 -0
- package/dist/struct/SearchResult.d.ts.map +1 -0
- package/dist/struct/SearchResult.js +79 -0
- package/dist/struct/SearchResult.js.map +1 -0
- package/dist/struct/Song.d.ts +68 -0
- package/dist/struct/Song.d.ts.map +1 -0
- package/dist/struct/Song.js +229 -0
- package/dist/struct/Song.js.map +1 -0
- package/dist/struct/TaskQueue.d.ts +33 -0
- package/dist/struct/TaskQueue.d.ts.map +1 -0
- package/dist/struct/TaskQueue.js +58 -0
- package/dist/struct/TaskQueue.js.map +1 -0
- package/dist/struct/index.d.ts +10 -0
- package/dist/struct/index.d.ts.map +1 -0
- package/dist/struct/index.js +22 -0
- package/dist/struct/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/type.d.ts +159 -0
- package/dist/type.d.ts.map +1 -0
- package/dist/type.js +3 -0
- package/dist/type.js.map +1 -0
- package/dist/util.d.ts +47 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +205 -0
- package/dist/util.js.map +1 -0
- package/package.json +50 -24
- package/src/DisTube.js +0 -1121
- package/src/Playlist.js +0 -107
- package/src/Queue.js +0 -120
- package/src/SearchResult.js +0 -81
- package/src/Song.js +0 -135
- package/src/duration.js +0 -39
- package/typings/DisTube.d.ts +0 -635
- package/typings/Playlist.d.ts +0 -73
- package/typings/Queue.d.ts +0 -106
- package/typings/SearchResult.d.ts +0 -59
- package/typings/Song.d.ts +0 -104
- package/typings/duration.d.ts +0 -2
package/src/Playlist.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/* eslint no-unused-vars: "off" */
|
|
2
|
-
const { formatDuration } = require("./duration"),
|
|
3
|
-
Discord = require("discord.js"),
|
|
4
|
-
Song = require("./Song"),
|
|
5
|
-
ytpl = require("@distube/ytpl");
|
|
6
|
-
|
|
7
|
-
const deprecate = (obj, oldProp, value, newProp = null) => {
|
|
8
|
-
Object.defineProperty(obj, oldProp, {
|
|
9
|
-
get: () => {
|
|
10
|
-
if (newProp) console.warn(`\`playlist.${oldProp}\` will be removed in the next major release, use \`playlist.${newProp}\` instead.`);
|
|
11
|
-
else console.warn(`\`playlist.${oldProp}\` will be removed completely in the next major release.`);
|
|
12
|
-
return value;
|
|
13
|
-
},
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const deprecateProps = {
|
|
18
|
-
title: "name",
|
|
19
|
-
items: "songs",
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/** Class representing a playlist. */
|
|
23
|
-
class Playlist {
|
|
24
|
-
/**
|
|
25
|
-
* Create a playlist
|
|
26
|
-
* @param {ytpl.result|Song[]} playlist Playlist
|
|
27
|
-
* @param {Discord.User} user Requested user
|
|
28
|
-
* @param {Object} properties Custom properties
|
|
29
|
-
*/
|
|
30
|
-
constructor(playlist, user, properties = {}) {
|
|
31
|
-
/**
|
|
32
|
-
* User requested.
|
|
33
|
-
* @type {Discord.User}
|
|
34
|
-
*/
|
|
35
|
-
this.user = user || playlist.user;
|
|
36
|
-
/**
|
|
37
|
-
* Playlist songs.
|
|
38
|
-
* @type {Song[]}
|
|
39
|
-
*/
|
|
40
|
-
this.songs = Array.isArray(playlist) ? playlist : playlist.items;
|
|
41
|
-
if (!Array.isArray(this.songs) || !this.songs.length) throw new Error("Playlist is empty!");
|
|
42
|
-
/**
|
|
43
|
-
* Playlist name.
|
|
44
|
-
* @type {string}
|
|
45
|
-
*/
|
|
46
|
-
this.name = playlist.name || playlist.title || this.songs[0].playlist_title || `${this.songs[0].name} and ${this.songs.length - 1} more songs.`;
|
|
47
|
-
/**
|
|
48
|
-
* Playlist URL.
|
|
49
|
-
* @type {string}
|
|
50
|
-
*/
|
|
51
|
-
this.url = playlist.url;
|
|
52
|
-
/**
|
|
53
|
-
* Playlist thumbnail.
|
|
54
|
-
* @type {string}
|
|
55
|
-
*/
|
|
56
|
-
this.thumbnail = playlist.thumbnail || this.songs[0].thumbnail;
|
|
57
|
-
for (let [key, value] of Object.entries(properties)) this[key] = value;
|
|
58
|
-
|
|
59
|
-
// Old version compatible
|
|
60
|
-
/**
|
|
61
|
-
* @deprecated use `Playlist.name` instead
|
|
62
|
-
* @type {string}
|
|
63
|
-
*/
|
|
64
|
-
this.title = "";
|
|
65
|
-
/**
|
|
66
|
-
* @deprecated use `Playlist.songs` instead
|
|
67
|
-
* @type {Song[]}
|
|
68
|
-
*/
|
|
69
|
-
this.items = [];
|
|
70
|
-
/**
|
|
71
|
-
* @deprecated use `Playlist.songs.length` instead
|
|
72
|
-
* @type {number}
|
|
73
|
-
*/
|
|
74
|
-
this.total_items = this.songs.length || 0;
|
|
75
|
-
/**
|
|
76
|
-
* @deprecated
|
|
77
|
-
* @type {string}
|
|
78
|
-
*/
|
|
79
|
-
this.id = playlist.id || "";
|
|
80
|
-
/**
|
|
81
|
-
* @deprecated
|
|
82
|
-
* @type {object}
|
|
83
|
-
*/
|
|
84
|
-
this.author = playlist.author || {};
|
|
85
|
-
for (let [oldProp, newProp] of Object.entries(deprecateProps)) deprecate(this, oldProp, this[newProp], newProp);
|
|
86
|
-
for (let prop of ["id", "author", "total_items"]) deprecate(this, prop, this[prop]);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Playlist duration in second.
|
|
91
|
-
* @type {number}
|
|
92
|
-
*/
|
|
93
|
-
get duration() {
|
|
94
|
-
if (!this.songs[0]) return 0;
|
|
95
|
-
return this.songs.reduce((prev, next) => prev + next.duration, 0)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Formatted duration string `hh:mm:ss`.
|
|
100
|
-
* @type {string}
|
|
101
|
-
*/
|
|
102
|
-
get formattedDuration() {
|
|
103
|
-
return formatDuration(this.duration * 1000)
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
module.exports = Playlist;
|
package/src/Queue.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/* eslint no-unused-vars: "off" */
|
|
2
|
-
const { formatDuration } = require("./duration"),
|
|
3
|
-
Discord = require("discord.js"),
|
|
4
|
-
Song = require("./Song"),
|
|
5
|
-
DisTube = require("./DisTube");
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Represents a queue.
|
|
9
|
-
*/
|
|
10
|
-
class Queue {
|
|
11
|
-
/**
|
|
12
|
-
* Create a queue.
|
|
13
|
-
* @param {Discord.Message} message Discord.Message
|
|
14
|
-
* @param {Song} song The first Song of the Queue
|
|
15
|
-
*/
|
|
16
|
-
constructor(message, song) {
|
|
17
|
-
/**
|
|
18
|
-
* Stream dispatcher.
|
|
19
|
-
* @type {Discord.StreamDispatcher}
|
|
20
|
-
*/
|
|
21
|
-
this.dispatcher = null;
|
|
22
|
-
/**
|
|
23
|
-
* Voice connection.
|
|
24
|
-
* @type {Discord.VoiceConnection}
|
|
25
|
-
*/
|
|
26
|
-
this.connection = null;
|
|
27
|
-
/**
|
|
28
|
-
* Stream volume.
|
|
29
|
-
* @type {number}
|
|
30
|
-
*/
|
|
31
|
-
this.volume = 50;
|
|
32
|
-
/**
|
|
33
|
-
* List of songs
|
|
34
|
-
* @type {Song[]}
|
|
35
|
-
*/
|
|
36
|
-
this.songs = [song];
|
|
37
|
-
/**
|
|
38
|
-
* Whether stream is currently stopped.
|
|
39
|
-
* @type {boolean}
|
|
40
|
-
*/
|
|
41
|
-
this.stopped = false;
|
|
42
|
-
/**
|
|
43
|
-
* Whether or not the last song was skipped.
|
|
44
|
-
* @type {boolean}
|
|
45
|
-
*/
|
|
46
|
-
this.skipped = false;
|
|
47
|
-
/**
|
|
48
|
-
* Whether or not the stream is currently playing.
|
|
49
|
-
* @type {boolean}
|
|
50
|
-
*/
|
|
51
|
-
this.playing = true;
|
|
52
|
-
/**
|
|
53
|
-
* Whether or not the stream is currently paused.
|
|
54
|
-
* @type {boolean}
|
|
55
|
-
*/
|
|
56
|
-
this.pause = false;
|
|
57
|
-
/**
|
|
58
|
-
* Type of repeat mode (0 is disabled, 1 is repeating a song, 2 is repeating all the playlist)
|
|
59
|
-
* @type {number}
|
|
60
|
-
*/
|
|
61
|
-
this.repeatMode = 0;
|
|
62
|
-
/**
|
|
63
|
-
* Whether or not the autoplay mode is enabled.
|
|
64
|
-
* @type {boolean}
|
|
65
|
-
*/
|
|
66
|
-
this.autoplay = true;
|
|
67
|
-
/**
|
|
68
|
-
* `@2.0.0` Queue audio filter.
|
|
69
|
-
* Available filters: {@link Filter}
|
|
70
|
-
* @type {DisTube.Filter}
|
|
71
|
-
*/
|
|
72
|
-
this.filter = null;
|
|
73
|
-
/**
|
|
74
|
-
* `@2.2.0` Message which initialize the queue
|
|
75
|
-
* @type {Discord.Message}
|
|
76
|
-
*/
|
|
77
|
-
this.initMessage = message;
|
|
78
|
-
/**
|
|
79
|
-
* `@2.5.0` ytdl stream
|
|
80
|
-
* @type {Readable}
|
|
81
|
-
*/
|
|
82
|
-
this.stream = null;
|
|
83
|
-
/**
|
|
84
|
-
* `@2.7.0` What time in the song to begin (in milliseconds).
|
|
85
|
-
* @type {number}
|
|
86
|
-
*/
|
|
87
|
-
this.beginTime = 0;
|
|
88
|
-
this.previousSongs = [];
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Formatted duration string.
|
|
92
|
-
* @type {string}
|
|
93
|
-
*/
|
|
94
|
-
get formattedDuration() {
|
|
95
|
-
return formatDuration(this.duration * 1000)
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Queue's duration.
|
|
99
|
-
* @type {number}
|
|
100
|
-
*/
|
|
101
|
-
get duration() {
|
|
102
|
-
return this.songs.reduce((prev, next) => prev + next.duration, 0)
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* `@2.7.0` What time in the song is playing (in milliseconds).
|
|
106
|
-
* @type {number}
|
|
107
|
-
*/
|
|
108
|
-
get currentTime() {
|
|
109
|
-
return this.dispatcher.streamTime + this.beginTime;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* `@2.8.0` Formatted {@link Queue#currentTime} string.
|
|
113
|
-
* @type {string}
|
|
114
|
-
*/
|
|
115
|
-
get formattedCurrentTime() {
|
|
116
|
-
return formatDuration(this.currentTime);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
module.exports = Queue;
|
package/src/SearchResult.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/* eslint no-unused-vars: "off" */
|
|
2
|
-
const { toSecond } = require("./duration"),
|
|
3
|
-
ytsr = require("@distube/ytsr");
|
|
4
|
-
|
|
5
|
-
const deprecate = (obj, oldProp, value, newProp = null) => {
|
|
6
|
-
Object.defineProperty(obj, oldProp, {
|
|
7
|
-
get: () => {
|
|
8
|
-
if (newProp) console.warn(`\`${obj.constructor.name}.${oldProp}\` will be removed in the next major release, use \`${obj.constructor.name}.${newProp}\` instead.`);
|
|
9
|
-
else console.warn(`\`${obj.constructor.name}.${oldProp}\` will be removed completely in the next major release.`)
|
|
10
|
-
return value;
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const deprecateProps = {
|
|
16
|
-
title: "name",
|
|
17
|
-
link: "url",
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/** `@2.7.0` Class representing a search result. */
|
|
21
|
-
class SearchResult {
|
|
22
|
-
/**
|
|
23
|
-
* Create a search result.
|
|
24
|
-
* @param {ytsr.Video} info Video info
|
|
25
|
-
*/
|
|
26
|
-
constructor(info) {
|
|
27
|
-
/**
|
|
28
|
-
* Youtube video id
|
|
29
|
-
* @type {string}
|
|
30
|
-
*/
|
|
31
|
-
this.id = info.id;
|
|
32
|
-
/**
|
|
33
|
-
* Song name aka video title.
|
|
34
|
-
* @type {string}
|
|
35
|
-
*/
|
|
36
|
-
this.name = info.name;
|
|
37
|
-
/**
|
|
38
|
-
* Song duration.
|
|
39
|
-
* @type {number}
|
|
40
|
-
*/
|
|
41
|
-
this.duration = toSecond(info.duration) || 0;
|
|
42
|
-
/**
|
|
43
|
-
* Formatted duration string `hh:mm:ss` or `mm:ss`.
|
|
44
|
-
* @type {string}
|
|
45
|
-
*/
|
|
46
|
-
this.formattedDuration = info.duration;
|
|
47
|
-
/**
|
|
48
|
-
* Song URL.
|
|
49
|
-
* @type {string}
|
|
50
|
-
*/
|
|
51
|
-
this.url = info.url;
|
|
52
|
-
/**
|
|
53
|
-
* Song thumbnail.
|
|
54
|
-
* @type {string}
|
|
55
|
-
*/
|
|
56
|
-
this.thumbnail = info.thumbnail;
|
|
57
|
-
/**
|
|
58
|
-
* Indicates if the video is an active live.
|
|
59
|
-
* @type {boolean}
|
|
60
|
-
*/
|
|
61
|
-
this.isLive = info.isLive;
|
|
62
|
-
/**
|
|
63
|
-
* Song views count
|
|
64
|
-
* @type {number}
|
|
65
|
-
*/
|
|
66
|
-
this.views = info.views;
|
|
67
|
-
/**
|
|
68
|
-
* @deprecated use `Song.name` instead
|
|
69
|
-
* @type {string}
|
|
70
|
-
*/
|
|
71
|
-
this.title = "";
|
|
72
|
-
/**
|
|
73
|
-
* @deprecated use `Song.url` instead
|
|
74
|
-
* @type {string}
|
|
75
|
-
*/
|
|
76
|
-
this.link = "";
|
|
77
|
-
for (let [oldProp, newProp] of Object.entries(deprecateProps)) deprecate(this, oldProp, this[newProp], newProp);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
module.exports = SearchResult;
|
package/src/Song.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/* eslint-disable complexity */
|
|
2
|
-
/* eslint no-unused-vars: "off" */
|
|
3
|
-
const { formatDuration, toSecond } = require("./duration"),
|
|
4
|
-
Discord = require("discord.js"),
|
|
5
|
-
ytdl = require("ytdl-core");
|
|
6
|
-
|
|
7
|
-
const deprecate = (obj, oldProp, value, newProp = null) => {
|
|
8
|
-
Object.defineProperty(obj, oldProp, {
|
|
9
|
-
get: () => {
|
|
10
|
-
if (newProp) console.warn(`\`${obj.constructor.name}.${oldProp}\` will be removed in the next major release, use \`${obj.constructor.name}.${newProp}\` instead.`);
|
|
11
|
-
else console.warn(`\`${obj.constructor.name}.${oldProp}\` will be removed completely in the next major release.`)
|
|
12
|
-
return value;
|
|
13
|
-
},
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const deprecateProps = {
|
|
18
|
-
title: "name",
|
|
19
|
-
link: "url",
|
|
20
|
-
plays: "views",
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const parseNumber = string => (typeof string === "string" ? Number(string.replace(/\D+/g, "")) : Number(string)) || 0;
|
|
24
|
-
|
|
25
|
-
/** Class representing a song. */
|
|
26
|
-
class Song {
|
|
27
|
-
/**
|
|
28
|
-
* Create a song.
|
|
29
|
-
* @param {ytdl.videoInfo|Object} info Video info
|
|
30
|
-
* @param {Discord.User} user Requested user
|
|
31
|
-
* @param {boolean} [youtube=false] Weather or not the video is a Youtube video.
|
|
32
|
-
*/
|
|
33
|
-
constructor(info, user, youtube = false) {
|
|
34
|
-
/**
|
|
35
|
-
* `@2.6.0` Weather or not the video is a Youtube video.
|
|
36
|
-
* @type {boolean}
|
|
37
|
-
*/
|
|
38
|
-
this.youtube = info.youtube || youtube;
|
|
39
|
-
if (this.youtube && info.full) {
|
|
40
|
-
this.info = info;
|
|
41
|
-
info = info.videoDetails;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* User requested
|
|
45
|
-
* @type {Discord.User}
|
|
46
|
-
*/
|
|
47
|
-
this.user = user;
|
|
48
|
-
/**
|
|
49
|
-
* `@2.1.4` Youtube video id
|
|
50
|
-
* @type {string}
|
|
51
|
-
*/
|
|
52
|
-
this.id = info.videoId || info.id;
|
|
53
|
-
/**
|
|
54
|
-
* Song name aka video title.
|
|
55
|
-
* @type {string}
|
|
56
|
-
*/
|
|
57
|
-
this.name = info.title;
|
|
58
|
-
/**
|
|
59
|
-
* `@2.5.0` Indicates if the video is an active live.
|
|
60
|
-
* @type {boolean}
|
|
61
|
-
*/
|
|
62
|
-
this.isLive = info.isLive || info.is_live || false;
|
|
63
|
-
/**
|
|
64
|
-
* Song duration.
|
|
65
|
-
* @type {number}
|
|
66
|
-
*/
|
|
67
|
-
this.duration = toSecond(Number(info.lengthSeconds) || info._duration_raw || info.duration) || 0;
|
|
68
|
-
/**
|
|
69
|
-
* Formatted duration string `hh:mm:ss` or `mm:ss`.
|
|
70
|
-
* @type {string}
|
|
71
|
-
*/
|
|
72
|
-
this.formattedDuration = this.isLive ? "Live" : formatDuration(this.duration * 1000)
|
|
73
|
-
/**
|
|
74
|
-
* Song URL.
|
|
75
|
-
* @type {string}
|
|
76
|
-
*/
|
|
77
|
-
this.url = this.youtube ? `https://www.youtube.com/watch?v=${this.id}` : info.webpage_url;
|
|
78
|
-
/**
|
|
79
|
-
* `@2.6.0` Stream / Download URL.
|
|
80
|
-
* @type {?string}
|
|
81
|
-
*/
|
|
82
|
-
this.streamURL = this.info && this.info.formats.length ? ytdl.chooseFormat(this.info.formats, {
|
|
83
|
-
filter: this.isLive ? "audioandvideo" : "audioonly",
|
|
84
|
-
quality: "highestaudio",
|
|
85
|
-
}).url : info.url;
|
|
86
|
-
/**
|
|
87
|
-
* Song thumbnail.
|
|
88
|
-
* @type {?string}
|
|
89
|
-
*/
|
|
90
|
-
this.thumbnail = info.thumbnails ? info.thumbnails.sort((a, b) => b.width - a.width)[0].url : info.thumbnail || null;
|
|
91
|
-
/**
|
|
92
|
-
* Related videos (Only available with YouTube video)
|
|
93
|
-
* @type {?ytdl.relatedVideo[]}
|
|
94
|
-
*/
|
|
95
|
-
this.related = info.related_videos;
|
|
96
|
-
/**
|
|
97
|
-
* `@2.6.0` Song views count
|
|
98
|
-
* @type {number}
|
|
99
|
-
*/
|
|
100
|
-
this.views = parseNumber(info.viewCount || info.view_count || info.views);
|
|
101
|
-
/**
|
|
102
|
-
* @deprecated use `Song.views` instead
|
|
103
|
-
* @type {number}
|
|
104
|
-
*/
|
|
105
|
-
this.plays = this.views;
|
|
106
|
-
/**
|
|
107
|
-
* `@2.6.0` Song like count
|
|
108
|
-
* @type {number}
|
|
109
|
-
*/
|
|
110
|
-
this.likes = parseNumber(info.likes || info.like_count);
|
|
111
|
-
/**
|
|
112
|
-
* `@2.6.0` Song dislike count
|
|
113
|
-
* @type {number}
|
|
114
|
-
*/
|
|
115
|
-
this.dislikes = parseNumber(info.dislikes || info.dislike_count);
|
|
116
|
-
/**
|
|
117
|
-
* `@2.6.0` Song repost count
|
|
118
|
-
* @type {number}
|
|
119
|
-
*/
|
|
120
|
-
this.reposts = parseNumber(info.repost_count);
|
|
121
|
-
/**
|
|
122
|
-
* @deprecated use `Song.name` instead
|
|
123
|
-
* @type {string}
|
|
124
|
-
*/
|
|
125
|
-
this.title = "";
|
|
126
|
-
/**
|
|
127
|
-
* @deprecated use `Song.url` instead
|
|
128
|
-
* @type {string}
|
|
129
|
-
*/
|
|
130
|
-
this.link = "";
|
|
131
|
-
for (let [oldProp, newProp] of Object.entries(deprecateProps)) deprecate(this, oldProp, this[newProp], newProp);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
module.exports = Song;
|
package/src/duration.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
const formatInt = int => {
|
|
2
|
-
if (int < 10) return `0${int}`;
|
|
3
|
-
return `${int}`;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
module.exports.formatDuration = milliseconds => {
|
|
7
|
-
if (!milliseconds || !parseInt(milliseconds)) return "00:00";
|
|
8
|
-
const seconds = Math.floor(milliseconds % 60000 / 1000);
|
|
9
|
-
const minutes = Math.floor(milliseconds % 3600000 / 60000);
|
|
10
|
-
const hours = Math.floor(milliseconds / 3600000);
|
|
11
|
-
if (hours > 0) {
|
|
12
|
-
return `${formatInt(hours)}:${formatInt(minutes)}:${formatInt(seconds)}`;
|
|
13
|
-
}
|
|
14
|
-
if (minutes > 0) {
|
|
15
|
-
return `${formatInt(minutes)}:${formatInt(seconds)}`;
|
|
16
|
-
}
|
|
17
|
-
return `00:${formatInt(seconds)}`;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
module.exports.toSecond = string => {
|
|
21
|
-
if (!string) return 0;
|
|
22
|
-
if (typeof string !== "string") return parseInt(string);
|
|
23
|
-
let h = 0,
|
|
24
|
-
m = 0,
|
|
25
|
-
s = 0;
|
|
26
|
-
if (string.match(/:/g)) {
|
|
27
|
-
let time = string.split(":");
|
|
28
|
-
if (time.length === 2) {
|
|
29
|
-
m = parseInt(time[0], 10);
|
|
30
|
-
s = parseInt(time[1], 10);
|
|
31
|
-
} else if (time.length === 3) {
|
|
32
|
-
h = parseInt(time[0], 10);
|
|
33
|
-
m = parseInt(time[1], 10);
|
|
34
|
-
s = parseInt(time[2], 10);
|
|
35
|
-
}
|
|
36
|
-
} else s = parseInt(string, 10);
|
|
37
|
-
// eslint-disable-next-line no-mixed-operators
|
|
38
|
-
return h * 60 * 60 + m * 60 + s;
|
|
39
|
-
};
|