distube 4.0.0-dev.1 → 4.0.0-dev.2
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/dist/DisTube.d.ts +13 -480
- package/dist/DisTube.d.ts.map +1 -1
- package/dist/DisTube.js +30 -544
- package/dist/DisTube.js.map +1 -1
- package/dist/constant.d.ts +0 -97
- package/dist/constant.d.ts.map +1 -1
- package/dist/constant.js +0 -97
- package/dist/constant.js.map +1 -1
- package/dist/core/DisTubeBase.d.ts +0 -40
- package/dist/core/DisTubeBase.d.ts.map +1 -1
- package/dist/core/DisTubeBase.js +0 -44
- package/dist/core/DisTubeBase.js.map +1 -1
- package/dist/core/DisTubeHandler.d.ts +2 -68
- package/dist/core/DisTubeHandler.d.ts.map +1 -1
- package/dist/core/DisTubeHandler.js +6 -68
- package/dist/core/DisTubeHandler.js.map +1 -1
- package/dist/core/DisTubeStream.d.ts +0 -33
- package/dist/core/DisTubeStream.d.ts.map +1 -1
- package/dist/core/DisTubeStream.js +0 -36
- package/dist/core/DisTubeStream.js.map +1 -1
- package/dist/core/manager/BaseManager.d.ts +1 -16
- package/dist/core/manager/BaseManager.d.ts.map +1 -1
- package/dist/core/manager/BaseManager.js +2 -28
- package/dist/core/manager/BaseManager.js.map +1 -1
- package/dist/core/manager/FilterManager.d.ts +16 -0
- package/dist/core/manager/FilterManager.d.ts.map +1 -0
- package/dist/core/manager/FilterManager.js +88 -0
- package/dist/core/manager/FilterManager.js.map +1 -0
- package/dist/core/manager/GuildIdManager.d.ts +9 -0
- package/dist/core/manager/GuildIdManager.d.ts.map +1 -0
- package/dist/core/manager/GuildIdManager.js +25 -0
- package/dist/core/manager/GuildIdManager.js.map +1 -0
- package/dist/core/manager/QueueManager.d.ts +4 -26
- package/dist/core/manager/QueueManager.d.ts.map +1 -1
- package/dist/core/manager/QueueManager.js +27 -48
- package/dist/core/manager/QueueManager.js.map +1 -1
- package/dist/core/manager/index.d.ts +2 -0
- package/dist/core/manager/index.d.ts.map +1 -1
- package/dist/core/manager/index.js +2 -0
- package/dist/core/manager/index.js.map +1 -1
- package/dist/core/voice/DisTubeVoice.d.ts +0 -50
- package/dist/core/voice/DisTubeVoice.d.ts.map +1 -1
- package/dist/core/voice/DisTubeVoice.js +8 -68
- package/dist/core/voice/DisTubeVoice.js.map +1 -1
- package/dist/core/voice/DisTubeVoiceManager.d.ts +2 -33
- package/dist/core/voice/DisTubeVoiceManager.d.ts.map +1 -1
- package/dist/core/voice/DisTubeVoiceManager.js +1 -32
- package/dist/core/voice/DisTubeVoiceManager.js.map +1 -1
- package/dist/struct/CustomPlugin.d.ts +0 -41
- package/dist/struct/CustomPlugin.d.ts.map +1 -1
- package/dist/struct/CustomPlugin.js +0 -34
- package/dist/struct/CustomPlugin.js.map +1 -1
- package/dist/struct/ExtractorPlugin.d.ts +0 -32
- package/dist/struct/ExtractorPlugin.d.ts.map +1 -1
- package/dist/struct/ExtractorPlugin.js +0 -23
- package/dist/struct/ExtractorPlugin.js.map +1 -1
- package/dist/struct/Playlist.d.ts +0 -29
- package/dist/struct/Playlist.d.ts.map +1 -1
- package/dist/struct/Playlist.js +0 -54
- package/dist/struct/Playlist.js.map +1 -1
- package/dist/struct/Plugin.d.ts +0 -58
- package/dist/struct/Plugin.d.ts.map +1 -1
- package/dist/struct/Plugin.js +0 -62
- package/dist/struct/Plugin.js.map +1 -1
- package/dist/struct/Queue.d.ts +10 -177
- package/dist/struct/Queue.d.ts.map +1 -1
- package/dist/struct/Queue.js +49 -256
- package/dist/struct/Queue.js.map +1 -1
- package/dist/struct/SearchResult.d.ts +0 -8
- package/dist/struct/SearchResult.d.ts.map +1 -1
- package/dist/struct/SearchResult.js +0 -47
- package/dist/struct/SearchResult.js.map +1 -1
- package/dist/struct/Song.d.ts +0 -35
- package/dist/struct/Song.d.ts.map +1 -1
- package/dist/struct/Song.js +0 -121
- package/dist/struct/Song.js.map +1 -1
- package/dist/struct/TaskQueue.d.ts +0 -20
- package/dist/struct/TaskQueue.d.ts.map +1 -1
- package/dist/struct/TaskQueue.js +0 -25
- package/dist/struct/TaskQueue.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/type.d.ts +6 -71
- package/dist/type.d.ts.map +1 -1
- package/dist/type.js.map +1 -1
- package/dist/util.d.ts +0 -29
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +2 -38
- package/dist/util.js.map +1 -1
- package/package.json +13 -4
|
@@ -2,71 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SearchResult = void 0;
|
|
4
4
|
const __1 = require("..");
|
|
5
|
-
/** Class representing a search result. */
|
|
6
5
|
class SearchResult {
|
|
7
|
-
/**
|
|
8
|
-
* Create a search result
|
|
9
|
-
* @param {Object} info ytsr result
|
|
10
|
-
*/
|
|
11
6
|
constructor(info) {
|
|
12
7
|
this.source = "youtube";
|
|
13
|
-
/**
|
|
14
|
-
* Type of SearchResult (`video` or `playlist`)
|
|
15
|
-
* @type {string}
|
|
16
|
-
*/
|
|
17
8
|
this.type = info.type;
|
|
18
|
-
/**
|
|
19
|
-
* YouTube video or playlist id
|
|
20
|
-
* @type {string}
|
|
21
|
-
*/
|
|
22
9
|
this.id = info.id;
|
|
23
|
-
/**
|
|
24
|
-
* Video or playlist title.
|
|
25
|
-
* @type {string}
|
|
26
|
-
*/
|
|
27
10
|
this.name = info.name;
|
|
28
|
-
/**
|
|
29
|
-
* Video or playlist URL.
|
|
30
|
-
* @type {string}
|
|
31
|
-
*/
|
|
32
11
|
this.url = info.url;
|
|
33
12
|
if (this.type === "video") {
|
|
34
13
|
info = info;
|
|
35
|
-
/**
|
|
36
|
-
* [Video only] Video or playlist views count
|
|
37
|
-
* @type {number}
|
|
38
|
-
*/
|
|
39
14
|
this.views = info.views;
|
|
40
|
-
/**
|
|
41
|
-
* [Video only] Indicates if the video is an active live.
|
|
42
|
-
* @type {boolean?}
|
|
43
|
-
*/
|
|
44
15
|
this.isLive = info.isLive;
|
|
45
|
-
/**
|
|
46
|
-
* [Video only] Video duration.
|
|
47
|
-
* @type {number}
|
|
48
|
-
*/
|
|
49
16
|
this.duration = this.isLive ? 0 : (0, __1.toSecond)(info.duration);
|
|
50
|
-
/**
|
|
51
|
-
* [Video only] Formatted duration string `hh:mm:ss` or `mm:ss`.
|
|
52
|
-
* @type {string}
|
|
53
|
-
*/
|
|
54
17
|
this.formattedDuration = this.isLive ? "Live" : (0, __1.formatDuration)(this.duration);
|
|
55
|
-
/**
|
|
56
|
-
* [Video only] Video thumbnail.
|
|
57
|
-
* @type {string?}
|
|
58
|
-
*/
|
|
59
18
|
this.thumbnail = info.thumbnail;
|
|
60
19
|
}
|
|
61
20
|
else if (this.type !== "playlist") {
|
|
62
21
|
throw new __1.DisTubeError("INVALID_TYPE", ["video", "playlist"], this.type, "SearchResult.type");
|
|
63
22
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Song uploader
|
|
66
|
-
* @type {Object}
|
|
67
|
-
* @prop {string?} name Uploader name
|
|
68
|
-
* @prop {string?} url Uploader url
|
|
69
|
-
*/
|
|
70
23
|
this.uploader = {
|
|
71
24
|
name: (info.author || info.owner)?.name,
|
|
72
25
|
url: (info.author || info.owner)?.url,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchResult.js","sourceRoot":"","sources":["../../src/struct/SearchResult.ts"],"names":[],"mappings":";;;AAAA,0BAA4D;
|
|
1
|
+
{"version":3,"file":"SearchResult.js","sourceRoot":"","sources":["../../src/struct/SearchResult.ts"],"names":[],"mappings":";;;AAAA,0BAA4D;AAI5D,MAAa,YAAY;IAsBvB,YAAY,IAAsB;QAChC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QAKxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QAKtB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QAKlB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QAKtB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACpB,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE;YACzB,IAAI,GAAG,IAAa,CAAC;YAKrB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;YAKxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;YAK1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAA,YAAQ,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAK1D,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAA,kBAAc,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAK9E,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;SACjC;aAAM,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE;YACnC,MAAM,IAAI,gBAAY,CAAC,cAAc,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;SAC/F;QAOD,IAAI,CAAC,QAAQ,GAAG;YACd,IAAI,EAAE,CAAE,IAAc,CAAC,MAAM,IAAK,IAAiB,CAAC,KAAK,CAAC,EAAE,IAAI;YAChE,GAAG,EAAE,CAAE,IAAc,CAAC,MAAM,IAAK,IAAiB,CAAC,KAAK,CAAC,EAAE,GAAG;SAC/D,CAAC;IACJ,CAAC;CACF;AArFD,oCAqFC","sourcesContent":["import { DisTubeError, formatDuration, toSecond } from \"..\";\nimport type { Playlist, Video } from \"@distube/ytsr\";\n\n/** Class representing a search result. */\nexport class SearchResult {\n source: \"youtube\";\n type: \"video\" | \"playlist\";\n id: string;\n name: string;\n url: string;\n views?: number;\n isLive?: boolean;\n duration?: number;\n formattedDuration?: string;\n thumbnail?: string;\n /** Video or playlist uploader */\n uploader: {\n /** Uploader name */\n name?: string;\n /** Uploader url */\n url?: string;\n };\n /**\n * Create a search result\n * @param {Object} info ytsr result\n */\n constructor(info: Video | Playlist) {\n this.source = \"youtube\";\n /**\n * Type of SearchResult (`video` or `playlist`)\n * @type {string}\n */\n this.type = info.type;\n /**\n * YouTube video or playlist id\n * @type {string}\n */\n this.id = info.id;\n /**\n * Video or playlist title.\n * @type {string}\n */\n this.name = info.name;\n /**\n * Video or playlist URL.\n * @type {string}\n */\n this.url = info.url;\n if (this.type === \"video\") {\n info = info as Video;\n /**\n * [Video only] Video or playlist views count\n * @type {number}\n */\n this.views = info.views;\n /**\n * [Video only] Indicates if the video is an active live.\n * @type {boolean?}\n */\n this.isLive = info.isLive;\n /**\n * [Video only] Video duration.\n * @type {number}\n */\n this.duration = this.isLive ? 0 : toSecond(info.duration);\n /**\n * [Video only] Formatted duration string `hh:mm:ss` or `mm:ss`.\n * @type {string}\n */\n this.formattedDuration = this.isLive ? \"Live\" : formatDuration(this.duration);\n /**\n * [Video only] Video thumbnail.\n * @type {string?}\n */\n this.thumbnail = info.thumbnail;\n } else if (this.type !== \"playlist\") {\n throw new DisTubeError(\"INVALID_TYPE\", [\"video\", \"playlist\"], this.type, \"SearchResult.type\");\n }\n /**\n * Song uploader\n * @type {Object}\n * @prop {string?} name Uploader name\n * @prop {string?} url Uploader url\n */\n this.uploader = {\n name: ((info as Video).author || (info as Playlist).owner)?.name,\n url: ((info as Video).author || (info as Playlist).owner)?.url,\n };\n }\n}\n"]}
|
package/dist/struct/Song.d.ts
CHANGED
|
@@ -2,16 +2,6 @@ import { Playlist } from "./Playlist";
|
|
|
2
2
|
import type ytdl from "@distube/ytdl-core";
|
|
3
3
|
import type { GuildMember } from "discord.js";
|
|
4
4
|
import type { Chapter, OtherSongInfo, RelatedSong, SearchResult } from "..";
|
|
5
|
-
/**
|
|
6
|
-
* Class representing a song.
|
|
7
|
-
*
|
|
8
|
-
* <info>If {@link Song} is added from a YouTube {@link SearchResult} or {@link Playlist},
|
|
9
|
-
* some info will be missing to save your resources. It will be filled when emitting {@link DisTube#playSong} event.
|
|
10
|
-
*
|
|
11
|
-
* Missing info: {@link Song#likes}, {@link Song#dislikes}, {@link Song#streamURL},
|
|
12
|
-
* {@link Song#related}, {@link Song#chapters}, {@link Song#age_restricted}</info>
|
|
13
|
-
* @template T - The type for the metadata (if any) of the song
|
|
14
|
-
*/
|
|
15
5
|
export declare class Song<T = unknown> {
|
|
16
6
|
#private;
|
|
17
7
|
source: string;
|
|
@@ -35,42 +25,17 @@ export declare class Song<T = unknown> {
|
|
|
35
25
|
age_restricted: boolean;
|
|
36
26
|
chapters: Chapter[];
|
|
37
27
|
reposts: number;
|
|
38
|
-
/**
|
|
39
|
-
* Create a Song
|
|
40
|
-
* @param {ytdl.videoInfo|SearchResult|OtherSongInfo} info Raw info
|
|
41
|
-
* @param {Object} [options] Optional options
|
|
42
|
-
* @param {Discord.GuildMember} [options.member] Requested user
|
|
43
|
-
* @param {string} [options.source="youtube"] Song source
|
|
44
|
-
* @param {T} [options.metadata] Song metadata
|
|
45
|
-
*/
|
|
46
28
|
constructor(info: ytdl.videoInfo | SearchResult | OtherSongInfo | ytdl.relatedVideo | RelatedSong, options?: {
|
|
47
29
|
member?: GuildMember;
|
|
48
30
|
source?: string;
|
|
49
31
|
metadata?: T;
|
|
50
32
|
});
|
|
51
33
|
_patchYouTube(i: ytdl.videoInfo | SearchResult): void;
|
|
52
|
-
/**
|
|
53
|
-
* Patch data from other source
|
|
54
|
-
* @param {OtherSongInfo} info Video info
|
|
55
|
-
* @private
|
|
56
|
-
*/
|
|
57
34
|
_patchOther(info: OtherSongInfo): void;
|
|
58
|
-
/**
|
|
59
|
-
* The playlist added this song
|
|
60
|
-
* @type {Playlist?}
|
|
61
|
-
*/
|
|
62
35
|
get playlist(): Playlist | undefined;
|
|
63
36
|
set playlist(playlist: Playlist | undefined);
|
|
64
|
-
/**
|
|
65
|
-
* User requested.
|
|
66
|
-
* @type {Discord.GuildMember?}
|
|
67
|
-
*/
|
|
68
37
|
get member(): GuildMember | undefined;
|
|
69
38
|
set member(member: GuildMember | undefined);
|
|
70
|
-
/**
|
|
71
|
-
* User requested.
|
|
72
|
-
* @type {Discord.User?}
|
|
73
|
-
*/
|
|
74
39
|
get user(): import("discord.js").User | undefined;
|
|
75
40
|
get metadata(): T;
|
|
76
41
|
set metadata(metadata: T);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Song.d.ts","sourceRoot":"","sources":["../../src/struct/Song.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"Song.d.ts","sourceRoot":"","sources":["../../src/struct/Song.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAY5E,qBAAa,IAAI,CAAC,CAAC,GAAG,OAAO;;IAC3B,MAAM,EAAG,MAAM,CAAC;IAEhB,OAAO,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;IAE7B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAG,OAAO,CAAC;IACjB,QAAQ,EAAG,MAAM,CAAC;IAClB,iBAAiB,CAAC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|
const Playlist_1 = require("./Playlist");
|
|
17
17
|
const __1 = require("..");
|
|
18
|
-
/**
|
|
19
|
-
* Class representing a song.
|
|
20
|
-
*
|
|
21
|
-
* <info>If {@link Song} is added from a YouTube {@link SearchResult} or {@link Playlist},
|
|
22
|
-
* some info will be missing to save your resources. It will be filled when emitting {@link DisTube#playSong} event.
|
|
23
|
-
*
|
|
24
|
-
* Missing info: {@link Song#likes}, {@link Song#dislikes}, {@link Song#streamURL},
|
|
25
|
-
* {@link Song#related}, {@link Song#chapters}, {@link Song#age_restricted}</info>
|
|
26
|
-
* @template T - The type for the metadata (if any) of the song
|
|
27
|
-
*/
|
|
28
18
|
class Song {
|
|
29
|
-
/**
|
|
30
|
-
* Create a Song
|
|
31
|
-
* @param {ytdl.videoInfo|SearchResult|OtherSongInfo} info Raw info
|
|
32
|
-
* @param {Object} [options] Optional options
|
|
33
|
-
* @param {Discord.GuildMember} [options.member] Requested user
|
|
34
|
-
* @param {string} [options.source="youtube"] Song source
|
|
35
|
-
* @param {T} [options.metadata] Song metadata
|
|
36
|
-
*/
|
|
37
19
|
constructor(info, options = {}) {
|
|
38
20
|
_Song_metadata.set(this, void 0);
|
|
39
21
|
_Song_member.set(this, void 0);
|
|
@@ -43,15 +25,7 @@ class Song {
|
|
|
43
25
|
(info.src && typeof info.src !== "string")) {
|
|
44
26
|
throw new __1.DisTubeError("INVALID_TYPE", "string", source, "source");
|
|
45
27
|
}
|
|
46
|
-
/**
|
|
47
|
-
* The source of the song
|
|
48
|
-
* @type {string}
|
|
49
|
-
*/
|
|
50
28
|
this.source = (info?.src || source).toLowerCase();
|
|
51
|
-
/**
|
|
52
|
-
* Optional metadata that can be used to identify the song.
|
|
53
|
-
* @type {T}
|
|
54
|
-
*/
|
|
55
29
|
this.metadata = metadata;
|
|
56
30
|
this.member = member;
|
|
57
31
|
if (this.source === "youtube") {
|
|
@@ -62,16 +36,9 @@ class Song {
|
|
|
62
36
|
}
|
|
63
37
|
}
|
|
64
38
|
_patchYouTube(i) {
|
|
65
|
-
// FIXME
|
|
66
39
|
const info = i;
|
|
67
40
|
if (info.full === true) {
|
|
68
|
-
/**
|
|
69
|
-
* Stream formats (Available if the song is from YouTube and playing)
|
|
70
|
-
* @type {ytdl.videoFormat[]?}
|
|
71
|
-
* @private
|
|
72
|
-
*/
|
|
73
41
|
this.formats = info.formats;
|
|
74
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
|
|
75
42
|
const err = require("@distube/ytdl-core/lib/utils").playError(info.player_response, [
|
|
76
43
|
"UNPLAYABLE",
|
|
77
44
|
"LIVE_STREAM_OFFLINE",
|
|
@@ -83,108 +50,32 @@ class Song {
|
|
|
83
50
|
throw new __1.DisTubeError("UNAVAILABLE_VIDEO");
|
|
84
51
|
}
|
|
85
52
|
const details = info.videoDetails || info;
|
|
86
|
-
/**
|
|
87
|
-
* YouTube video id
|
|
88
|
-
* @type {string?}
|
|
89
|
-
*/
|
|
90
53
|
this.id = details.videoId || details.id;
|
|
91
|
-
/**
|
|
92
|
-
* Song name.
|
|
93
|
-
* @type {string?}
|
|
94
|
-
*/
|
|
95
54
|
this.name = details.title || details.name;
|
|
96
|
-
/**
|
|
97
|
-
* Indicates if the video is an active live.
|
|
98
|
-
* @type {boolean}
|
|
99
|
-
*/
|
|
100
55
|
this.isLive = !!details.isLive;
|
|
101
|
-
/**
|
|
102
|
-
* Song duration.
|
|
103
|
-
* @type {number}
|
|
104
|
-
*/
|
|
105
56
|
this.duration = this.isLive ? 0 : (0, __1.toSecond)(details.lengthSeconds || details.length_seconds || details.duration);
|
|
106
|
-
/**
|
|
107
|
-
* Formatted duration string (`hh:mm:ss`, `mm:ss` or `Live`).
|
|
108
|
-
* @type {string?}
|
|
109
|
-
*/
|
|
110
57
|
this.formattedDuration = this.isLive ? "Live" : (0, __1.formatDuration)(this.duration);
|
|
111
|
-
/**
|
|
112
|
-
* Song URL.
|
|
113
|
-
* @type {string}
|
|
114
|
-
*/
|
|
115
58
|
this.url = `https://www.youtube.com/watch?v=${this.id}`;
|
|
116
|
-
/**
|
|
117
|
-
* Stream / Download URL (Available if the song is playing)
|
|
118
|
-
* @type {string?}
|
|
119
|
-
*/
|
|
120
59
|
this.streamURL = undefined;
|
|
121
|
-
/**
|
|
122
|
-
* Song thumbnail.
|
|
123
|
-
* @type {string?}
|
|
124
|
-
*/
|
|
125
60
|
this.thumbnail =
|
|
126
61
|
details.thumbnails?.sort((a, b) => b.width - a.width)?.[0]?.url ||
|
|
127
62
|
details.thumbnail?.url ||
|
|
128
63
|
details.thumbnail;
|
|
129
|
-
/**
|
|
130
|
-
* Related songs (without {@link Song#related} properties)
|
|
131
|
-
* @type {Song[]}
|
|
132
|
-
*/
|
|
133
64
|
this.related = info?.related_videos || details.related || [];
|
|
134
65
|
if (!Array.isArray(this.related))
|
|
135
66
|
throw new __1.DisTubeError("INVALID_TYPE", "Array", this.related, "Song#related");
|
|
136
67
|
this.related = this.related.map((v) => new Song(v, { source: this.source, metadata: this.metadata }));
|
|
137
|
-
/**
|
|
138
|
-
* Song views count
|
|
139
|
-
* @type {number}
|
|
140
|
-
*/
|
|
141
68
|
this.views = (0, __1.parseNumber)(details.viewCount || details.view_count || details.views);
|
|
142
|
-
/**
|
|
143
|
-
* Song like count
|
|
144
|
-
* @type {number}
|
|
145
|
-
*/
|
|
146
69
|
this.likes = (0, __1.parseNumber)(details.likes);
|
|
147
|
-
/**
|
|
148
|
-
* Song dislike count
|
|
149
|
-
* @type {number}
|
|
150
|
-
*/
|
|
151
70
|
this.dislikes = (0, __1.parseNumber)(details.dislikes);
|
|
152
|
-
/**
|
|
153
|
-
* Song uploader
|
|
154
|
-
* @type {Object}
|
|
155
|
-
* @prop {string?} name Uploader name
|
|
156
|
-
* @prop {string?} url Uploader url
|
|
157
|
-
*/
|
|
158
71
|
this.uploader = {
|
|
159
72
|
name: info.uploader?.name || details.author?.name,
|
|
160
73
|
url: info.uploader?.url || details.author?.channel_url || details.author?.url,
|
|
161
74
|
};
|
|
162
|
-
/**
|
|
163
|
-
* Whether or not an age-restricted content
|
|
164
|
-
* @type {boolean}
|
|
165
|
-
*/
|
|
166
75
|
this.age_restricted = !!details.age_restricted;
|
|
167
|
-
/**
|
|
168
|
-
* @typedef {Object} Chapter
|
|
169
|
-
* @prop {string} title Chapter title
|
|
170
|
-
* @prop {number} start_time Chapter start time in seconds
|
|
171
|
-
*/
|
|
172
|
-
/**
|
|
173
|
-
* Chapters information (YouTube only)
|
|
174
|
-
* @type {Chapter[]}
|
|
175
|
-
*/
|
|
176
76
|
this.chapters = details.chapters || [];
|
|
177
|
-
/**
|
|
178
|
-
* Song repost count
|
|
179
|
-
* @type {number}
|
|
180
|
-
*/
|
|
181
77
|
this.reposts = 0;
|
|
182
78
|
}
|
|
183
|
-
/**
|
|
184
|
-
* Patch data from other source
|
|
185
|
-
* @param {OtherSongInfo} info Video info
|
|
186
|
-
* @private
|
|
187
|
-
*/
|
|
188
79
|
_patchOther(info) {
|
|
189
80
|
this.id = info.id;
|
|
190
81
|
this.name = info.title || info.name;
|
|
@@ -216,10 +107,6 @@ class Song {
|
|
|
216
107
|
this.age_restricted = info.age_restricted || (!!info.age_limit && (0, __1.parseNumber)(info.age_limit) >= 18);
|
|
217
108
|
this.chapters = info.chapters || [];
|
|
218
109
|
}
|
|
219
|
-
/**
|
|
220
|
-
* The playlist added this song
|
|
221
|
-
* @type {Playlist?}
|
|
222
|
-
*/
|
|
223
110
|
get playlist() {
|
|
224
111
|
return __classPrivateFieldGet(this, _Song_playlist, "f");
|
|
225
112
|
}
|
|
@@ -229,10 +116,6 @@ class Song {
|
|
|
229
116
|
__classPrivateFieldSet(this, _Song_playlist, playlist, "f");
|
|
230
117
|
this.member = playlist.member;
|
|
231
118
|
}
|
|
232
|
-
/**
|
|
233
|
-
* User requested.
|
|
234
|
-
* @type {Discord.GuildMember?}
|
|
235
|
-
*/
|
|
236
119
|
get member() {
|
|
237
120
|
return __classPrivateFieldGet(this, _Song_member, "f");
|
|
238
121
|
}
|
|
@@ -240,10 +123,6 @@ class Song {
|
|
|
240
123
|
if ((0, __1.isMemberInstance)(member))
|
|
241
124
|
__classPrivateFieldSet(this, _Song_member, member, "f");
|
|
242
125
|
}
|
|
243
|
-
/**
|
|
244
|
-
* User requested.
|
|
245
|
-
* @type {Discord.User?}
|
|
246
|
-
*/
|
|
247
126
|
get user() {
|
|
248
127
|
return this.member?.user;
|
|
249
128
|
}
|
package/dist/struct/Song.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Song.js","sourceRoot":"","sources":["../../src/struct/Song.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,yCAAsC;AACtC,0BAA2F;AAK3F;;;;;;;;;GASG;AACH,MAAa,IAAI;IAyBf;;;;;;;OAOG;IACH,YACE,IAAqF,EACrF,UAII,EAAE;QArCR,iCAAc;QAEd,+BAAsB;QAoBtB,iCAAqB;QAiBnB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,EAAE,CAAC;QAEvE,IACE,OAAO,MAAM,KAAK,QAAQ;YAC1B,CAAE,IAAsB,CAAC,GAAG,IAAI,OAAQ,IAAsB,CAAC,GAAG,KAAK,QAAQ,CAAC,EAChF;YACA,MAAM,IAAI,gBAAY,CAAC,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;SACpE;QACD;;;WAGG;QACH,IAAI,CAAC,MAAM,GAAG,CAAE,IAAsB,EAAE,GAAG,IAAI,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;QACrE;;;WAGG;QACH,IAAI,CAAC,QAAQ,GAAG,QAAa,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE;YAC7B,IAAI,CAAC,aAAa,CAAC,IAAsB,CAAC,CAAC;SAC5C;aA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C,cAAc,GAAG,IAAI,CAAC,cAAc,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,IAAA,eAAW,EAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;QACrG,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,IAAI,QAAQ;QACV,OAAO,uBAAA,IAAI,sBAAU,CAAC;IACxB,CAAC;IAED,IAAI,QAAQ,CAAC,QAA8B;QACzC,IAAI,CAAC,CAAC,QAAQ,YAAY,mBAAQ,CAAC;YAAE,MAAM,IAAI,gBAAY,CAAC,cAAc,EAAE,UAAU,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;QACnH,uBAAA,IAAI,kBAAa,QAAQ,MAAA,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;IAChC,CAAC;IAED;;;OAGG;IACH,IAAI,MAAM;QACR,OAAO,uBAAA,IAAI,oBAAQ,CAAC;IACtB,CAAC;IAED,IAAI,MAAM,CAAC,MAA+B;QACxC,IAAI,IAAA,oBAAgB,EAAC,MAAM,CAAC;YAAE,uBAAA,IAAI,gBAAW,MAAM,MAAA,CAAC;IACtD,CAAC;IAED;;;OAGG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC;IAC3B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,uBAAA,IAAI,sBAAU,CAAC;IACxB,CAAC;IAED,IAAI,QAAQ,CAAC,QAAW;QACtB,uBAAA,IAAI,kBAAa,QAAQ,MAAA,CAAC;IAC5B,CAAC;CACF;AArQD,oBAqQC","sourcesContent":["import { Playlist } from \"./Playlist\";\nimport { DisTubeError, formatDuration, isMemberInstance, parseNumber, toSecond } from \"..\";\nimport type ytdl from \"@distube/ytdl-core\";\nimport type { GuildMember } from \"discord.js\";\nimport type { Chapter, OtherSongInfo, RelatedSong, SearchResult } from \"..\";\n\n/**\n * Class representing a song.\n *\n * <info>If {@link Song} is added from a YouTube {@link SearchResult} or {@link Playlist},\n * some info will be missing to save your resources. It will be filled when emitting {@link DisTube#playSong} event.\n *\n * Missing info: {@link Song#likes}, {@link Song#dislikes}, {@link Song#streamURL},\n * {@link Song#related}, {@link Song#chapters}, {@link Song#age_restricted}</info>\n * @template T - The type for the metadata (if any) of the song\n */\nexport class Song<T = unknown> {\n source!: string;\n #metadata!: T;\n formats?: ytdl.videoFormat[];\n #member?: GuildMember;\n id?: string;\n name?: string;\n isLive!: boolean;\n duration!: number;\n formattedDuration?: string;\n url!: string;\n streamURL?: string;\n thumbnail?: string;\n related!: RelatedSong[];\n views!: number;\n likes!: number;\n dislikes!: number;\n uploader!: {\n name?: string;\n url?: string;\n };\n age_restricted!: boolean;\n chapters!: Chapter[];\n reposts!: number;\n #playlist?: Playlist;\n /**\n * Create a Song\n * @param {ytdl.videoInfo|SearchResult|OtherSongInfo} info Raw info\n * @param {Object} [options] Optional options\n * @param {Discord.GuildMember} [options.member] Requested user\n * @param {string} [options.source=\"youtube\"] Song source\n * @param {T} [options.metadata] Song metadata\n */\n constructor(\n info: ytdl.videoInfo | SearchResult | OtherSongInfo | ytdl.relatedVideo | RelatedSong,\n options: {\n member?: GuildMember;\n source?: string;\n metadata?: T;\n } = {},\n ) {\n const { member, source, metadata } = { source: \"youtube\", ...options };\n\n if (\n typeof source !== \"string\" ||\n ((info as OtherSongInfo).src && typeof (info as OtherSongInfo).src !== \"string\")\n ) {\n throw new DisTubeError(\"INVALID_TYPE\", \"string\", source, \"source\");\n }\n /**\n * The source of the song\n * @type {string}\n */\n this.source = ((info as OtherSongInfo)?.src || source).toLowerCase();\n /**\n * Optional metadata that can be used to identify the song.\n * @type {T}\n */\n this.metadata = metadata as T;\n this.member = member;\n if (this.source === \"youtube\") {\n this._patchYouTube(info as ytdl.videoInfo);\n } else {\n this._patchOther(info as OtherSongInfo);\n }\n }\n\n _patchYouTube(i: ytdl.videoInfo | SearchResult) {\n // FIXME\n const info = i as any;\n if (info.full === true) {\n /**\n * Stream formats (Available if the song is from YouTube and playing)\n * @type {ytdl.videoFormat[]?}\n * @private\n */\n this.formats = info.formats;\n // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports\n const err = require(\"@distube/ytdl-core/lib/utils\").playError(info.player_response, [\n \"UNPLAYABLE\",\n \"LIVE_STREAM_OFFLINE\",\n \"LOGIN_REQUIRED\",\n ]);\n if (err) throw err;\n\n if (!info.formats?.length) throw new DisTubeError(\"UNAVAILABLE_VIDEO\");\n }\n const details = info.videoDetails || info;\n /**\n * YouTube video id\n * @type {string?}\n */\n this.id = details.videoId || details.id;\n /**\n * Song name.\n * @type {string?}\n */\n this.name = details.title || details.name;\n /**\n * Indicates if the video is an active live.\n * @type {boolean}\n */\n this.isLive = !!details.isLive;\n /**\n * Song duration.\n * @type {number}\n */\n this.duration = this.isLive ? 0 : toSecond(details.lengthSeconds || details.length_seconds || details.duration);\n /**\n * Formatted duration string (`hh:mm:ss`, `mm:ss` or `Live`).\n * @type {string?}\n */\n this.formattedDuration = this.isLive ? \"Live\" : formatDuration(this.duration);\n /**\n * Song URL.\n * @type {string}\n */\n this.url = `https://www.youtube.com/watch?v=${this.id}`;\n /**\n * Stream / Download URL (Available if the song is playing)\n * @type {string?}\n */\n this.streamURL = undefined;\n /**\n * Song thumbnail.\n * @type {string?}\n */\n this.thumbnail =\n details.thumbnails?.sort((a: any, b: any) => b.width - a.width)?.[0]?.url ||\n details.thumbnail?.url ||\n details.thumbnail;\n /**\n * Related songs (without {@link Song#related} properties)\n * @type {Song[]}\n */\n this.related = info?.related_videos || details.related || [];\n if (!Array.isArray(this.related)) throw new DisTubeError(\"INVALID_TYPE\", \"Array\", this.related, \"Song#related\");\n this.related = this.related.map((v: any) => new Song(v, { source: this.source, metadata: this.metadata }));\n /**\n * Song views count\n * @type {number}\n */\n this.views = parseNumber(details.viewCount || details.view_count || details.views);\n /**\n * Song like count\n * @type {number}\n */\n this.likes = parseNumber(details.likes);\n /**\n * Song dislike count\n * @type {number}\n */\n this.dislikes = parseNumber(details.dislikes);\n /**\n * Song uploader\n * @type {Object}\n * @prop {string?} name Uploader name\n * @prop {string?} url Uploader url\n */\n this.uploader = {\n name: info.uploader?.name || details.author?.name,\n url: info.uploader?.url || details.author?.channel_url || details.author?.url,\n };\n /**\n * Whether or not an age-restricted content\n * @type {boolean}\n */\n this.age_restricted = !!details.age_restricted;\n /**\n * @typedef {Object} Chapter\n * @prop {string} title Chapter title\n * @prop {number} start_time Chapter start time in seconds\n */\n /**\n * Chapters information (YouTube only)\n * @type {Chapter[]}\n */\n this.chapters = details.chapters || [];\n /**\n * Song repost count\n * @type {number}\n */\n this.reposts = 0;\n }\n\n /**\n * Patch data from other source\n * @param {OtherSongInfo} info Video info\n * @private\n */\n _patchOther(info: OtherSongInfo) {\n this.id = info.id;\n this.name = info.title || info.name;\n this.isLive = Boolean(info.is_live || info.isLive);\n this.duration = this.isLive ? 0 : toSecond(info._duration_raw || info.duration);\n this.formattedDuration = this.isLive ? \"Live\" : formatDuration(this.duration);\n this.url = info.webpage_url || info.url;\n this.thumbnail = info.thumbnail;\n this.related = info.related || [];\n if (!Array.isArray(this.related)) throw new DisTubeError(\"INVALID_TYPE\", \"Array\", this.related, \"Song#related\");\n this.related = this.related.map(i => new Song(i, { source: this.source, metadata: this.metadata }));\n this.views = parseNumber(info.view_count || info.views);\n this.likes = parseNumber(info.like_count || info.likes);\n this.dislikes = parseNumber(info.dislike_count || info.dislikes);\n this.reposts = parseNumber(info.repost_count || info.reposts);\n if (typeof info.uploader === \"string\") {\n this.uploader = {\n name: info.uploader,\n url: info.uploader_url,\n };\n } else {\n this.uploader = {\n name: info.uploader?.name,\n url: info.uploader?.url,\n };\n }\n this.age_restricted = info.age_restricted || (!!info.age_limit && parseNumber(info.age_limit) >= 18);\n this.chapters = info.chapters || [];\n }\n\n /**\n * The playlist added this song\n * @type {Playlist?}\n */\n get playlist() {\n return this.#playlist;\n }\n\n set playlist(playlist: Playlist | undefined) {\n if (!(playlist instanceof Playlist)) throw new DisTubeError(\"INVALID_TYPE\", \"Playlist\", playlist, \"Song#playlist\");\n this.#playlist = playlist;\n this.member = playlist.member;\n }\n\n /**\n * User requested.\n * @type {Discord.GuildMember?}\n */\n get member() {\n return this.#member;\n }\n\n set member(member: GuildMember | undefined) {\n if (isMemberInstance(member)) this.#member = member;\n }\n\n /**\n * User requested.\n * @type {Discord.User?}\n */\n get user() {\n return this.member?.user;\n }\n\n get metadata() {\n return this.#metadata;\n }\n\n set metadata(metadata: T) {\n this.#metadata = metadata;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Song.js","sourceRoot":"","sources":["../../src/struct/Song.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,yCAAsC;AACtC,0BAA2F;AAe3F,MAAa,IAAI;IAiCf,YACE,IAAqF,EACrF,UAII,EAAE;QArCR,iCAAc;QAEd,+BAAsB;QAoBtB,iCAAqB;QAiBnB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,EAAE,CAAC;QAEvE,IACE,OAAO,MAAM,KAAK,QAAQ;YAC1B,CAAE,IAAsB,CAAC,GAAG,IAAI,OAAQ,IAAsB,CAAC,GAAG,KAAK,QAAQ,CAAC,EAChF;YACA,MAAM,IAAI,gBAAY,CAAC,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;SACpE;QAKD,IAAI,CAAC,MAAM,GAAG,CAAE,IAAsB,EAAE,GAAG,IAAI,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;QAKrE,IAAI,CAAC,QAAQ,GAAG,QAAa,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE;YAC7B,IAAI,CAAC,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D,IAAI,QAAQ;QACV,OAAO,uBAAA,IAAI,sBAAU,CAAC;IACxB,CAAC;IAED,IAAI,QAAQ,CAAC,QAA8B;QACzC,IAAI,CAAC,CAAC,QAAQ,YAAY,mBAAQ,CAAC;YAAE,MAAM,IAAI,gBAAY,CAAC,cAAc,EAAE,UAAU,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;QACnH,uBAAA,IAAI,kBAAa,QAAQ,MAAA,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;IAChC,CAAC;IAMD,IAAI,MAAM;QACR,OAAO,uBAAA,IAAI,oBAAQ,CAAC;IACtB,CAAC;IAED,IAAI,MAAM,CAAC,MAA+B;QACxC,IAAI,IAAA,oBAAgB,EAAC,MAAM,CAAC;YAAE,uBAAA,IAAI,gBAAW,MAAM,MAAA,CAAC;IACtD,CAAC;IAMD,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC;IAC3B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,uBAAA,IAAI,sBAAU,CAAC;IACxB,CAAC;IAED,IAAI,QAAQ,CAAC,QAAW;QACtB,uBAAA,IAAI,kBAAa,QAAQ,MAAA,CAAC;IAC5B,CAAC;CACF;AArQD,oBAqQC","sourcesContent":["import { Playlist } from \"./Playlist\";\nimport { DisTubeError, formatDuration, isMemberInstance, parseNumber, toSecond } from \"..\";\nimport type ytdl from \"@distube/ytdl-core\";\nimport type { GuildMember } from \"discord.js\";\nimport type { Chapter, OtherSongInfo, RelatedSong, SearchResult } from \"..\";\n\n/**\n * Class representing a song.\n *\n * <info>If {@link Song} is added from a YouTube {@link SearchResult} or {@link Playlist},\n * some info will be missing to save your resources. It will be filled when emitting {@link DisTube#playSong} event.\n *\n * Missing info: {@link Song#likes}, {@link Song#dislikes}, {@link Song#streamURL},\n * {@link Song#related}, {@link Song#chapters}, {@link Song#age_restricted}</info>\n * @template T - The type for the metadata (if any) of the song\n */\nexport class Song<T = unknown> {\n source!: string;\n #metadata!: T;\n formats?: ytdl.videoFormat[];\n #member?: GuildMember;\n id?: string;\n name?: string;\n isLive!: boolean;\n duration!: number;\n formattedDuration?: string;\n url!: string;\n streamURL?: string;\n thumbnail?: string;\n related!: RelatedSong[];\n views!: number;\n likes!: number;\n dislikes!: number;\n uploader!: {\n name?: string;\n url?: string;\n };\n age_restricted!: boolean;\n chapters!: Chapter[];\n reposts!: number;\n #playlist?: Playlist;\n /**\n * Create a Song\n * @param {ytdl.videoInfo|SearchResult|OtherSongInfo} info Raw info\n * @param {Object} [options] Optional options\n * @param {Discord.GuildMember} [options.member] Requested user\n * @param {string} [options.source=\"youtube\"] Song source\n * @param {T} [options.metadata] Song metadata\n */\n constructor(\n info: ytdl.videoInfo | SearchResult | OtherSongInfo | ytdl.relatedVideo | RelatedSong,\n options: {\n member?: GuildMember;\n source?: string;\n metadata?: T;\n } = {},\n ) {\n const { member, source, metadata } = { source: \"youtube\", ...options };\n\n if (\n typeof source !== \"string\" ||\n ((info as OtherSongInfo).src && typeof (info as OtherSongInfo).src !== \"string\")\n ) {\n throw new DisTubeError(\"INVALID_TYPE\", \"string\", source, \"source\");\n }\n /**\n * The source of the song\n * @type {string}\n */\n this.source = ((info as OtherSongInfo)?.src || source).toLowerCase();\n /**\n * Optional metadata that can be used to identify the song.\n * @type {T}\n */\n this.metadata = metadata as T;\n this.member = member;\n if (this.source === \"youtube\") {\n this._patchYouTube(info as ytdl.videoInfo);\n } else {\n this._patchOther(info as OtherSongInfo);\n }\n }\n\n _patchYouTube(i: ytdl.videoInfo | SearchResult) {\n // FIXME\n const info = i as any;\n if (info.full === true) {\n /**\n * Stream formats (Available if the song is from YouTube and playing)\n * @type {ytdl.videoFormat[]?}\n * @private\n */\n this.formats = info.formats;\n // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports\n const err = require(\"@distube/ytdl-core/lib/utils\").playError(info.player_response, [\n \"UNPLAYABLE\",\n \"LIVE_STREAM_OFFLINE\",\n \"LOGIN_REQUIRED\",\n ]);\n if (err) throw err;\n\n if (!info.formats?.length) throw new DisTubeError(\"UNAVAILABLE_VIDEO\");\n }\n const details = info.videoDetails || info;\n /**\n * YouTube video id\n * @type {string?}\n */\n this.id = details.videoId || details.id;\n /**\n * Song name.\n * @type {string?}\n */\n this.name = details.title || details.name;\n /**\n * Indicates if the video is an active live.\n * @type {boolean}\n */\n this.isLive = !!details.isLive;\n /**\n * Song duration.\n * @type {number}\n */\n this.duration = this.isLive ? 0 : toSecond(details.lengthSeconds || details.length_seconds || details.duration);\n /**\n * Formatted duration string (`hh:mm:ss`, `mm:ss` or `Live`).\n * @type {string?}\n */\n this.formattedDuration = this.isLive ? \"Live\" : formatDuration(this.duration);\n /**\n * Song URL.\n * @type {string}\n */\n this.url = `https://www.youtube.com/watch?v=${this.id}`;\n /**\n * Stream / Download URL (Available if the song is playing)\n * @type {string?}\n */\n this.streamURL = undefined;\n /**\n * Song thumbnail.\n * @type {string?}\n */\n this.thumbnail =\n details.thumbnails?.sort((a: any, b: any) => b.width - a.width)?.[0]?.url ||\n details.thumbnail?.url ||\n details.thumbnail;\n /**\n * Related songs (without {@link Song#related} properties)\n * @type {Song[]}\n */\n this.related = info?.related_videos || details.related || [];\n if (!Array.isArray(this.related)) throw new DisTubeError(\"INVALID_TYPE\", \"Array\", this.related, \"Song#related\");\n this.related = this.related.map((v: any) => new Song(v, { source: this.source, metadata: this.metadata }));\n /**\n * Song views count\n * @type {number}\n */\n this.views = parseNumber(details.viewCount || details.view_count || details.views);\n /**\n * Song like count\n * @type {number}\n */\n this.likes = parseNumber(details.likes);\n /**\n * Song dislike count\n * @type {number}\n */\n this.dislikes = parseNumber(details.dislikes);\n /**\n * Song uploader\n * @type {Object}\n * @prop {string?} name Uploader name\n * @prop {string?} url Uploader url\n */\n this.uploader = {\n name: info.uploader?.name || details.author?.name,\n url: info.uploader?.url || details.author?.channel_url || details.author?.url,\n };\n /**\n * Whether or not an age-restricted content\n * @type {boolean}\n */\n this.age_restricted = !!details.age_restricted;\n /**\n * @typedef {Object} Chapter\n * @prop {string} title Chapter title\n * @prop {number} start_time Chapter start time in seconds\n */\n /**\n * Chapters information (YouTube only)\n * @type {Chapter[]}\n */\n this.chapters = details.chapters || [];\n /**\n * Song repost count\n * @type {number}\n */\n this.reposts = 0;\n }\n\n /**\n * Patch data from other source\n * @param {OtherSongInfo} info Video info\n * @private\n */\n _patchOther(info: OtherSongInfo) {\n this.id = info.id;\n this.name = info.title || info.name;\n this.isLive = Boolean(info.is_live || info.isLive);\n this.duration = this.isLive ? 0 : toSecond(info._duration_raw || info.duration);\n this.formattedDuration = this.isLive ? \"Live\" : formatDuration(this.duration);\n this.url = info.webpage_url || info.url;\n this.thumbnail = info.thumbnail;\n this.related = info.related || [];\n if (!Array.isArray(this.related)) throw new DisTubeError(\"INVALID_TYPE\", \"Array\", this.related, \"Song#related\");\n this.related = this.related.map(i => new Song(i, { source: this.source, metadata: this.metadata }));\n this.views = parseNumber(info.view_count || info.views);\n this.likes = parseNumber(info.like_count || info.likes);\n this.dislikes = parseNumber(info.dislike_count || info.dislikes);\n this.reposts = parseNumber(info.repost_count || info.reposts);\n if (typeof info.uploader === \"string\") {\n this.uploader = {\n name: info.uploader,\n url: info.uploader_url,\n };\n } else {\n this.uploader = {\n name: info.uploader?.name,\n url: info.uploader?.url,\n };\n }\n this.age_restricted = info.age_restricted || (!!info.age_limit && parseNumber(info.age_limit) >= 18);\n this.chapters = info.chapters || [];\n }\n\n /**\n * The playlist added this song\n * @type {Playlist?}\n */\n get playlist() {\n return this.#playlist;\n }\n\n set playlist(playlist: Playlist | undefined) {\n if (!(playlist instanceof Playlist)) throw new DisTubeError(\"INVALID_TYPE\", \"Playlist\", playlist, \"Song#playlist\");\n this.#playlist = playlist;\n this.member = playlist.member;\n }\n\n /**\n * User requested.\n * @type {Discord.GuildMember?}\n */\n get member() {\n return this.#member;\n }\n\n set member(member: GuildMember | undefined) {\n if (isMemberInstance(member)) this.#member = member;\n }\n\n /**\n * User requested.\n * @type {Discord.User?}\n */\n get user() {\n return this.member?.user;\n }\n\n get metadata() {\n return this.#metadata;\n }\n\n set metadata(metadata: T) {\n this.#metadata = metadata;\n }\n}\n"]}
|
|
@@ -1,28 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Task queuing system
|
|
3
|
-
* @private
|
|
4
|
-
*/
|
|
5
1
|
export declare class TaskQueue {
|
|
6
2
|
#private;
|
|
7
|
-
/**
|
|
8
|
-
* Waits for last task finished and queues a new task
|
|
9
|
-
* @param {boolean} [resolveInfo=false] Whether the task is a resolving info task
|
|
10
|
-
* @returns {Promise<void>}
|
|
11
|
-
*/
|
|
12
3
|
queuing(resolveInfo?: boolean): Promise<void>;
|
|
13
|
-
/**
|
|
14
|
-
* Removes the finished task and processes the next task
|
|
15
|
-
*/
|
|
16
4
|
resolve(): void;
|
|
17
|
-
/**
|
|
18
|
-
* The remaining number of tasks
|
|
19
|
-
* @type {number}
|
|
20
|
-
*/
|
|
21
5
|
get remaining(): number;
|
|
22
|
-
/**
|
|
23
|
-
* Whether or not having a resolving info task
|
|
24
|
-
* @type {boolean}
|
|
25
|
-
*/
|
|
26
6
|
get hasResolveTask(): boolean;
|
|
27
7
|
}
|
|
28
8
|
//# sourceMappingURL=TaskQueue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaskQueue.d.ts","sourceRoot":"","sources":["../../src/struct/TaskQueue.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TaskQueue.d.ts","sourceRoot":"","sources":["../../src/struct/TaskQueue.ts"],"names":[],"mappings":"AAgBA,qBAAa,SAAS;;IAab,OAAO,CAAC,WAAW,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAS3C,OAAO,IAAI,IAAI;IAQtB,IAAW,SAAS,IAAI,MAAM,CAE7B;IAMD,IAAW,cAAc,IAAI,OAAO,CAEnC;CACF"}
|
package/dist/struct/TaskQueue.js
CHANGED
|
@@ -15,46 +15,21 @@ class Task {
|
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Task queuing system
|
|
20
|
-
* @private
|
|
21
|
-
*/
|
|
22
18
|
class TaskQueue {
|
|
23
19
|
constructor() {
|
|
24
|
-
/**
|
|
25
|
-
* The task array
|
|
26
|
-
* @type {Task[]}
|
|
27
|
-
* @private
|
|
28
|
-
*/
|
|
29
20
|
_TaskQueue_tasks.set(this, []);
|
|
30
21
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Waits for last task finished and queues a new task
|
|
33
|
-
* @param {boolean} [resolveInfo=false] Whether the task is a resolving info task
|
|
34
|
-
* @returns {Promise<void>}
|
|
35
|
-
*/
|
|
36
22
|
queuing(resolveInfo = false) {
|
|
37
23
|
const next = this.remaining ? __classPrivateFieldGet(this, _TaskQueue_tasks, "f")[__classPrivateFieldGet(this, _TaskQueue_tasks, "f").length - 1].promise : Promise.resolve();
|
|
38
24
|
__classPrivateFieldGet(this, _TaskQueue_tasks, "f").push(new Task(resolveInfo));
|
|
39
25
|
return next;
|
|
40
26
|
}
|
|
41
|
-
/**
|
|
42
|
-
* Removes the finished task and processes the next task
|
|
43
|
-
*/
|
|
44
27
|
resolve() {
|
|
45
28
|
__classPrivateFieldGet(this, _TaskQueue_tasks, "f").shift()?.resolve();
|
|
46
29
|
}
|
|
47
|
-
/**
|
|
48
|
-
* The remaining number of tasks
|
|
49
|
-
* @type {number}
|
|
50
|
-
*/
|
|
51
30
|
get remaining() {
|
|
52
31
|
return __classPrivateFieldGet(this, _TaskQueue_tasks, "f").length;
|
|
53
32
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Whether or not having a resolving info task
|
|
56
|
-
* @type {boolean}
|
|
57
|
-
*/
|
|
58
33
|
get hasResolveTask() {
|
|
59
34
|
return !!__classPrivateFieldGet(this, _TaskQueue_tasks, "f").find(t => t.resolveInfo);
|
|
60
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaskQueue.js","sourceRoot":"","sources":["../../src/struct/TaskQueue.ts"],"names":[],"mappings":";;;;;;;;;AAAA,MAAM,IAAI;IAIR,YAAY,WAAoB;QAC9B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAO,GAAG,CAAC,EAAE;YACrC,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;
|
|
1
|
+
{"version":3,"file":"TaskQueue.js","sourceRoot":"","sources":["../../src/struct/TaskQueue.ts"],"names":[],"mappings":";;;;;;;;;AAAA,MAAM,IAAI;IAIR,YAAY,WAAoB;QAC9B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAO,GAAG,CAAC,EAAE;YACrC,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAMD,MAAa,SAAS;IAAtB;QAME,2BAAiB,EAAE,EAAC;IAmCtB,CAAC;IA5BQ,OAAO,CAAC,WAAW,GAAG,KAAK;QAChC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,uBAAA,IAAI,wBAAO,CAAC,uBAAA,IAAI,wBAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QAC9F,uBAAA,IAAI,wBAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IAKM,OAAO;QACZ,uBAAA,IAAI,wBAAO,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC;IACjC,CAAC;IAMD,IAAW,SAAS;QAClB,OAAO,uBAAA,IAAI,wBAAO,CAAC,MAAM,CAAC;IAC5B,CAAC;IAMD,IAAW,cAAc;QACvB,OAAO,CAAC,CAAC,uBAAA,IAAI,wBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IAChD,CAAC;CACF;AAzCD,8BAyCC","sourcesContent":["class Task {\n resolve!: () => void;\n promise: Promise<void>;\n resolveInfo: boolean;\n constructor(resolveInfo: boolean) {\n this.resolveInfo = resolveInfo;\n this.promise = new Promise<void>(res => {\n this.resolve = res;\n });\n }\n}\n\n/**\n * Task queuing system\n * @private\n */\nexport class TaskQueue {\n /**\n * The task array\n * @type {Task[]}\n * @private\n */\n #tasks: Task[] = [];\n\n /**\n * Waits for last task finished and queues a new task\n * @param {boolean} [resolveInfo=false] Whether the task is a resolving info task\n * @returns {Promise<void>}\n */\n public queuing(resolveInfo = false): Promise<void> {\n const next = this.remaining ? this.#tasks[this.#tasks.length - 1].promise : Promise.resolve();\n this.#tasks.push(new Task(resolveInfo));\n return next;\n }\n\n /**\n * Removes the finished task and processes the next task\n */\n public resolve(): void {\n this.#tasks.shift()?.resolve();\n }\n\n /**\n * The remaining number of tasks\n * @type {number}\n */\n public get remaining(): number {\n return this.#tasks.length;\n }\n\n /**\n * Whether or not having a resolving info task\n * @type {boolean}\n */\n public get hasResolveTask(): boolean {\n return !!this.#tasks.find(t => t.resolveInfo);\n }\n}\n"]}
|