@ziplayer/plugin 0.1.2 → 0.1.33
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/TTSPlugin.js +2 -0
- package/dist/TTSPlugin.js.map +1 -1
- package/package.json +42 -42
- package/src/SoundCloudPlugin.ts +368 -368
- package/src/TTSPlugin.ts +1 -1
- package/src/index.ts +103 -103
- package/tsconfig.json +23 -23
package/dist/TTSPlugin.js
CHANGED
|
@@ -161,6 +161,8 @@ class TTSPlugin extends ziplayer_1.BasePlugin {
|
|
|
161
161
|
*/
|
|
162
162
|
async getStream(track) {
|
|
163
163
|
const cfg = this.extractConfig(track);
|
|
164
|
+
if (track.source !== this.name)
|
|
165
|
+
return { stream: null, type: "arbitrary" };
|
|
164
166
|
if (this.opts.createStream && typeof this.opts.createStream === "function") {
|
|
165
167
|
const out = await this.opts.createStream(cfg.text, { lang: cfg.lang, slow: cfg.slow, track });
|
|
166
168
|
let type;
|
package/dist/TTSPlugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TTSPlugin.js","sourceRoot":"","sources":["../src/TTSPlugin.ts"],"names":[],"mappings":";;;;;;AAAA,uCAAuE;AACvE,mCAAkC;AAClC,wCAA0C;AAC1C,kDAA0B;AAgD1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAa,SAAU,SAAQ,qBAAU;IAKxC;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,YAAY,IAAuB;QAClC,KAAK,EAAE,CAAC;QA/BT,SAAI,GAAG,KAAK,CAAC;QACb,YAAO,GAAG,OAAO,CAAC;QA+BjB,IAAI,CAAC,IAAI,GAAG;YACX,WAAW,EAAE,IAAI,EAAE,WAAW,IAAI,IAAI;YACtC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI;YAClB,YAAY,EAAE,IAAI,EAAE,YAAY;SAChC,CAAC;IACH,CAAC;IAED;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AAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;YAC5E,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;YACpD,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QACtF,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACvF,CAAC;IACF,CAAC;CACD;AAhRD,8BAgRC"}
|
package/package.json
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@ziplayer/plugin",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "A modular Discord voice player with plugin system",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"ZiPlayer",
|
|
7
|
-
"@ziplayer/plugin",
|
|
8
|
-
"discord",
|
|
9
|
-
"music",
|
|
10
|
-
"player",
|
|
11
|
-
"voice"
|
|
12
|
-
],
|
|
13
|
-
"homepage": "https://player.ziji.world",
|
|
14
|
-
"bugs": {
|
|
15
|
-
"url": "https://github.com/ZiProject/ZiPlayer/issues"
|
|
16
|
-
},
|
|
17
|
-
"repository": {
|
|
18
|
-
"type": "git",
|
|
19
|
-
"url": "git+https://github.com/ZiProject/ZiPlayer.git"
|
|
20
|
-
},
|
|
21
|
-
"license": "MIT",
|
|
22
|
-
"author": "Ziji",
|
|
23
|
-
"main": "dist/index.js",
|
|
24
|
-
"types": "dist/index.d.ts",
|
|
25
|
-
"scripts": {
|
|
26
|
-
"build": "tsc",
|
|
27
|
-
"dev": "tsc --watch",
|
|
28
|
-
"prepare": "npm run build"
|
|
29
|
-
},
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"@zibot/scdl": "^0.0.5",
|
|
32
|
-
"@zibot/zitts": "^0.0.3",
|
|
33
|
-
"axios": "^1.12.2",
|
|
34
|
-
"youtube-sr": "^4.3.4",
|
|
35
|
-
"youtubei.js": "^15.0.1",
|
|
36
|
-
"ziplayer": "^0.
|
|
37
|
-
},
|
|
38
|
-
"devDependencies": {
|
|
39
|
-
"@types/node": "^20.0.0",
|
|
40
|
-
"typescript": "^5.0.0"
|
|
41
|
-
}
|
|
42
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@ziplayer/plugin",
|
|
3
|
+
"version": "0.1.33",
|
|
4
|
+
"description": "A modular Discord voice player with plugin system",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ZiPlayer",
|
|
7
|
+
"@ziplayer/plugin",
|
|
8
|
+
"discord",
|
|
9
|
+
"music",
|
|
10
|
+
"player",
|
|
11
|
+
"voice"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://player.ziji.world",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/ZiProject/ZiPlayer/issues"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/ZiProject/ZiPlayer.git"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "Ziji",
|
|
23
|
+
"main": "dist/index.js",
|
|
24
|
+
"types": "dist/index.d.ts",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"dev": "tsc --watch",
|
|
28
|
+
"prepare": "npm run build"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@zibot/scdl": "^0.0.5",
|
|
32
|
+
"@zibot/zitts": "^0.0.3",
|
|
33
|
+
"axios": "^1.12.2",
|
|
34
|
+
"youtube-sr": "^4.3.4",
|
|
35
|
+
"youtubei.js": "^15.0.1",
|
|
36
|
+
"ziplayer": "^0.1.2"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^20.0.0",
|
|
40
|
+
"typescript": "^5.0.0"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/SoundCloudPlugin.ts
CHANGED
|
@@ -1,368 +1,368 @@
|
|
|
1
|
-
import { BasePlugin, Track, SearchResult, StreamInfo } from "ziplayer";
|
|
2
|
-
|
|
3
|
-
const SoundCloud = require("@zibot/scdl");
|
|
4
|
-
import { URL } from "url";
|
|
5
|
-
|
|
6
|
-
const ALLOWED_SOUNDCLOUD_HOSTS = ["soundcloud.com", "www.soundcloud.com", "m.soundcloud.com"];
|
|
7
|
-
|
|
8
|
-
function isValidSoundCloudHost(maybeUrl: string): boolean {
|
|
9
|
-
try {
|
|
10
|
-
const parsed = new URL(maybeUrl);
|
|
11
|
-
return ALLOWED_SOUNDCLOUD_HOSTS.includes(parsed.hostname);
|
|
12
|
-
} catch {
|
|
13
|
-
// Not a valid URL, not handled as host-based
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* A plugin for handling SoundCloud audio content including tracks, playlists, and search functionality.
|
|
19
|
-
*
|
|
20
|
-
* This plugin provides comprehensive support for:
|
|
21
|
-
* - SoundCloud track URLs (soundcloud.com)
|
|
22
|
-
* - SoundCloud playlist URLs
|
|
23
|
-
* - SoundCloud search queries
|
|
24
|
-
* - Audio stream extraction from SoundCloud tracks
|
|
25
|
-
* - Related track recommendations
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
*
|
|
29
|
-
* const soundcloudPlugin = new SoundCloudPlugin();
|
|
30
|
-
*
|
|
31
|
-
* // Add to PlayerManager
|
|
32
|
-
* const manager = new PlayerManager({
|
|
33
|
-
* plugins: [soundcloudPlugin]
|
|
34
|
-
* });
|
|
35
|
-
*
|
|
36
|
-
* // Search for tracks
|
|
37
|
-
* const result = await soundcloudPlugin.search("chill music", "user123");
|
|
38
|
-
*
|
|
39
|
-
* // Get audio stream
|
|
40
|
-
* const stream = await soundcloudPlugin.getStream(result.tracks[0]);
|
|
41
|
-
*
|
|
42
|
-
* @since 1.0.0
|
|
43
|
-
*/
|
|
44
|
-
export class SoundCloudPlugin extends BasePlugin {
|
|
45
|
-
name = "soundcloud";
|
|
46
|
-
version = "1.0.0";
|
|
47
|
-
private client: any;
|
|
48
|
-
private ready: Promise<void>;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Creates a new SoundCloudPlugin instance.
|
|
52
|
-
*
|
|
53
|
-
* The plugin will automatically initialize the SoundCloud client for track
|
|
54
|
-
* and playlist operations. Initialization is asynchronous and handled internally.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* const plugin = new SoundCloudPlugin();
|
|
58
|
-
* // Plugin is ready to use after initialization completes
|
|
59
|
-
*/
|
|
60
|
-
constructor() {
|
|
61
|
-
super();
|
|
62
|
-
this.ready = this.init();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
private async init(): Promise<void> {
|
|
66
|
-
this.client = new SoundCloud({ init: false });
|
|
67
|
-
await this.client.init();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Determines if this plugin can handle the given query.
|
|
72
|
-
*
|
|
73
|
-
* @param query - The search query or URL to check
|
|
74
|
-
* @returns `true` if the plugin can handle the query, `false` otherwise
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* plugin.canHandle("https://soundcloud.com/artist/track"); // true
|
|
78
|
-
* plugin.canHandle("chill music"); // true
|
|
79
|
-
* plugin.canHandle("spotify:track:123"); // false
|
|
80
|
-
*/
|
|
81
|
-
canHandle(query: string): boolean {
|
|
82
|
-
const q = (query || "").trim().toLowerCase();
|
|
83
|
-
const isUrl = q.startsWith("http://") || q.startsWith("https://");
|
|
84
|
-
if (isUrl) {
|
|
85
|
-
return isValidSoundCloudHost(query);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Avoid intercepting explicit patterns for other extractors
|
|
89
|
-
if (q.startsWith("tts:") || q.startsWith("say ")) return false;
|
|
90
|
-
if (q.startsWith("spotify:") || q.includes("open.spotify.com")) return false;
|
|
91
|
-
if (q.includes("youtube")) return false;
|
|
92
|
-
|
|
93
|
-
// Treat remaining non-URL free text as searchable
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Validates if a URL is a valid SoundCloud URL.
|
|
99
|
-
*
|
|
100
|
-
* @param url - The URL to validate
|
|
101
|
-
* @returns `true` if the URL is a valid SoundCloud URL, `false` otherwise
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
* plugin.validate("https://soundcloud.com/artist/track"); // true
|
|
105
|
-
* plugin.validate("https://www.soundcloud.com/artist/track"); // true
|
|
106
|
-
* plugin.validate("https://youtube.com/watch?v=123"); // false
|
|
107
|
-
*/
|
|
108
|
-
validate(url: string): boolean {
|
|
109
|
-
return isValidSoundCloudHost(url);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Searches for SoundCloud content based on the given query.
|
|
114
|
-
*
|
|
115
|
-
* This method handles both URL-based queries (direct track/playlist links) and
|
|
116
|
-
* text-based search queries. For URLs, it will extract track or playlist information.
|
|
117
|
-
* For text queries, it will perform a SoundCloud search and return up to 10 results.
|
|
118
|
-
*
|
|
119
|
-
* @param query - The search query (URL or text)
|
|
120
|
-
* @param requestedBy - The user ID who requested the search
|
|
121
|
-
* @returns A SearchResult containing tracks and optional playlist information
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* // Search by URL
|
|
125
|
-
* const result = await plugin.search("https://soundcloud.com/artist/track", "user123");
|
|
126
|
-
*
|
|
127
|
-
* // Search by text
|
|
128
|
-
* const searchResult = await plugin.search("chill music", "user123");
|
|
129
|
-
* console.log(searchResult.tracks); // Array of Track objects
|
|
130
|
-
*/
|
|
131
|
-
async search(query: string, requestedBy: string): Promise<SearchResult> {
|
|
132
|
-
await this.ready;
|
|
133
|
-
|
|
134
|
-
// If the query is a URL but not a SoundCloud URL, do not handle it here
|
|
135
|
-
// This prevents hijacking e.g. YouTube/Spotify links as free-text searches.
|
|
136
|
-
try {
|
|
137
|
-
const q = (query || "").trim().toLowerCase();
|
|
138
|
-
const isUrl = q.startsWith("http://") || q.startsWith("https://");
|
|
139
|
-
if (isUrl && !this.validate(query)) {
|
|
140
|
-
return { tracks: [] };
|
|
141
|
-
}
|
|
142
|
-
} catch {}
|
|
143
|
-
|
|
144
|
-
try {
|
|
145
|
-
if (isValidSoundCloudHost(query)) {
|
|
146
|
-
try {
|
|
147
|
-
const info = await this.client.getTrackDetails(query);
|
|
148
|
-
const track: Track = {
|
|
149
|
-
id: info.id.toString(),
|
|
150
|
-
title: info.title,
|
|
151
|
-
url: info.permalink_url || query,
|
|
152
|
-
duration: info.duration,
|
|
153
|
-
thumbnail: info.artwork_url,
|
|
154
|
-
requestedBy,
|
|
155
|
-
source: this.name,
|
|
156
|
-
metadata: {
|
|
157
|
-
author: info.user?.username,
|
|
158
|
-
plays: info.playback_count,
|
|
159
|
-
},
|
|
160
|
-
};
|
|
161
|
-
return { tracks: [track] };
|
|
162
|
-
} catch {
|
|
163
|
-
const playlist = await this.client.getPlaylistDetails(query);
|
|
164
|
-
const tracks: Track[] = playlist.tracks.map((t: any) => ({
|
|
165
|
-
id: t.id.toString(),
|
|
166
|
-
title: t.title,
|
|
167
|
-
url: t.permalink_url,
|
|
168
|
-
duration: t.duration,
|
|
169
|
-
thumbnail: t.artwork_url || playlist.artwork_url,
|
|
170
|
-
requestedBy,
|
|
171
|
-
source: this.name,
|
|
172
|
-
metadata: {
|
|
173
|
-
author: t.user?.username,
|
|
174
|
-
plays: t.playback_count,
|
|
175
|
-
playlist: playlist.id?.toString(),
|
|
176
|
-
},
|
|
177
|
-
}));
|
|
178
|
-
|
|
179
|
-
return {
|
|
180
|
-
tracks,
|
|
181
|
-
playlist: {
|
|
182
|
-
name: playlist.title,
|
|
183
|
-
url: playlist.permalink_url || query,
|
|
184
|
-
thumbnail: playlist.artwork_url,
|
|
185
|
-
},
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const results = await this.client.searchTracks({ query, limit: 15 });
|
|
191
|
-
const tracks: Track[] = results.slice(0, 10).map((track: any) => ({
|
|
192
|
-
id: track.id.toString(),
|
|
193
|
-
title: track.title,
|
|
194
|
-
url: track.permalink_url,
|
|
195
|
-
duration: track.duration,
|
|
196
|
-
thumbnail: track.artwork_url,
|
|
197
|
-
requestedBy,
|
|
198
|
-
source: this.name,
|
|
199
|
-
metadata: {
|
|
200
|
-
author: track.user?.username,
|
|
201
|
-
plays: track.playback_count,
|
|
202
|
-
},
|
|
203
|
-
}));
|
|
204
|
-
|
|
205
|
-
return { tracks };
|
|
206
|
-
} catch (error: any) {
|
|
207
|
-
throw new Error(`SoundCloud search failed: ${error?.message}`);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Retrieves the audio stream for a SoundCloud track.
|
|
213
|
-
*
|
|
214
|
-
* This method downloads the audio stream from SoundCloud using the track's URL.
|
|
215
|
-
* It handles the SoundCloud-specific download process and returns the stream
|
|
216
|
-
* in a format compatible with the player.
|
|
217
|
-
*
|
|
218
|
-
* @param track - The Track object to get the stream for
|
|
219
|
-
* @returns A StreamInfo object containing the audio stream and metadata
|
|
220
|
-
* @throws {Error} If the track URL is invalid or stream download fails
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* const track = { id: "123", title: "Track Title", url: "https://soundcloud.com/artist/track", ... };
|
|
224
|
-
* const streamInfo = await plugin.getStream(track);
|
|
225
|
-
* console.log(streamInfo.type); // "arbitrary"
|
|
226
|
-
* console.log(streamInfo.stream); // Readable stream
|
|
227
|
-
*/
|
|
228
|
-
async getStream(track: Track): Promise<StreamInfo> {
|
|
229
|
-
await this.ready;
|
|
230
|
-
|
|
231
|
-
try {
|
|
232
|
-
const stream = await this.client.downloadTrack(track.url);
|
|
233
|
-
if (!stream) {
|
|
234
|
-
throw new Error("SoundCloud download returned null");
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return {
|
|
238
|
-
stream,
|
|
239
|
-
type: "arbitrary",
|
|
240
|
-
metadata: track.metadata,
|
|
241
|
-
};
|
|
242
|
-
} catch (error: any) {
|
|
243
|
-
throw new Error(`Failed to get SoundCloud stream: ${error.message}`);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Gets related tracks for a given SoundCloud track.
|
|
249
|
-
*
|
|
250
|
-
* This method fetches related tracks from SoundCloud's recommendation system
|
|
251
|
-
* based on the provided track URL or ID. It can filter out tracks that are
|
|
252
|
-
* already in the history to avoid duplicates.
|
|
253
|
-
*
|
|
254
|
-
* @param trackURL - The SoundCloud track URL or ID to get related tracks for
|
|
255
|
-
* @param opts - Options for filtering and limiting results
|
|
256
|
-
* @param opts.limit - Maximum number of related tracks to return (default: 1)
|
|
257
|
-
* @param opts.offset - Number of tracks to skip from the beginning (default: 0)
|
|
258
|
-
* @param opts.history - Array of tracks to exclude from results
|
|
259
|
-
* @returns An array of related Track objects
|
|
260
|
-
*
|
|
261
|
-
* @example
|
|
262
|
-
* const related = await plugin.getRelatedTracks(
|
|
263
|
-
* "https://soundcloud.com/artist/track",
|
|
264
|
-
* { limit: 3, history: [currentTrack] }
|
|
265
|
-
* );
|
|
266
|
-
* console.log(`Found ${related.length} related tracks`);
|
|
267
|
-
*/
|
|
268
|
-
async getRelatedTracks(
|
|
269
|
-
trackURL: string | number,
|
|
270
|
-
opts: { limit?: number; offset?: number; history?: Track[] } = {},
|
|
271
|
-
): Promise<Track[]> {
|
|
272
|
-
await this.ready;
|
|
273
|
-
try {
|
|
274
|
-
const tracks = await this.client.getRelatedTracks(trackURL, {
|
|
275
|
-
limit: 30,
|
|
276
|
-
filter: "tracks",
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
if (!tracks || !tracks?.length) {
|
|
280
|
-
return [];
|
|
281
|
-
}
|
|
282
|
-
const relatedfilter = tracks.filter((tr: any) => !(opts?.history ?? []).some((t) => t.url === tr.permalink_url));
|
|
283
|
-
|
|
284
|
-
const related = relatedfilter.slice(0, opts.limit || 1);
|
|
285
|
-
|
|
286
|
-
return related.map((t: any) => ({
|
|
287
|
-
id: t.id.toString(),
|
|
288
|
-
title: t.title,
|
|
289
|
-
url: t.permalink_url,
|
|
290
|
-
duration: t.duration,
|
|
291
|
-
thumbnail: t.artwork_url,
|
|
292
|
-
requestedBy: "auto",
|
|
293
|
-
source: this.name,
|
|
294
|
-
metadata: {
|
|
295
|
-
author: t.user?.username,
|
|
296
|
-
plays: t.playback_count,
|
|
297
|
-
},
|
|
298
|
-
}));
|
|
299
|
-
} catch {
|
|
300
|
-
return [];
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Provides a fallback stream by searching for the track title.
|
|
306
|
-
*
|
|
307
|
-
* This method is used when the primary stream extraction fails. It performs
|
|
308
|
-
* a search using the track's title and attempts to get a stream from the
|
|
309
|
-
* first search result.
|
|
310
|
-
*
|
|
311
|
-
* @param track - The Track object to get a fallback stream for
|
|
312
|
-
* @returns A StreamInfo object containing the fallback audio stream
|
|
313
|
-
* @throws {Error} If no fallback track is found or stream extraction fails
|
|
314
|
-
*
|
|
315
|
-
* @example
|
|
316
|
-
* try {
|
|
317
|
-
* const stream = await plugin.getStream(track);
|
|
318
|
-
* } catch (error) {
|
|
319
|
-
* // Try fallback
|
|
320
|
-
* const fallbackStream = await plugin.getFallback(track);
|
|
321
|
-
* }
|
|
322
|
-
*/
|
|
323
|
-
async getFallback(track: Track): Promise<StreamInfo> {
|
|
324
|
-
const trackfall = await this.search(track.title, track.requestedBy);
|
|
325
|
-
const fallbackTrack = trackfall.tracks?.[0];
|
|
326
|
-
if (!fallbackTrack) {
|
|
327
|
-
throw new Error(`No fallback track found for ${track.title}`);
|
|
328
|
-
}
|
|
329
|
-
return await this.getStream(fallbackTrack);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Extracts tracks from a SoundCloud playlist URL.
|
|
334
|
-
*
|
|
335
|
-
* @param url - The SoundCloud playlist URL
|
|
336
|
-
* @param requestedBy - The user ID who requested the extraction
|
|
337
|
-
* @returns An array of Track objects from the playlist
|
|
338
|
-
*
|
|
339
|
-
* @example
|
|
340
|
-
* const tracks = await plugin.extractPlaylist(
|
|
341
|
-
* "https://soundcloud.com/artist/sets/playlist-name",
|
|
342
|
-
* "user123"
|
|
343
|
-
* );
|
|
344
|
-
* console.log(`Found ${tracks.length} tracks in playlist`);
|
|
345
|
-
*/
|
|
346
|
-
async extractPlaylist(url: string, requestedBy: string): Promise<Track[]> {
|
|
347
|
-
await this.ready;
|
|
348
|
-
try {
|
|
349
|
-
const playlist = await this.client.getPlaylistDetails(url);
|
|
350
|
-
return playlist.tracks.map((t: any) => ({
|
|
351
|
-
id: t.id.toString(),
|
|
352
|
-
title: t.title,
|
|
353
|
-
url: t.permalink_url,
|
|
354
|
-
duration: t.duration,
|
|
355
|
-
thumbnail: t.artwork_url || playlist.artwork_url,
|
|
356
|
-
requestedBy,
|
|
357
|
-
source: this.name,
|
|
358
|
-
metadata: {
|
|
359
|
-
author: t.user?.username,
|
|
360
|
-
plays: t.playback_count,
|
|
361
|
-
playlist: playlist.id?.toString(),
|
|
362
|
-
},
|
|
363
|
-
}));
|
|
364
|
-
} catch {
|
|
365
|
-
return [];
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
1
|
+
import { BasePlugin, Track, SearchResult, StreamInfo } from "ziplayer";
|
|
2
|
+
|
|
3
|
+
const SoundCloud = require("@zibot/scdl");
|
|
4
|
+
import { URL } from "url";
|
|
5
|
+
|
|
6
|
+
const ALLOWED_SOUNDCLOUD_HOSTS = ["soundcloud.com", "www.soundcloud.com", "m.soundcloud.com"];
|
|
7
|
+
|
|
8
|
+
function isValidSoundCloudHost(maybeUrl: string): boolean {
|
|
9
|
+
try {
|
|
10
|
+
const parsed = new URL(maybeUrl);
|
|
11
|
+
return ALLOWED_SOUNDCLOUD_HOSTS.includes(parsed.hostname);
|
|
12
|
+
} catch {
|
|
13
|
+
// Not a valid URL, not handled as host-based
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A plugin for handling SoundCloud audio content including tracks, playlists, and search functionality.
|
|
19
|
+
*
|
|
20
|
+
* This plugin provides comprehensive support for:
|
|
21
|
+
* - SoundCloud track URLs (soundcloud.com)
|
|
22
|
+
* - SoundCloud playlist URLs
|
|
23
|
+
* - SoundCloud search queries
|
|
24
|
+
* - Audio stream extraction from SoundCloud tracks
|
|
25
|
+
* - Related track recommendations
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
*
|
|
29
|
+
* const soundcloudPlugin = new SoundCloudPlugin();
|
|
30
|
+
*
|
|
31
|
+
* // Add to PlayerManager
|
|
32
|
+
* const manager = new PlayerManager({
|
|
33
|
+
* plugins: [soundcloudPlugin]
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* // Search for tracks
|
|
37
|
+
* const result = await soundcloudPlugin.search("chill music", "user123");
|
|
38
|
+
*
|
|
39
|
+
* // Get audio stream
|
|
40
|
+
* const stream = await soundcloudPlugin.getStream(result.tracks[0]);
|
|
41
|
+
*
|
|
42
|
+
* @since 1.0.0
|
|
43
|
+
*/
|
|
44
|
+
export class SoundCloudPlugin extends BasePlugin {
|
|
45
|
+
name = "soundcloud";
|
|
46
|
+
version = "1.0.0";
|
|
47
|
+
private client: any;
|
|
48
|
+
private ready: Promise<void>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new SoundCloudPlugin instance.
|
|
52
|
+
*
|
|
53
|
+
* The plugin will automatically initialize the SoundCloud client for track
|
|
54
|
+
* and playlist operations. Initialization is asynchronous and handled internally.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* const plugin = new SoundCloudPlugin();
|
|
58
|
+
* // Plugin is ready to use after initialization completes
|
|
59
|
+
*/
|
|
60
|
+
constructor() {
|
|
61
|
+
super();
|
|
62
|
+
this.ready = this.init();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private async init(): Promise<void> {
|
|
66
|
+
this.client = new SoundCloud({ init: false });
|
|
67
|
+
await this.client.init();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Determines if this plugin can handle the given query.
|
|
72
|
+
*
|
|
73
|
+
* @param query - The search query or URL to check
|
|
74
|
+
* @returns `true` if the plugin can handle the query, `false` otherwise
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* plugin.canHandle("https://soundcloud.com/artist/track"); // true
|
|
78
|
+
* plugin.canHandle("chill music"); // true
|
|
79
|
+
* plugin.canHandle("spotify:track:123"); // false
|
|
80
|
+
*/
|
|
81
|
+
canHandle(query: string): boolean {
|
|
82
|
+
const q = (query || "").trim().toLowerCase();
|
|
83
|
+
const isUrl = q.startsWith("http://") || q.startsWith("https://");
|
|
84
|
+
if (isUrl) {
|
|
85
|
+
return isValidSoundCloudHost(query);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Avoid intercepting explicit patterns for other extractors
|
|
89
|
+
if (q.startsWith("tts:") || q.startsWith("say ")) return false;
|
|
90
|
+
if (q.startsWith("spotify:") || q.includes("open.spotify.com")) return false;
|
|
91
|
+
if (q.includes("youtube")) return false;
|
|
92
|
+
|
|
93
|
+
// Treat remaining non-URL free text as searchable
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Validates if a URL is a valid SoundCloud URL.
|
|
99
|
+
*
|
|
100
|
+
* @param url - The URL to validate
|
|
101
|
+
* @returns `true` if the URL is a valid SoundCloud URL, `false` otherwise
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* plugin.validate("https://soundcloud.com/artist/track"); // true
|
|
105
|
+
* plugin.validate("https://www.soundcloud.com/artist/track"); // true
|
|
106
|
+
* plugin.validate("https://youtube.com/watch?v=123"); // false
|
|
107
|
+
*/
|
|
108
|
+
validate(url: string): boolean {
|
|
109
|
+
return isValidSoundCloudHost(url);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Searches for SoundCloud content based on the given query.
|
|
114
|
+
*
|
|
115
|
+
* This method handles both URL-based queries (direct track/playlist links) and
|
|
116
|
+
* text-based search queries. For URLs, it will extract track or playlist information.
|
|
117
|
+
* For text queries, it will perform a SoundCloud search and return up to 10 results.
|
|
118
|
+
*
|
|
119
|
+
* @param query - The search query (URL or text)
|
|
120
|
+
* @param requestedBy - The user ID who requested the search
|
|
121
|
+
* @returns A SearchResult containing tracks and optional playlist information
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* // Search by URL
|
|
125
|
+
* const result = await plugin.search("https://soundcloud.com/artist/track", "user123");
|
|
126
|
+
*
|
|
127
|
+
* // Search by text
|
|
128
|
+
* const searchResult = await plugin.search("chill music", "user123");
|
|
129
|
+
* console.log(searchResult.tracks); // Array of Track objects
|
|
130
|
+
*/
|
|
131
|
+
async search(query: string, requestedBy: string): Promise<SearchResult> {
|
|
132
|
+
await this.ready;
|
|
133
|
+
|
|
134
|
+
// If the query is a URL but not a SoundCloud URL, do not handle it here
|
|
135
|
+
// This prevents hijacking e.g. YouTube/Spotify links as free-text searches.
|
|
136
|
+
try {
|
|
137
|
+
const q = (query || "").trim().toLowerCase();
|
|
138
|
+
const isUrl = q.startsWith("http://") || q.startsWith("https://");
|
|
139
|
+
if (isUrl && !this.validate(query)) {
|
|
140
|
+
return { tracks: [] };
|
|
141
|
+
}
|
|
142
|
+
} catch {}
|
|
143
|
+
|
|
144
|
+
try {
|
|
145
|
+
if (isValidSoundCloudHost(query)) {
|
|
146
|
+
try {
|
|
147
|
+
const info = await this.client.getTrackDetails(query);
|
|
148
|
+
const track: Track = {
|
|
149
|
+
id: info.id.toString(),
|
|
150
|
+
title: info.title,
|
|
151
|
+
url: info.permalink_url || query,
|
|
152
|
+
duration: info.duration,
|
|
153
|
+
thumbnail: info.artwork_url,
|
|
154
|
+
requestedBy,
|
|
155
|
+
source: this.name,
|
|
156
|
+
metadata: {
|
|
157
|
+
author: info.user?.username,
|
|
158
|
+
plays: info.playback_count,
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
return { tracks: [track] };
|
|
162
|
+
} catch {
|
|
163
|
+
const playlist = await this.client.getPlaylistDetails(query);
|
|
164
|
+
const tracks: Track[] = playlist.tracks.map((t: any) => ({
|
|
165
|
+
id: t.id.toString(),
|
|
166
|
+
title: t.title,
|
|
167
|
+
url: t.permalink_url,
|
|
168
|
+
duration: t.duration,
|
|
169
|
+
thumbnail: t.artwork_url || playlist.artwork_url,
|
|
170
|
+
requestedBy,
|
|
171
|
+
source: this.name,
|
|
172
|
+
metadata: {
|
|
173
|
+
author: t.user?.username,
|
|
174
|
+
plays: t.playback_count,
|
|
175
|
+
playlist: playlist.id?.toString(),
|
|
176
|
+
},
|
|
177
|
+
}));
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
tracks,
|
|
181
|
+
playlist: {
|
|
182
|
+
name: playlist.title,
|
|
183
|
+
url: playlist.permalink_url || query,
|
|
184
|
+
thumbnail: playlist.artwork_url,
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const results = await this.client.searchTracks({ query, limit: 15 });
|
|
191
|
+
const tracks: Track[] = results.slice(0, 10).map((track: any) => ({
|
|
192
|
+
id: track.id.toString(),
|
|
193
|
+
title: track.title,
|
|
194
|
+
url: track.permalink_url,
|
|
195
|
+
duration: track.duration,
|
|
196
|
+
thumbnail: track.artwork_url,
|
|
197
|
+
requestedBy,
|
|
198
|
+
source: this.name,
|
|
199
|
+
metadata: {
|
|
200
|
+
author: track.user?.username,
|
|
201
|
+
plays: track.playback_count,
|
|
202
|
+
},
|
|
203
|
+
}));
|
|
204
|
+
|
|
205
|
+
return { tracks };
|
|
206
|
+
} catch (error: any) {
|
|
207
|
+
throw new Error(`SoundCloud search failed: ${error?.message}`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Retrieves the audio stream for a SoundCloud track.
|
|
213
|
+
*
|
|
214
|
+
* This method downloads the audio stream from SoundCloud using the track's URL.
|
|
215
|
+
* It handles the SoundCloud-specific download process and returns the stream
|
|
216
|
+
* in a format compatible with the player.
|
|
217
|
+
*
|
|
218
|
+
* @param track - The Track object to get the stream for
|
|
219
|
+
* @returns A StreamInfo object containing the audio stream and metadata
|
|
220
|
+
* @throws {Error} If the track URL is invalid or stream download fails
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* const track = { id: "123", title: "Track Title", url: "https://soundcloud.com/artist/track", ... };
|
|
224
|
+
* const streamInfo = await plugin.getStream(track);
|
|
225
|
+
* console.log(streamInfo.type); // "arbitrary"
|
|
226
|
+
* console.log(streamInfo.stream); // Readable stream
|
|
227
|
+
*/
|
|
228
|
+
async getStream(track: Track): Promise<StreamInfo> {
|
|
229
|
+
await this.ready;
|
|
230
|
+
|
|
231
|
+
try {
|
|
232
|
+
const stream = await this.client.downloadTrack(track.url);
|
|
233
|
+
if (!stream) {
|
|
234
|
+
throw new Error("SoundCloud download returned null");
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return {
|
|
238
|
+
stream,
|
|
239
|
+
type: "arbitrary",
|
|
240
|
+
metadata: track.metadata,
|
|
241
|
+
};
|
|
242
|
+
} catch (error: any) {
|
|
243
|
+
throw new Error(`Failed to get SoundCloud stream: ${error.message}`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Gets related tracks for a given SoundCloud track.
|
|
249
|
+
*
|
|
250
|
+
* This method fetches related tracks from SoundCloud's recommendation system
|
|
251
|
+
* based on the provided track URL or ID. It can filter out tracks that are
|
|
252
|
+
* already in the history to avoid duplicates.
|
|
253
|
+
*
|
|
254
|
+
* @param trackURL - The SoundCloud track URL or ID to get related tracks for
|
|
255
|
+
* @param opts - Options for filtering and limiting results
|
|
256
|
+
* @param opts.limit - Maximum number of related tracks to return (default: 1)
|
|
257
|
+
* @param opts.offset - Number of tracks to skip from the beginning (default: 0)
|
|
258
|
+
* @param opts.history - Array of tracks to exclude from results
|
|
259
|
+
* @returns An array of related Track objects
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* const related = await plugin.getRelatedTracks(
|
|
263
|
+
* "https://soundcloud.com/artist/track",
|
|
264
|
+
* { limit: 3, history: [currentTrack] }
|
|
265
|
+
* );
|
|
266
|
+
* console.log(`Found ${related.length} related tracks`);
|
|
267
|
+
*/
|
|
268
|
+
async getRelatedTracks(
|
|
269
|
+
trackURL: string | number,
|
|
270
|
+
opts: { limit?: number; offset?: number; history?: Track[] } = {},
|
|
271
|
+
): Promise<Track[]> {
|
|
272
|
+
await this.ready;
|
|
273
|
+
try {
|
|
274
|
+
const tracks = await this.client.getRelatedTracks(trackURL, {
|
|
275
|
+
limit: 30,
|
|
276
|
+
filter: "tracks",
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
if (!tracks || !tracks?.length) {
|
|
280
|
+
return [];
|
|
281
|
+
}
|
|
282
|
+
const relatedfilter = tracks.filter((tr: any) => !(opts?.history ?? []).some((t) => t.url === tr.permalink_url));
|
|
283
|
+
|
|
284
|
+
const related = relatedfilter.slice(0, opts.limit || 1);
|
|
285
|
+
|
|
286
|
+
return related.map((t: any) => ({
|
|
287
|
+
id: t.id.toString(),
|
|
288
|
+
title: t.title,
|
|
289
|
+
url: t.permalink_url,
|
|
290
|
+
duration: t.duration,
|
|
291
|
+
thumbnail: t.artwork_url,
|
|
292
|
+
requestedBy: "auto",
|
|
293
|
+
source: this.name,
|
|
294
|
+
metadata: {
|
|
295
|
+
author: t.user?.username,
|
|
296
|
+
plays: t.playback_count,
|
|
297
|
+
},
|
|
298
|
+
}));
|
|
299
|
+
} catch {
|
|
300
|
+
return [];
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Provides a fallback stream by searching for the track title.
|
|
306
|
+
*
|
|
307
|
+
* This method is used when the primary stream extraction fails. It performs
|
|
308
|
+
* a search using the track's title and attempts to get a stream from the
|
|
309
|
+
* first search result.
|
|
310
|
+
*
|
|
311
|
+
* @param track - The Track object to get a fallback stream for
|
|
312
|
+
* @returns A StreamInfo object containing the fallback audio stream
|
|
313
|
+
* @throws {Error} If no fallback track is found or stream extraction fails
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* try {
|
|
317
|
+
* const stream = await plugin.getStream(track);
|
|
318
|
+
* } catch (error) {
|
|
319
|
+
* // Try fallback
|
|
320
|
+
* const fallbackStream = await plugin.getFallback(track);
|
|
321
|
+
* }
|
|
322
|
+
*/
|
|
323
|
+
async getFallback(track: Track): Promise<StreamInfo> {
|
|
324
|
+
const trackfall = await this.search(track.title, track.requestedBy);
|
|
325
|
+
const fallbackTrack = trackfall.tracks?.[0];
|
|
326
|
+
if (!fallbackTrack) {
|
|
327
|
+
throw new Error(`No fallback track found for ${track.title}`);
|
|
328
|
+
}
|
|
329
|
+
return await this.getStream(fallbackTrack);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Extracts tracks from a SoundCloud playlist URL.
|
|
334
|
+
*
|
|
335
|
+
* @param url - The SoundCloud playlist URL
|
|
336
|
+
* @param requestedBy - The user ID who requested the extraction
|
|
337
|
+
* @returns An array of Track objects from the playlist
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* const tracks = await plugin.extractPlaylist(
|
|
341
|
+
* "https://soundcloud.com/artist/sets/playlist-name",
|
|
342
|
+
* "user123"
|
|
343
|
+
* );
|
|
344
|
+
* console.log(`Found ${tracks.length} tracks in playlist`);
|
|
345
|
+
*/
|
|
346
|
+
async extractPlaylist(url: string, requestedBy: string): Promise<Track[]> {
|
|
347
|
+
await this.ready;
|
|
348
|
+
try {
|
|
349
|
+
const playlist = await this.client.getPlaylistDetails(url);
|
|
350
|
+
return playlist.tracks.map((t: any) => ({
|
|
351
|
+
id: t.id.toString(),
|
|
352
|
+
title: t.title,
|
|
353
|
+
url: t.permalink_url,
|
|
354
|
+
duration: t.duration,
|
|
355
|
+
thumbnail: t.artwork_url || playlist.artwork_url,
|
|
356
|
+
requestedBy,
|
|
357
|
+
source: this.name,
|
|
358
|
+
metadata: {
|
|
359
|
+
author: t.user?.username,
|
|
360
|
+
plays: t.playback_count,
|
|
361
|
+
playlist: playlist.id?.toString(),
|
|
362
|
+
},
|
|
363
|
+
}));
|
|
364
|
+
} catch {
|
|
365
|
+
return [];
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
package/src/TTSPlugin.ts
CHANGED
|
@@ -208,7 +208,7 @@ export class TTSPlugin extends BasePlugin {
|
|
|
208
208
|
*/
|
|
209
209
|
async getStream(track: Track): Promise<StreamInfo> {
|
|
210
210
|
const cfg = this.extractConfig(track);
|
|
211
|
-
|
|
211
|
+
if (track.source !== this.name) return {stream:null as any, type:"arbitrary" };
|
|
212
212
|
if (this.opts.createStream && typeof this.opts.createStream === "function") {
|
|
213
213
|
const out = await this.opts.createStream(cfg.text, { lang: cfg.lang, slow: cfg.slow, track });
|
|
214
214
|
let type: StreamInfo["type"] | undefined;
|
package/src/index.ts
CHANGED
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Main export file for ZiPlayer plugins.
|
|
3
|
-
*
|
|
4
|
-
* This module exports all available plugins for the ZiPlayer music bot framework.
|
|
5
|
-
* Each plugin provides support for different audio sources and services.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* import { YouTubePlugin, SoundCloudPlugin, SpotifyPlugin, TTSPlugin } from "ziplayer/plugins";
|
|
9
|
-
*
|
|
10
|
-
* const manager = new PlayerManager({
|
|
11
|
-
* plugins: [
|
|
12
|
-
* new YouTubePlugin(),
|
|
13
|
-
* new SoundCloudPlugin(),
|
|
14
|
-
* new SpotifyPlugin(),
|
|
15
|
-
* new TTSPlugin({ defaultLang: "en" })
|
|
16
|
-
* ]
|
|
17
|
-
* });
|
|
18
|
-
*
|
|
19
|
-
* @since 1.0.0
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* YouTube plugin for handling YouTube videos, playlists, and search.
|
|
24
|
-
*
|
|
25
|
-
* Provides comprehensive support for YouTube content including:
|
|
26
|
-
* - Video URLs (youtube.com, youtu.be, music.youtube.com)
|
|
27
|
-
* - Playlist URLs and dynamic mixes
|
|
28
|
-
* - Search functionality
|
|
29
|
-
* - Audio stream extraction
|
|
30
|
-
* - Related track recommendations
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* const youtubePlugin = new YouTubePlugin();
|
|
34
|
-
* const result = await youtubePlugin.search("Never Gonna Give You Up", "user123");
|
|
35
|
-
*/
|
|
36
|
-
export { YouTubePlugin } from "./YouTubePlugin";
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* SoundCloud plugin for handling SoundCloud tracks, playlists, and search.
|
|
40
|
-
*
|
|
41
|
-
* Provides comprehensive support for SoundCloud content including:
|
|
42
|
-
* - Track URLs (soundcloud.com)
|
|
43
|
-
* - Playlist URLs
|
|
44
|
-
* - Search functionality
|
|
45
|
-
* - Audio stream extraction
|
|
46
|
-
* - Related track recommendations
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* const soundcloudPlugin = new SoundCloudPlugin();
|
|
50
|
-
* const result = await soundcloudPlugin.search("chill music", "user123");
|
|
51
|
-
*/
|
|
52
|
-
export { SoundCloudPlugin } from "./SoundCloudPlugin";
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Spotify plugin for metadata extraction and display purposes.
|
|
56
|
-
*
|
|
57
|
-
* **Note:** This plugin only provides metadata extraction and does not support
|
|
58
|
-
* audio streaming. It uses Spotify's public oEmbed endpoint for display purposes.
|
|
59
|
-
*
|
|
60
|
-
* Provides support for:
|
|
61
|
-
* - Track URLs/URIs (spotify:track:...)
|
|
62
|
-
* - Playlist URLs/URIs (spotify:playlist:...)
|
|
63
|
-
* - Album URLs/URIs (spotify:album:...)
|
|
64
|
-
* - Metadata extraction using oEmbed API
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* const spotifyPlugin = new SpotifyPlugin();
|
|
68
|
-
* const result = await spotifyPlugin.search("spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "user123");
|
|
69
|
-
*/
|
|
70
|
-
export { SpotifyPlugin } from "./SpotifyPlugin";
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Text-to-Speech (TTS) plugin for converting text to audio.
|
|
74
|
-
*
|
|
75
|
-
* Provides comprehensive TTS functionality including:
|
|
76
|
-
* - Google TTS integration
|
|
77
|
-
* - Custom TTS provider support
|
|
78
|
-
* - Multiple language support
|
|
79
|
-
* - Configurable speech rate
|
|
80
|
-
* - Flexible query parsing
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* const ttsPlugin = new TTSPlugin({ defaultLang: "en" });
|
|
84
|
-
* const result = await ttsPlugin.search("tts:Hello world", "user123");
|
|
85
|
-
*/
|
|
86
|
-
export { TTSPlugin } from "./TTSPlugin";
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* YTSR plugin for advanced YouTube search without streaming.
|
|
90
|
-
*
|
|
91
|
-
* Provides comprehensive YouTube search functionality including:
|
|
92
|
-
* - Advanced video search with filters (duration, upload date, sort by)
|
|
93
|
-
* - Playlist and channel search
|
|
94
|
-
* - Multiple search types (video, playlist, channel, all)
|
|
95
|
-
* - Metadata extraction without streaming
|
|
96
|
-
* - Support for YouTube URLs
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* const ytsrPlugin = new YTSRPlugin();
|
|
100
|
-
* const result = await ytsrPlugin.search("Never Gonna Give You Up", "user123");
|
|
101
|
-
* const playlistResult = await ytsrPlugin.searchPlaylist("chill music", "user123");
|
|
102
|
-
*/
|
|
103
|
-
export { YTSRPlugin } from "./YTSRPlugin";
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Main export file for ZiPlayer plugins.
|
|
3
|
+
*
|
|
4
|
+
* This module exports all available plugins for the ZiPlayer music bot framework.
|
|
5
|
+
* Each plugin provides support for different audio sources and services.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { YouTubePlugin, SoundCloudPlugin, SpotifyPlugin, TTSPlugin } from "ziplayer/plugins";
|
|
9
|
+
*
|
|
10
|
+
* const manager = new PlayerManager({
|
|
11
|
+
* plugins: [
|
|
12
|
+
* new YouTubePlugin(),
|
|
13
|
+
* new SoundCloudPlugin(),
|
|
14
|
+
* new SpotifyPlugin(),
|
|
15
|
+
* new TTSPlugin({ defaultLang: "en" })
|
|
16
|
+
* ]
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* @since 1.0.0
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* YouTube plugin for handling YouTube videos, playlists, and search.
|
|
24
|
+
*
|
|
25
|
+
* Provides comprehensive support for YouTube content including:
|
|
26
|
+
* - Video URLs (youtube.com, youtu.be, music.youtube.com)
|
|
27
|
+
* - Playlist URLs and dynamic mixes
|
|
28
|
+
* - Search functionality
|
|
29
|
+
* - Audio stream extraction
|
|
30
|
+
* - Related track recommendations
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const youtubePlugin = new YouTubePlugin();
|
|
34
|
+
* const result = await youtubePlugin.search("Never Gonna Give You Up", "user123");
|
|
35
|
+
*/
|
|
36
|
+
export { YouTubePlugin } from "./YouTubePlugin";
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* SoundCloud plugin for handling SoundCloud tracks, playlists, and search.
|
|
40
|
+
*
|
|
41
|
+
* Provides comprehensive support for SoundCloud content including:
|
|
42
|
+
* - Track URLs (soundcloud.com)
|
|
43
|
+
* - Playlist URLs
|
|
44
|
+
* - Search functionality
|
|
45
|
+
* - Audio stream extraction
|
|
46
|
+
* - Related track recommendations
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const soundcloudPlugin = new SoundCloudPlugin();
|
|
50
|
+
* const result = await soundcloudPlugin.search("chill music", "user123");
|
|
51
|
+
*/
|
|
52
|
+
export { SoundCloudPlugin } from "./SoundCloudPlugin";
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Spotify plugin for metadata extraction and display purposes.
|
|
56
|
+
*
|
|
57
|
+
* **Note:** This plugin only provides metadata extraction and does not support
|
|
58
|
+
* audio streaming. It uses Spotify's public oEmbed endpoint for display purposes.
|
|
59
|
+
*
|
|
60
|
+
* Provides support for:
|
|
61
|
+
* - Track URLs/URIs (spotify:track:...)
|
|
62
|
+
* - Playlist URLs/URIs (spotify:playlist:...)
|
|
63
|
+
* - Album URLs/URIs (spotify:album:...)
|
|
64
|
+
* - Metadata extraction using oEmbed API
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* const spotifyPlugin = new SpotifyPlugin();
|
|
68
|
+
* const result = await spotifyPlugin.search("spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "user123");
|
|
69
|
+
*/
|
|
70
|
+
export { SpotifyPlugin } from "./SpotifyPlugin";
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Text-to-Speech (TTS) plugin for converting text to audio.
|
|
74
|
+
*
|
|
75
|
+
* Provides comprehensive TTS functionality including:
|
|
76
|
+
* - Google TTS integration
|
|
77
|
+
* - Custom TTS provider support
|
|
78
|
+
* - Multiple language support
|
|
79
|
+
* - Configurable speech rate
|
|
80
|
+
* - Flexible query parsing
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* const ttsPlugin = new TTSPlugin({ defaultLang: "en" });
|
|
84
|
+
* const result = await ttsPlugin.search("tts:Hello world", "user123");
|
|
85
|
+
*/
|
|
86
|
+
export { TTSPlugin } from "./TTSPlugin";
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* YTSR plugin for advanced YouTube search without streaming.
|
|
90
|
+
*
|
|
91
|
+
* Provides comprehensive YouTube search functionality including:
|
|
92
|
+
* - Advanced video search with filters (duration, upload date, sort by)
|
|
93
|
+
* - Playlist and channel search
|
|
94
|
+
* - Multiple search types (video, playlist, channel, all)
|
|
95
|
+
* - Metadata extraction without streaming
|
|
96
|
+
* - Support for YouTube URLs
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* const ytsrPlugin = new YTSRPlugin();
|
|
100
|
+
* const result = await ytsrPlugin.search("Never Gonna Give You Up", "user123");
|
|
101
|
+
* const playlistResult = await ytsrPlugin.searchPlaylist("chill music", "user123");
|
|
102
|
+
*/
|
|
103
|
+
export { YTSRPlugin } from "./YTSRPlugin";
|
package/tsconfig.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"lib": ["ES2020"],
|
|
6
|
-
"outDir": "./dist",
|
|
7
|
-
"rootDir": "./src",
|
|
8
|
-
"strict": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
"declaration": true,
|
|
13
|
-
"declarationMap": true,
|
|
14
|
-
"sourceMap": true,
|
|
15
|
-
"moduleResolution": "node",
|
|
16
|
-
"allowSyntheticDefaultImports": true,
|
|
17
|
-
"experimentalDecorators": true,
|
|
18
|
-
"emitDecoratorMetadata": true,
|
|
19
|
-
"resolveJsonModule": true
|
|
20
|
-
},
|
|
21
|
-
"include": ["src/*"],
|
|
22
|
-
"exclude": ["node_modules", "dist", "examples"]
|
|
23
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"lib": ["ES2020"],
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"rootDir": "./src",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"declarationMap": true,
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"moduleResolution": "node",
|
|
16
|
+
"allowSyntheticDefaultImports": true,
|
|
17
|
+
"experimentalDecorators": true,
|
|
18
|
+
"emitDecoratorMetadata": true,
|
|
19
|
+
"resolveJsonModule": true
|
|
20
|
+
},
|
|
21
|
+
"include": ["src/*"],
|
|
22
|
+
"exclude": ["node_modules", "dist", "examples"]
|
|
23
|
+
}
|