@zibot/scdl 0.1.0 → 0.1.1
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 +73 -102
- package/index.d.ts +148 -12
- package/index.js +1 -1
- package/package.json +2 -2
- package/test.js +24 -18
package/README.md
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
# @zibot/scdl
|
|
2
2
|
|
|
3
|
-
A tiny, promise-based Node.js client for searching SoundCloud, fetching track/playlist details, and downloading tracks as readable
|
|
3
|
+
A tiny, promise-based Node.js client for searching SoundCloud, fetching track/playlist details, and downloading tracks as readable
|
|
4
|
+
streams.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
- **Search** tracks, playlists, and users
|
|
7
|
+
- **Inspect** rich metadata for tracks and playlists
|
|
8
|
+
- **Download** a track stream (high/low quality)
|
|
9
|
+
- **Discover** related tracks by URL or ID
|
|
9
10
|
|
|
10
|
-
> ⚠️ Respect SoundCloud’s Terms of Service and creator rights. This library is for personal/educational use; don’t redistribute
|
|
11
|
+
> ⚠️ Respect SoundCloud’s Terms of Service and creator rights. This library is for personal/educational use; don’t redistribute
|
|
12
|
+
> copyrighted content without permission.
|
|
11
13
|
|
|
12
14
|
---
|
|
13
15
|
|
|
@@ -35,21 +37,21 @@ import SoundCloud from "@zibot/scdl";
|
|
|
35
37
|
const sc = new SoundCloud({ init: true }); // auto-initialize clientId
|
|
36
38
|
|
|
37
39
|
(async () => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
// Search tracks
|
|
41
|
+
const results = await sc.search({ query: "lofi hip hop", limit: 5, type: "tracks" });
|
|
42
|
+
console.log(results);
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
// Track details
|
|
45
|
+
const track = await sc.getTrackDetails("https://soundcloud.com/user/track-slug");
|
|
46
|
+
console.log(track.title, track.user.username);
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
// Download a track (Readable stream)
|
|
49
|
+
const stream = await sc.downloadTrack("https://soundcloud.com/user/track-slug", { quality: "high" });
|
|
50
|
+
stream.pipe(process.stdout); // or pipe to fs.createWriteStream("track.mp3")
|
|
49
51
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
// Related tracks
|
|
53
|
+
const related = await sc.getRelatedTracks(track.id, { limit: 10 });
|
|
54
|
+
console.log(related.map((t) => t.title));
|
|
53
55
|
})();
|
|
54
56
|
```
|
|
55
57
|
|
|
@@ -62,8 +64,8 @@ const fs = require("node:fs");
|
|
|
62
64
|
const sc = new SoundCloud({ init: true });
|
|
63
65
|
|
|
64
66
|
(async () => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
const stream = await sc.downloadTrack("https://soundcloud.com/user/track-slug");
|
|
68
|
+
stream.pipe(fs.createWriteStream("track.mp3"));
|
|
67
69
|
})();
|
|
68
70
|
```
|
|
69
71
|
|
|
@@ -82,7 +84,8 @@ const sc = new SoundCloud();
|
|
|
82
84
|
await sc.init(); // retrieves clientId
|
|
83
85
|
```
|
|
84
86
|
|
|
85
|
-
> You usually only need to call `init()` once per process. If you get authentication errors later, re-calling `init()` may refresh
|
|
87
|
+
> You usually only need to call `init()` once per process. If you get authentication errors later, re-calling `init()` may refresh
|
|
88
|
+
> the client ID.
|
|
86
89
|
|
|
87
90
|
---
|
|
88
91
|
|
|
@@ -92,12 +95,12 @@ await sc.init(); // retrieves clientId
|
|
|
92
95
|
|
|
93
96
|
Create a client.
|
|
94
97
|
|
|
95
|
-
|
|
98
|
+
- `options.init?: boolean` – if `true`, calls `init()` internally.
|
|
96
99
|
|
|
97
100
|
**Properties**
|
|
98
101
|
|
|
99
|
-
|
|
100
|
-
|
|
102
|
+
- `clientId: string | null` – resolved after `init()`
|
|
103
|
+
- `apiBaseUrl: string` – internal base URL used for API calls
|
|
101
104
|
|
|
102
105
|
---
|
|
103
106
|
|
|
@@ -107,25 +110,25 @@ Initialize the client (retrieve `clientId`). Call this if you didn’t pass `{ i
|
|
|
107
110
|
|
|
108
111
|
---
|
|
109
112
|
|
|
110
|
-
### `
|
|
113
|
+
### `search(options: SearchOptions): Promise<(Track | Playlist | User)[]>`
|
|
111
114
|
|
|
112
115
|
Search SoundCloud.
|
|
113
116
|
|
|
114
117
|
**Parameters – `SearchOptions`**
|
|
115
118
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
119
|
+
- `query: string` – search text
|
|
120
|
+
- `limit?: number` – default depends on endpoint (commonly 10–20)
|
|
121
|
+
- `offset?: number` – for pagination
|
|
122
|
+
- `type?: "all" | "tracks" | "playlists" | "users"` – filter result kinds (default `"all"`)
|
|
120
123
|
|
|
121
124
|
**Usage**
|
|
122
125
|
|
|
123
126
|
```ts
|
|
124
127
|
// Top tracks
|
|
125
|
-
const tracks = await sc.
|
|
128
|
+
const tracks = await sc.search({ query: "ambient study", type: "tracks", limit: 10 });
|
|
126
129
|
|
|
127
130
|
// Mixed kinds (tracks/playlists/users)
|
|
128
|
-
const mixed = await sc.
|
|
131
|
+
const mixed = await sc.search({ query: "chill", type: "all", limit: 5, offset: 5 });
|
|
129
132
|
```
|
|
130
133
|
|
|
131
134
|
---
|
|
@@ -137,30 +140,12 @@ Get rich metadata for a single track by its public URL.
|
|
|
137
140
|
```ts
|
|
138
141
|
const t = await sc.getTrackDetails("https://soundcloud.com/artist/track");
|
|
139
142
|
console.log({
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
streamables: t.media.transcodings.length,
|
|
143
|
+
id: t.id,
|
|
144
|
+
title: t.title,
|
|
145
|
+
url: t.permalink_url,
|
|
144
146
|
});
|
|
145
147
|
```
|
|
146
148
|
|
|
147
|
-
**`Track`**
|
|
148
|
-
|
|
149
|
-
```ts
|
|
150
|
-
interface Track {
|
|
151
|
-
id: number;
|
|
152
|
-
title: string;
|
|
153
|
-
url: string;
|
|
154
|
-
user: { id: number; username: string };
|
|
155
|
-
media: {
|
|
156
|
-
transcodings: {
|
|
157
|
-
url: string;
|
|
158
|
-
format: { protocol: string; mime_type: string };
|
|
159
|
-
}[];
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
```
|
|
163
|
-
|
|
164
149
|
---
|
|
165
150
|
|
|
166
151
|
### `getPlaylistDetails(url: string): Promise<Playlist>`
|
|
@@ -172,16 +157,6 @@ const pl = await sc.getPlaylistDetails("https://soundcloud.com/artist/sets/playl
|
|
|
172
157
|
console.log(pl.title, pl.tracks.length);
|
|
173
158
|
```
|
|
174
159
|
|
|
175
|
-
**`Playlist`**
|
|
176
|
-
|
|
177
|
-
```ts
|
|
178
|
-
interface Playlist {
|
|
179
|
-
id: number;
|
|
180
|
-
title: string;
|
|
181
|
-
tracks: Track[];
|
|
182
|
-
}
|
|
183
|
-
```
|
|
184
|
-
|
|
185
160
|
---
|
|
186
161
|
|
|
187
162
|
### `downloadTrack(url: string, options?: DownloadOptions): Promise<Readable>`
|
|
@@ -190,7 +165,7 @@ Download a track as a Node `Readable` stream.
|
|
|
190
165
|
|
|
191
166
|
**Parameters – `DownloadOptions`**
|
|
192
167
|
|
|
193
|
-
|
|
168
|
+
- `quality?: "high" | "low"` – choose available transcoding (default implementation prefers higher quality when available)
|
|
194
169
|
|
|
195
170
|
**Examples**
|
|
196
171
|
|
|
@@ -199,9 +174,7 @@ import fs from "node:fs";
|
|
|
199
174
|
|
|
200
175
|
const read = await sc.downloadTrack("https://soundcloud.com/user/track", { quality: "high" });
|
|
201
176
|
await new Promise((resolve, reject) => {
|
|
202
|
-
|
|
203
|
-
.on("finish", resolve)
|
|
204
|
-
.on("error", reject);
|
|
177
|
+
read.pipe(fs.createWriteStream("track.ts")).on("finish", resolve).on("error", reject);
|
|
205
178
|
});
|
|
206
179
|
```
|
|
207
180
|
|
|
@@ -228,21 +201,21 @@ const relById = await sc.getRelatedTracks(base.id, { limit: 6 });
|
|
|
228
201
|
|
|
229
202
|
```ts
|
|
230
203
|
export interface SearchOptions {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
204
|
+
query: string;
|
|
205
|
+
limit?: number;
|
|
206
|
+
offset?: number;
|
|
207
|
+
type?: "all" | "tracks" | "playlists" | "users";
|
|
235
208
|
}
|
|
236
209
|
|
|
237
210
|
export interface DownloadOptions {
|
|
238
|
-
|
|
211
|
+
quality?: "high" | "low";
|
|
239
212
|
}
|
|
240
213
|
|
|
241
214
|
export interface User {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
215
|
+
id: number;
|
|
216
|
+
username: string;
|
|
217
|
+
followers_count: number;
|
|
218
|
+
track_count: number;
|
|
246
219
|
}
|
|
247
220
|
```
|
|
248
221
|
|
|
@@ -261,56 +234,53 @@ import SoundCloud from "@zibot/scdl";
|
|
|
261
234
|
const sc = new SoundCloud({ init: true });
|
|
262
235
|
|
|
263
236
|
async function save(url: string, file: string) {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
.on("error", reject);
|
|
269
|
-
});
|
|
237
|
+
const stream = await sc.downloadTrack(url, { quality: "high" });
|
|
238
|
+
await new Promise<void>((resolve, reject) => {
|
|
239
|
+
stream.pipe(fs.createWriteStream(file)).on("finish", resolve).on("error", reject);
|
|
240
|
+
});
|
|
270
241
|
}
|
|
271
242
|
|
|
272
|
-
save("https://soundcloud.com/user/track", "output.
|
|
243
|
+
save("https://soundcloud.com/user/track", "output.ts");
|
|
273
244
|
```
|
|
274
245
|
|
|
275
246
|
### Basic search → pick first result → download
|
|
276
247
|
|
|
277
248
|
```ts
|
|
278
|
-
const [first] = await sc.
|
|
249
|
+
const [first] = await sc.search({ query: "deep house 2024", type: "tracks", limit: 1 });
|
|
279
250
|
if (first && "url" in first) {
|
|
280
|
-
|
|
281
|
-
|
|
251
|
+
const s = await sc.downloadTrack(first.url);
|
|
252
|
+
s.pipe(process.stdout);
|
|
282
253
|
}
|
|
283
254
|
```
|
|
284
255
|
|
|
285
256
|
### Paginate results
|
|
286
257
|
|
|
287
258
|
```ts
|
|
288
|
-
const page1 = await sc.
|
|
289
|
-
const page2 = await sc.
|
|
259
|
+
const page1 = await sc.search({ query: "vaporwave", type: "tracks", limit: 20, offset: 0 });
|
|
260
|
+
const page2 = await sc.search({ query: "vaporwave", type: "tracks", limit: 20, offset: 20 });
|
|
290
261
|
```
|
|
291
262
|
|
|
292
263
|
---
|
|
293
264
|
|
|
294
265
|
## Error Handling & Tips
|
|
295
266
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
267
|
+
- **Initialization:** If a method throws due to missing/expired `clientId`, call `await sc.init()` and retry.
|
|
268
|
+
- **Quality selection:** Not all tracks expose multiple transcodings; the library will fall back when needed.
|
|
269
|
+
- **Rate limits / 429:** Back off and retry with an exponential strategy.
|
|
270
|
+
- **Private/geo-restricted tracks:** Details/downloads may be unavailable.
|
|
271
|
+
- **Networking:** Wrap downloads with proper error and close handlers to avoid dangling file descriptors.
|
|
301
272
|
|
|
302
273
|
---
|
|
303
274
|
|
|
304
275
|
## FAQ
|
|
305
276
|
|
|
306
|
-
**Q: Can I use this in the browser?**
|
|
307
|
-
This package targets Node.js (it returns Node `Readable`). Browser use is not supported.
|
|
277
|
+
**Q: Can I use this in the browser?** This package targets Node.js (it returns Node `Readable`). Browser use is not supported.
|
|
308
278
|
|
|
309
|
-
**Q: What audio format do I get?**
|
|
310
|
-
|
|
279
|
+
**Q: What audio format do I get?** Whatever the selected transcoding provides (commonly progressive MP3 or HLS AAC). You may need
|
|
280
|
+
to remux/encode if you require a specific container/codec.
|
|
311
281
|
|
|
312
|
-
**Q: Do I need my own client ID?**
|
|
313
|
-
|
|
282
|
+
**Q: Do I need my own client ID?** The client auto-discovers a valid `clientId`. If discovery fails due to upstream changes,
|
|
283
|
+
update the package to the latest version.
|
|
314
284
|
|
|
315
285
|
---
|
|
316
286
|
|
|
@@ -318,9 +288,9 @@ The client auto-discovers a valid `clientId`. If discovery fails due to upstream
|
|
|
318
288
|
|
|
319
289
|
PRs and issues are welcome! Please include:
|
|
320
290
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
291
|
+
- A clear description of the change
|
|
292
|
+
- Repro steps (for bugs)
|
|
293
|
+
- Tests where possible
|
|
324
294
|
|
|
325
295
|
---
|
|
326
296
|
|
|
@@ -332,4 +302,5 @@ MIT © Zibot
|
|
|
332
302
|
|
|
333
303
|
## Disclaimer
|
|
334
304
|
|
|
335
|
-
This project is not affiliated with SoundCloud. Use responsibly and comply with all applicable laws and SoundCloud’s Terms of
|
|
305
|
+
This project is not affiliated with SoundCloud. Use responsibly and comply with all applicable laws and SoundCloud’s Terms of
|
|
306
|
+
Service.
|
package/index.d.ts
CHANGED
|
@@ -13,36 +13,172 @@ export interface DownloadOptions {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export interface Track {
|
|
16
|
+
artwork_url: string | null;
|
|
17
|
+
caption: string | null;
|
|
18
|
+
commentable: boolean;
|
|
19
|
+
comment_count: number;
|
|
20
|
+
created_at: string;
|
|
21
|
+
description: string | null;
|
|
22
|
+
downloadable: boolean;
|
|
23
|
+
download_count: number;
|
|
24
|
+
duration: number;
|
|
25
|
+
full_duration: number;
|
|
26
|
+
embeddable_by: string;
|
|
27
|
+
genre: string;
|
|
28
|
+
has_downloads_left: boolean;
|
|
16
29
|
id: number;
|
|
30
|
+
kind: string;
|
|
31
|
+
label_name: string | null;
|
|
32
|
+
last_modified: string;
|
|
33
|
+
license: string;
|
|
34
|
+
likes_count: number;
|
|
35
|
+
permalink: string;
|
|
36
|
+
permalink_url: string;
|
|
37
|
+
playback_count: number;
|
|
38
|
+
public: boolean;
|
|
39
|
+
publisher_metadata: PublisherMetadata | null;
|
|
40
|
+
purchase_title: string | null;
|
|
41
|
+
purchase_url: string | null;
|
|
42
|
+
release_date: string | null;
|
|
43
|
+
reposts_count: number;
|
|
44
|
+
secret_token: string | null;
|
|
45
|
+
sharing: string;
|
|
46
|
+
state: "finished" | "processing" | "failed" | string;
|
|
47
|
+
streamable: boolean;
|
|
48
|
+
tag_list: string;
|
|
17
49
|
title: string;
|
|
18
|
-
|
|
19
|
-
|
|
50
|
+
uri: string;
|
|
51
|
+
urn: string;
|
|
52
|
+
user_id: number;
|
|
53
|
+
visuals: any | null;
|
|
54
|
+
waveform_url: string;
|
|
55
|
+
display_date: string;
|
|
20
56
|
media: {
|
|
21
|
-
transcodings:
|
|
22
|
-
url: string;
|
|
23
|
-
format: { protocol: string; mime_type: string };
|
|
24
|
-
}[];
|
|
57
|
+
transcodings: Transcoding[];
|
|
25
58
|
};
|
|
59
|
+
station_urn: string;
|
|
60
|
+
station_permalink: string;
|
|
61
|
+
track_authorization: string;
|
|
62
|
+
monetization_model: string;
|
|
63
|
+
policy: string;
|
|
64
|
+
user: User;
|
|
26
65
|
}
|
|
27
66
|
|
|
28
|
-
export interface
|
|
67
|
+
export interface PublisherMetadata {
|
|
29
68
|
id: number;
|
|
30
|
-
|
|
31
|
-
|
|
69
|
+
urn: string;
|
|
70
|
+
contains_music: boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface Transcoding {
|
|
74
|
+
url: string;
|
|
75
|
+
preset: string;
|
|
76
|
+
duration: number;
|
|
77
|
+
snipped: boolean;
|
|
78
|
+
format: {
|
|
79
|
+
protocol: string;
|
|
80
|
+
mime_type: string;
|
|
81
|
+
};
|
|
82
|
+
quality: string;
|
|
32
83
|
}
|
|
33
84
|
|
|
34
85
|
export interface User {
|
|
86
|
+
avatar_url: string;
|
|
87
|
+
city: string | null;
|
|
88
|
+
comments_count: number;
|
|
89
|
+
country_code: string | null;
|
|
90
|
+
created_at: string | null;
|
|
91
|
+
creator_subscriptions: any[];
|
|
92
|
+
creator_subscription: {
|
|
93
|
+
product: { id: string; [key: string]: any };
|
|
94
|
+
};
|
|
95
|
+
description: string | null;
|
|
96
|
+
followers_count: number;
|
|
97
|
+
followings_count: number;
|
|
98
|
+
first_name: string;
|
|
99
|
+
full_name: string;
|
|
100
|
+
groups_count: number;
|
|
35
101
|
id: number;
|
|
102
|
+
kind: string;
|
|
103
|
+
last_modified: string;
|
|
104
|
+
last_name: string;
|
|
105
|
+
likes_count: number;
|
|
106
|
+
playlist_likes_count: number;
|
|
107
|
+
permalink: string;
|
|
108
|
+
permalink_url: string;
|
|
109
|
+
playlist_count: number;
|
|
110
|
+
reposts_count: number | null;
|
|
111
|
+
track_count: number;
|
|
112
|
+
uri: string;
|
|
113
|
+
urn: string;
|
|
36
114
|
username: string;
|
|
37
|
-
|
|
115
|
+
verified: boolean;
|
|
116
|
+
visuals: {
|
|
117
|
+
urn: string;
|
|
118
|
+
enabled: boolean;
|
|
119
|
+
visuals: any[];
|
|
120
|
+
tracking: any | null;
|
|
121
|
+
} | null;
|
|
122
|
+
badges: {
|
|
123
|
+
pro: boolean;
|
|
124
|
+
creator_mid_tier: boolean;
|
|
125
|
+
pro_unlimited: boolean;
|
|
126
|
+
verified: boolean;
|
|
127
|
+
};
|
|
128
|
+
station_urn: string;
|
|
129
|
+
station_permalink: string;
|
|
130
|
+
date_of_birth: string | null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface Playlist {
|
|
134
|
+
artwork_url: string | null;
|
|
135
|
+
created_at: string;
|
|
136
|
+
description: string | null;
|
|
137
|
+
duration: number;
|
|
138
|
+
embeddable_by: string;
|
|
139
|
+
genre: string;
|
|
140
|
+
id: number;
|
|
141
|
+
kind: "playlist" | string;
|
|
142
|
+
label_name: string | null;
|
|
143
|
+
last_modified: string;
|
|
144
|
+
license: string;
|
|
145
|
+
likes_count: number;
|
|
146
|
+
managed_by_feeds: boolean;
|
|
147
|
+
permalink: string;
|
|
148
|
+
permalink_url: string;
|
|
149
|
+
public: boolean;
|
|
150
|
+
purchase_title: string | null;
|
|
151
|
+
purchase_url: string | null;
|
|
152
|
+
release_date: string | null;
|
|
153
|
+
reposts_count: number;
|
|
154
|
+
secret_token: string | null;
|
|
155
|
+
sharing: string;
|
|
156
|
+
tag_list: string;
|
|
157
|
+
title: string;
|
|
158
|
+
uri: string;
|
|
159
|
+
user_id: number;
|
|
160
|
+
set_type: string;
|
|
161
|
+
is_album: boolean;
|
|
162
|
+
published_at: string | null;
|
|
163
|
+
display_date: string;
|
|
164
|
+
user: User;
|
|
165
|
+
tracks: Track[];
|
|
38
166
|
track_count: number;
|
|
39
167
|
}
|
|
40
168
|
|
|
41
169
|
declare class SoundCloud {
|
|
42
170
|
clientId: string | null;
|
|
43
171
|
apiBaseUrl: string;
|
|
172
|
+
appVersion: number;
|
|
44
173
|
|
|
45
|
-
constructor(options?: {
|
|
174
|
+
constructor(options?: {
|
|
175
|
+
init?: boolean;
|
|
176
|
+
autoInit: boolean;
|
|
177
|
+
apiBaseUrl: string;
|
|
178
|
+
timeout: number;
|
|
179
|
+
onClientId: null;
|
|
180
|
+
clientId: null;
|
|
181
|
+
});
|
|
46
182
|
|
|
47
183
|
/**
|
|
48
184
|
* Initialize the SoundCloud client to retrieve clientId.
|
|
@@ -52,7 +188,7 @@ declare class SoundCloud {
|
|
|
52
188
|
/**
|
|
53
189
|
* Search for tracks, playlists, or users on SoundCloud.
|
|
54
190
|
*/
|
|
55
|
-
|
|
191
|
+
search(options: SearchOptions): Promise<(Track | Playlist | User)[]>;
|
|
56
192
|
|
|
57
193
|
/**
|
|
58
194
|
* Retrieve detailed information about a single track.
|
package/index.js
CHANGED
|
@@ -124,7 +124,7 @@ class SoundCloud {
|
|
|
124
124
|
return this.clientId;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
async
|
|
127
|
+
async search({ query, limit = 30, offset = 0, type = "all" }) {
|
|
128
128
|
await this.ensureReady();
|
|
129
129
|
const path = type === "all" ? "" : `/${type}`;
|
|
130
130
|
const url =
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zibot/scdl",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Soucloud download",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://github.com/ZiProject/scdl#readme",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"axios": "^1.
|
|
28
|
+
"axios": "^1.15.0",
|
|
29
29
|
"events": "^3.3.0",
|
|
30
30
|
"m3u8stream": "^0.8.6"
|
|
31
31
|
}
|
package/test.js
CHANGED
|
@@ -6,31 +6,37 @@ const sc = new SoundCloud();
|
|
|
6
6
|
|
|
7
7
|
(async () => {
|
|
8
8
|
try {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const Search = await sc.getPlaylistDetails(
|
|
10
|
+
"https://soundcloud.com/atniexvnk0ry/sets/c2nk5mokbmad?si=469007ce80c5418a93f7df6d8a431c51&utm_source=clipboard&utm_medium=text&utm_campaign=social_sharing",
|
|
11
|
+
);
|
|
12
|
+
console.log("Thông tin bài hát:", Search);
|
|
13
|
+
// const getRelatedTracks = await sc.getRelatedTracks(Search.uri);
|
|
14
|
+
// console.log("Các bài hát liên quan:", getRelatedTracks);
|
|
15
|
+
// console.log("Đang khởi tạo và lấy stream...");
|
|
16
|
+
// const url = "https://soundcloud.com/jar-chow-794199690/etoilesong-by-vermementomori-ost";
|
|
11
17
|
|
|
12
|
-
const stream = await sc.downloadTrack(url);
|
|
18
|
+
// const stream = await sc.downloadTrack(url);
|
|
13
19
|
|
|
14
|
-
if (!stream) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
20
|
+
// if (!stream) {
|
|
21
|
+
// console.error("Không lấy được stream.");
|
|
22
|
+
// return;
|
|
23
|
+
// }
|
|
18
24
|
|
|
19
|
-
const filename = "track.ts"; // HLS thường là định dạng MPEG-TS
|
|
20
|
-
const writeStream = fs.createWriteStream(filename);
|
|
25
|
+
// const filename = "track.ts"; // HLS thường là định dạng MPEG-TS
|
|
26
|
+
// const writeStream = fs.createWriteStream(filename);
|
|
21
27
|
|
|
22
|
-
console.log("Đang tải dữ liệu...");
|
|
28
|
+
// console.log("Đang tải dữ liệu...");
|
|
23
29
|
|
|
24
|
-
// Theo dõi tiến trình (optional)
|
|
25
|
-
let downloaded = 0;
|
|
26
|
-
stream.on("data", (chunk) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
+
// // Theo dõi tiến trình (optional)
|
|
31
|
+
// let downloaded = 0;
|
|
32
|
+
// stream.on("data", (chunk) => {
|
|
33
|
+
// downloaded += chunk.length;
|
|
34
|
+
// process.stdout.write(`\rĐã tải: ${(downloaded / 1024).toFixed(2)} KB`);
|
|
35
|
+
// });
|
|
30
36
|
|
|
31
|
-
await pipeline(stream, writeStream);
|
|
37
|
+
// await pipeline(stream, writeStream);
|
|
32
38
|
|
|
33
|
-
console.log(`\n✅ Tải xong! File lưu tại: ${filename}`);
|
|
39
|
+
// console.log(`\n✅ Tải xong! File lưu tại: ${filename}`);
|
|
34
40
|
} catch (err) {
|
|
35
41
|
console.error("\n❌ Lỗi trong quá trình tải:", err.message);
|
|
36
42
|
}
|