@ziplayer/plugin 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SoundCloudPlugin.d.ts +149 -0
- package/dist/SoundCloudPlugin.d.ts.map +1 -1
- package/dist/SoundCloudPlugin.js +149 -0
- package/dist/SoundCloudPlugin.js.map +1 -1
- package/dist/SpotifyPlugin.d.ts +127 -5
- package/dist/SpotifyPlugin.d.ts.map +1 -1
- package/dist/SpotifyPlugin.js +127 -5
- package/dist/SpotifyPlugin.js.map +1 -1
- package/dist/TTSPlugin.d.ts +123 -2
- package/dist/TTSPlugin.d.ts.map +1 -1
- package/dist/TTSPlugin.js +114 -0
- package/dist/TTSPlugin.js.map +1 -1
- package/dist/YouTubePlugin.d.ts +148 -0
- package/dist/YouTubePlugin.d.ts.map +1 -1
- package/dist/YouTubePlugin.js +148 -2
- package/dist/YouTubePlugin.js.map +1 -1
- package/dist/index.d.ts +78 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/SoundCloudPlugin.ts +149 -0
- package/src/SpotifyPlugin.ts +312 -190
- package/src/TTSPlugin.ts +130 -3
- package/src/YouTubePlugin.ts +528 -382
- package/src/index.ts +82 -0
package/src/SoundCloudPlugin.ts
CHANGED
|
@@ -14,12 +14,49 @@ function isValidSoundCloudHost(maybeUrl: string): boolean {
|
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
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
|
+
*/
|
|
17
44
|
export class SoundCloudPlugin extends BasePlugin {
|
|
18
45
|
name = "soundcloud";
|
|
19
46
|
version = "1.0.0";
|
|
20
47
|
private client: any;
|
|
21
48
|
private ready: Promise<void>;
|
|
22
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
|
+
*/
|
|
23
60
|
constructor() {
|
|
24
61
|
super();
|
|
25
62
|
this.ready = this.init();
|
|
@@ -30,6 +67,17 @@ export class SoundCloudPlugin extends BasePlugin {
|
|
|
30
67
|
await this.client.init();
|
|
31
68
|
}
|
|
32
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
|
+
*/
|
|
33
81
|
canHandle(query: string): boolean {
|
|
34
82
|
const q = (query || "").trim().toLowerCase();
|
|
35
83
|
const isUrl = q.startsWith("http://") || q.startsWith("https://");
|
|
@@ -46,10 +94,40 @@ export class SoundCloudPlugin extends BasePlugin {
|
|
|
46
94
|
return true;
|
|
47
95
|
}
|
|
48
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
|
+
*/
|
|
49
108
|
validate(url: string): boolean {
|
|
50
109
|
return isValidSoundCloudHost(url);
|
|
51
110
|
}
|
|
52
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
|
+
*/
|
|
53
131
|
async search(query: string, requestedBy: string): Promise<SearchResult> {
|
|
54
132
|
await this.ready;
|
|
55
133
|
|
|
@@ -130,6 +208,23 @@ export class SoundCloudPlugin extends BasePlugin {
|
|
|
130
208
|
}
|
|
131
209
|
}
|
|
132
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
|
+
*/
|
|
133
228
|
async getStream(track: Track): Promise<StreamInfo> {
|
|
134
229
|
await this.ready;
|
|
135
230
|
|
|
@@ -149,6 +244,27 @@ export class SoundCloudPlugin extends BasePlugin {
|
|
|
149
244
|
}
|
|
150
245
|
}
|
|
151
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
|
+
*/
|
|
152
268
|
async getRelatedTracks(
|
|
153
269
|
trackURL: string | number,
|
|
154
270
|
opts: { limit?: number; offset?: number; history?: Track[] } = {},
|
|
@@ -185,6 +301,25 @@ export class SoundCloudPlugin extends BasePlugin {
|
|
|
185
301
|
}
|
|
186
302
|
}
|
|
187
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
|
+
*/
|
|
188
323
|
async getFallback(track: Track): Promise<StreamInfo> {
|
|
189
324
|
const trackfall = await this.search(track.title, track.requestedBy);
|
|
190
325
|
const fallbackTrack = trackfall.tracks?.[0];
|
|
@@ -194,6 +329,20 @@ export class SoundCloudPlugin extends BasePlugin {
|
|
|
194
329
|
return await this.getStream(fallbackTrack);
|
|
195
330
|
}
|
|
196
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
|
+
*/
|
|
197
346
|
async extractPlaylist(url: string, requestedBy: string): Promise<Track[]> {
|
|
198
347
|
await this.ready;
|
|
199
348
|
try {
|