distube 3.3.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/README.md +6 -8
- package/dist/DisTube.d.ts +13 -557
- package/dist/DisTube.d.ts.map +1 -1
- package/dist/DisTube.js +38 -639
- package/dist/DisTube.js.map +1 -1
- package/dist/constant.d.ts +0 -101
- package/dist/constant.d.ts.map +1 -1
- package/dist/constant.js +0 -101
- 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 -89
- package/dist/core/DisTubeHandler.d.ts.map +1 -1
- package/dist/core/DisTubeHandler.js +14 -124
- package/dist/core/DisTubeHandler.js.map +1 -1
- package/dist/core/DisTubeOptions.d.ts +0 -2
- package/dist/core/DisTubeOptions.d.ts.map +1 -1
- package/dist/core/DisTubeOptions.js +0 -13
- package/dist/core/DisTubeOptions.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 +9 -71
- 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/core/voice/index.d.ts +0 -1
- package/dist/core/voice/index.d.ts.map +1 -1
- package/dist/core/voice/index.js +0 -1
- package/dist/core/voice/index.js.map +1 -1
- package/dist/plugin/index.d.ts +0 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +0 -1
- package/dist/plugin/index.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/DisTubeError.d.ts +0 -1
- package/dist/struct/DisTubeError.d.ts.map +1 -1
- package/dist/struct/DisTubeError.js +0 -2
- package/dist/struct/DisTubeError.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 -36
- package/dist/struct/Playlist.d.ts.map +1 -1
- package/dist/struct/Playlist.js +3 -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 -38
- package/dist/struct/Song.d.ts.map +1 -1
- package/dist/struct/Song.js +3 -122
- 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 -75
- package/dist/type.d.ts.map +1 -1
- package/dist/type.js.map +1 -1
- package/dist/util.d.ts +1 -30
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +16 -59
- package/dist/util.js.map +1 -1
- package/package.json +22 -14
- package/dist/core/voice/DJSAdapter.d.ts +0 -4
- package/dist/core/voice/DJSAdapter.d.ts.map +0 -1
- package/dist/core/voice/DJSAdapter.js +0 -58
- package/dist/core/voice/DJSAdapter.js.map +0 -1
- package/dist/plugin/youtube-dl.d.ts +0 -12
- package/dist/plugin/youtube-dl.d.ts.map +0 -1
- package/dist/plugin/youtube-dl.js +0 -70
- package/dist/plugin/youtube-dl.js.map +0 -1
|
@@ -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,45 +25,17 @@ export declare class Song<T = unknown> {
|
|
|
35
25
|
age_restricted: boolean;
|
|
36
26
|
chapters: Chapter[];
|
|
37
27
|
reposts: number;
|
|
38
|
-
constructor(info: ytdl.videoInfo | SearchResult | OtherSongInfo | ytdl.relatedVideo);
|
|
39
|
-
/** @deprecated Passing GuildMember for DisTube#Song() is deprecated. */
|
|
40
|
-
constructor(info: ytdl.videoInfo | SearchResult | OtherSongInfo | ytdl.relatedVideo, member?: GuildMember, source?: string, metadata?: T);
|
|
41
|
-
/**
|
|
42
|
-
* Create a Song
|
|
43
|
-
* @param {ytdl.videoInfo|SearchResult|OtherSongInfo} info Raw info
|
|
44
|
-
* @param {Object} [options] Optional options
|
|
45
|
-
* @param {Discord.GuildMember} [options.member] Requested user
|
|
46
|
-
* @param {string} [options.source="youtube"] Song source
|
|
47
|
-
* @param {T} [options.metadata] Song metadata
|
|
48
|
-
*/
|
|
49
28
|
constructor(info: ytdl.videoInfo | SearchResult | OtherSongInfo | ytdl.relatedVideo | RelatedSong, options?: {
|
|
50
29
|
member?: GuildMember;
|
|
51
30
|
source?: string;
|
|
52
31
|
metadata?: T;
|
|
53
32
|
});
|
|
54
33
|
_patchYouTube(i: ytdl.videoInfo | SearchResult): void;
|
|
55
|
-
/**
|
|
56
|
-
* Patch data from other source
|
|
57
|
-
* @param {OtherSongInfo} info Video info
|
|
58
|
-
* @private
|
|
59
|
-
*/
|
|
60
34
|
_patchOther(info: OtherSongInfo): void;
|
|
61
|
-
/**
|
|
62
|
-
* The playlist added this song
|
|
63
|
-
* @type {Playlist?}
|
|
64
|
-
*/
|
|
65
35
|
get playlist(): Playlist | undefined;
|
|
66
36
|
set playlist(playlist: Playlist | undefined);
|
|
67
|
-
/**
|
|
68
|
-
* User requested.
|
|
69
|
-
* @type {Discord.GuildMember?}
|
|
70
|
-
*/
|
|
71
37
|
get member(): GuildMember | undefined;
|
|
72
38
|
set member(member: GuildMember | undefined);
|
|
73
|
-
/**
|
|
74
|
-
* User requested.
|
|
75
|
-
* @type {Discord.User?}
|
|
76
|
-
*/
|
|
77
39
|
get user(): import("discord.js").User | undefined;
|
|
78
40
|
get metadata(): T;
|
|
79
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,EAAE,MAAM,CAAC;IAC3B,GAAG,EAAG,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAG,WAAW,EAAE,CAAC;IACxB,KAAK,EAAG,MAAM,CAAC;IACf,KAAK,EAAG,MAAM,CAAC;IACf,QAAQ,EAAG,MAAM,CAAC;IAClB,QAAQ,EAAG;QACT,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;IACF,cAAc,EAAG,OAAO,CAAC;IACzB,QAAQ,EAAG,OAAO,EAAE,CAAC;IACrB,OAAO,EAAG,MAAM,CAAC;gBAWf,IAAI,EAAE,IAAI,CAAC,SAAS,GAAG,YAAY,GAAG,aAAa,GAAG,IAAI,CAAC,YAAY,GAAG,WAAW,EACrF,OAAO,GAAE;QACP,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,CAAC,CAAC;KACT;IA4BR,aAAa,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,GAAG,YAAY;IA2H9C,WAAW,CAAC,IAAI,EAAE,aAAa;IAkC/B,IAAI,QAAQ,IAIW,QAAQ,GAAG,SAAS,CAF1C;IAED,IAAI,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,EAI1C;IAMD,IAAI,MAAM,IAIS,WAAW,GAAG,SAAS,CAFzC;IAED,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,EAEzC;IAMD,IAAI,IAAI,0CAEP;IAED,IAAI,QAAQ,IAIW,CAAC,CAFvB;IAED,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC,EAEvB;CACF"}
|
package/dist/struct/Song.js
CHANGED
|
@@ -15,40 +15,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.Song = void 0;
|
|
16
16
|
const Playlist_1 = require("./Playlist");
|
|
17
17
|
const __1 = require("..");
|
|
18
|
-
// TODO: Clean parameters on the next major version.
|
|
19
|
-
/**
|
|
20
|
-
* Class representing a song.
|
|
21
|
-
*
|
|
22
|
-
* <info>If {@link Song} is added from a YouTube {@link SearchResult} or {@link Playlist},
|
|
23
|
-
* some info will be missing to save your resources. It will be filled when emitting {@link DisTube#playSong} event.
|
|
24
|
-
*
|
|
25
|
-
* Missing info: {@link Song#likes}, {@link Song#dislikes}, {@link Song#streamURL},
|
|
26
|
-
* {@link Song#related}, {@link Song#chapters}, {@link Song#age_restricted}</info>
|
|
27
|
-
* @template T - The type for the metadata (if any) of the song
|
|
28
|
-
*/
|
|
29
18
|
class Song {
|
|
30
|
-
constructor(info, options = {}
|
|
19
|
+
constructor(info, options = {}) {
|
|
31
20
|
_Song_metadata.set(this, void 0);
|
|
32
21
|
_Song_member.set(this, void 0);
|
|
33
22
|
_Song_playlist.set(this, void 0);
|
|
34
|
-
if ((0, __1.isMemberInstance)(options)) {
|
|
35
|
-
process.emitWarning("Passing GuildMember for DisTube#Song() is deprecated, read the docs for more.", "DeprecationWarning");
|
|
36
|
-
return new Song(info, { member: options, source: src, metadata: meta });
|
|
37
|
-
}
|
|
38
23
|
const { member, source, metadata } = { source: "youtube", ...options };
|
|
39
24
|
if (typeof source !== "string" ||
|
|
40
25
|
(info.src && typeof info.src !== "string")) {
|
|
41
26
|
throw new __1.DisTubeError("INVALID_TYPE", "string", source, "source");
|
|
42
27
|
}
|
|
43
|
-
/**
|
|
44
|
-
* The source of the song
|
|
45
|
-
* @type {string}
|
|
46
|
-
*/
|
|
47
28
|
this.source = (info?.src || source).toLowerCase();
|
|
48
|
-
/**
|
|
49
|
-
* Optional metadata that can be used to identify the song.
|
|
50
|
-
* @type {T}
|
|
51
|
-
*/
|
|
52
29
|
this.metadata = metadata;
|
|
53
30
|
this.member = member;
|
|
54
31
|
if (this.source === "youtube") {
|
|
@@ -59,16 +36,9 @@ class Song {
|
|
|
59
36
|
}
|
|
60
37
|
}
|
|
61
38
|
_patchYouTube(i) {
|
|
62
|
-
// FIXME
|
|
63
39
|
const info = i;
|
|
64
40
|
if (info.full === true) {
|
|
65
|
-
/**
|
|
66
|
-
* Stream formats (Available if the song is from YouTube and playing)
|
|
67
|
-
* @type {ytdl.videoFormat[]?}
|
|
68
|
-
* @private
|
|
69
|
-
*/
|
|
70
41
|
this.formats = info.formats;
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
|
|
72
42
|
const err = require("@distube/ytdl-core/lib/utils").playError(info.player_response, [
|
|
73
43
|
"UNPLAYABLE",
|
|
74
44
|
"LIVE_STREAM_OFFLINE",
|
|
@@ -80,108 +50,32 @@ class Song {
|
|
|
80
50
|
throw new __1.DisTubeError("UNAVAILABLE_VIDEO");
|
|
81
51
|
}
|
|
82
52
|
const details = info.videoDetails || info;
|
|
83
|
-
/**
|
|
84
|
-
* YouTube video id
|
|
85
|
-
* @type {string?}
|
|
86
|
-
*/
|
|
87
53
|
this.id = details.videoId || details.id;
|
|
88
|
-
/**
|
|
89
|
-
* Song name.
|
|
90
|
-
* @type {string?}
|
|
91
|
-
*/
|
|
92
54
|
this.name = details.title || details.name;
|
|
93
|
-
/**
|
|
94
|
-
* Indicates if the video is an active live.
|
|
95
|
-
* @type {boolean}
|
|
96
|
-
*/
|
|
97
55
|
this.isLive = !!details.isLive;
|
|
98
|
-
/**
|
|
99
|
-
* Song duration.
|
|
100
|
-
* @type {number}
|
|
101
|
-
*/
|
|
102
56
|
this.duration = this.isLive ? 0 : (0, __1.toSecond)(details.lengthSeconds || details.length_seconds || details.duration);
|
|
103
|
-
/**
|
|
104
|
-
* Formatted duration string (`hh:mm:ss`, `mm:ss` or `Live`).
|
|
105
|
-
* @type {string?}
|
|
106
|
-
*/
|
|
107
57
|
this.formattedDuration = this.isLive ? "Live" : (0, __1.formatDuration)(this.duration);
|
|
108
|
-
/**
|
|
109
|
-
* Song URL.
|
|
110
|
-
* @type {string}
|
|
111
|
-
*/
|
|
112
58
|
this.url = `https://www.youtube.com/watch?v=${this.id}`;
|
|
113
|
-
/**
|
|
114
|
-
* Stream / Download URL (Available if the song is playing)
|
|
115
|
-
* @type {string?}
|
|
116
|
-
*/
|
|
117
59
|
this.streamURL = undefined;
|
|
118
|
-
/**
|
|
119
|
-
* Song thumbnail.
|
|
120
|
-
* @type {string?}
|
|
121
|
-
*/
|
|
122
60
|
this.thumbnail =
|
|
123
61
|
details.thumbnails?.sort((a, b) => b.width - a.width)?.[0]?.url ||
|
|
124
62
|
details.thumbnail?.url ||
|
|
125
63
|
details.thumbnail;
|
|
126
|
-
/**
|
|
127
|
-
* Related songs (without {@link Song#related} properties)
|
|
128
|
-
* @type {Song[]}
|
|
129
|
-
*/
|
|
130
64
|
this.related = info?.related_videos || details.related || [];
|
|
131
65
|
if (!Array.isArray(this.related))
|
|
132
66
|
throw new __1.DisTubeError("INVALID_TYPE", "Array", this.related, "Song#related");
|
|
133
67
|
this.related = this.related.map((v) => new Song(v, { source: this.source, metadata: this.metadata }));
|
|
134
|
-
/**
|
|
135
|
-
* Song views count
|
|
136
|
-
* @type {number}
|
|
137
|
-
*/
|
|
138
68
|
this.views = (0, __1.parseNumber)(details.viewCount || details.view_count || details.views);
|
|
139
|
-
/**
|
|
140
|
-
* Song like count
|
|
141
|
-
* @type {number}
|
|
142
|
-
*/
|
|
143
69
|
this.likes = (0, __1.parseNumber)(details.likes);
|
|
144
|
-
/**
|
|
145
|
-
* Song dislike count
|
|
146
|
-
* @type {number}
|
|
147
|
-
*/
|
|
148
70
|
this.dislikes = (0, __1.parseNumber)(details.dislikes);
|
|
149
|
-
/**
|
|
150
|
-
* Song uploader
|
|
151
|
-
* @type {Object}
|
|
152
|
-
* @prop {string?} name Uploader name
|
|
153
|
-
* @prop {string?} url Uploader url
|
|
154
|
-
*/
|
|
155
71
|
this.uploader = {
|
|
156
72
|
name: info.uploader?.name || details.author?.name,
|
|
157
73
|
url: info.uploader?.url || details.author?.channel_url || details.author?.url,
|
|
158
74
|
};
|
|
159
|
-
/**
|
|
160
|
-
* Whether or not an age-restricted content
|
|
161
|
-
* @type {boolean}
|
|
162
|
-
*/
|
|
163
75
|
this.age_restricted = !!details.age_restricted;
|
|
164
|
-
/**
|
|
165
|
-
* @typedef {Object} Chapter
|
|
166
|
-
* @prop {string} title Chapter title
|
|
167
|
-
* @prop {number} start_time Chapter start time in seconds
|
|
168
|
-
*/
|
|
169
|
-
/**
|
|
170
|
-
* Chapters information (YouTube only)
|
|
171
|
-
* @type {Chapter[]}
|
|
172
|
-
*/
|
|
173
76
|
this.chapters = details.chapters || [];
|
|
174
|
-
/**
|
|
175
|
-
* Song repost count
|
|
176
|
-
* @type {number}
|
|
177
|
-
*/
|
|
178
77
|
this.reposts = 0;
|
|
179
78
|
}
|
|
180
|
-
/**
|
|
181
|
-
* Patch data from other source
|
|
182
|
-
* @param {OtherSongInfo} info Video info
|
|
183
|
-
* @private
|
|
184
|
-
*/
|
|
185
79
|
_patchOther(info) {
|
|
186
80
|
this.id = info.id;
|
|
187
81
|
this.name = info.title || info.name;
|
|
@@ -213,10 +107,6 @@ class Song {
|
|
|
213
107
|
this.age_restricted = info.age_restricted || (!!info.age_limit && (0, __1.parseNumber)(info.age_limit) >= 18);
|
|
214
108
|
this.chapters = info.chapters || [];
|
|
215
109
|
}
|
|
216
|
-
/**
|
|
217
|
-
* The playlist added this song
|
|
218
|
-
* @type {Playlist?}
|
|
219
|
-
*/
|
|
220
110
|
get playlist() {
|
|
221
111
|
return __classPrivateFieldGet(this, _Song_playlist, "f");
|
|
222
112
|
}
|
|
@@ -226,22 +116,13 @@ class Song {
|
|
|
226
116
|
__classPrivateFieldSet(this, _Song_playlist, playlist, "f");
|
|
227
117
|
this.member = playlist.member;
|
|
228
118
|
}
|
|
229
|
-
/**
|
|
230
|
-
* User requested.
|
|
231
|
-
* @type {Discord.GuildMember?}
|
|
232
|
-
*/
|
|
233
119
|
get member() {
|
|
234
120
|
return __classPrivateFieldGet(this, _Song_member, "f");
|
|
235
121
|
}
|
|
236
122
|
set member(member) {
|
|
237
|
-
if (
|
|
238
|
-
|
|
239
|
-
__classPrivateFieldSet(this, _Song_member, member, "f");
|
|
123
|
+
if ((0, __1.isMemberInstance)(member))
|
|
124
|
+
__classPrivateFieldSet(this, _Song_member, member, "f");
|
|
240
125
|
}
|
|
241
|
-
/**
|
|
242
|
-
* User requested.
|
|
243
|
-
* @type {Discord.User?}
|
|
244
|
-
*/
|
|
245
126
|
get user() {
|
|
246
127
|
return this.member?.user;
|
|
247
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,oDAAoD;AAEpD;;;;;;;;;GASG;AACH,MAAa,IAAI;IAiDf,YACE,IAAqF,EACrF,UAMQ,EAAE,EACV,GAAG,GAAG,SAAS,EACf,IAAQ;QAzDV,iCAAc;QAEd,+BAAsB;QAoBtB,iCAAqB;QAqCnB,IAAI,IAAA,oBAAgB,EAAC,OAAO,CAAC,EAAE;YAC7B,OAAO,CAAC,WAAW,CACjB,+EAA+E,EAC/E,oBAAoB,CACrB,CAAC;YACF,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;SACzE;QAED,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;Q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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// TODO: Clean parameters on the next major version.\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 constructor(info: ytdl.videoInfo | SearchResult | OtherSongInfo | ytdl.relatedVideo);\n /** @deprecated Passing GuildMember for DisTube#Song() is deprecated. */\n constructor(\n info: ytdl.videoInfo | SearchResult | OtherSongInfo | ytdl.relatedVideo,\n member?: GuildMember,\n source?: string,\n metadata?: T,\n );\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 constructor(\n info: ytdl.videoInfo | SearchResult | OtherSongInfo | ytdl.relatedVideo | RelatedSong,\n options:\n | GuildMember\n | {\n member?: GuildMember;\n source?: string;\n metadata?: T;\n } = {},\n src = \"youtube\",\n meta?: T,\n ) {\n if (isMemberInstance(options)) {\n process.emitWarning(\n \"Passing GuildMember for DisTube#Song() is deprecated, read the docs for more.\",\n \"DeprecationWarning\",\n );\n return new Song(info, { member: options, source: src, metadata: meta });\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 as any).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 (!member) return;\n 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,iCAA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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"]}
|