@zibot/scdl 0.0.5 → 0.0.6
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/.prettierrc +21 -0
- package/README.md +272 -55
- package/index.js +1 -0
- package/package.json +32 -35
package/.prettierrc
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"arrowParens": "always",
|
|
3
|
+
"bracketSameLine": true,
|
|
4
|
+
"bracketSpacing": true,
|
|
5
|
+
"semi": true,
|
|
6
|
+
"experimentalTernaries": true,
|
|
7
|
+
"singleQuote": false,
|
|
8
|
+
"jsxSingleQuote": true,
|
|
9
|
+
"quoteProps": "as-needed",
|
|
10
|
+
"trailingComma": "all",
|
|
11
|
+
"singleAttributePerLine": true,
|
|
12
|
+
"htmlWhitespaceSensitivity": "css",
|
|
13
|
+
"vueIndentScriptAndStyle": false,
|
|
14
|
+
"proseWrap": "always",
|
|
15
|
+
"insertPragma": false,
|
|
16
|
+
"printWidth": 130,
|
|
17
|
+
"requirePragma": false,
|
|
18
|
+
"tabWidth": 2,
|
|
19
|
+
"useTabs": true,
|
|
20
|
+
"embeddedLanguageFormatting": "auto"
|
|
21
|
+
}
|
package/README.md
CHANGED
|
@@ -1,118 +1,335 @@
|
|
|
1
1
|
# @zibot/scdl
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
phương thức tiện lợi để xử lý track, playlist, và tải nội dung.
|
|
3
|
+
A tiny, promise-based Node.js client for searching SoundCloud, fetching track/playlist details, and downloading tracks as readable streams.
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
* **Search** tracks, playlists, and users
|
|
6
|
+
* **Inspect** rich metadata for tracks and playlists
|
|
7
|
+
* **Download** a track stream (high/low quality)
|
|
8
|
+
* **Discover** related tracks by URL or ID
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
> ⚠️ Respect SoundCloud’s Terms of Service and creator rights. This library is for personal/educational use; don’t redistribute copyrighted content without permission.
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
npm install @zibot/scdl
|
|
12
|
-
```
|
|
12
|
+
---
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
## Installation
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
|
+
npm i @zibot/scdl
|
|
18
|
+
# or
|
|
17
19
|
yarn add @zibot/scdl
|
|
20
|
+
# or
|
|
21
|
+
pnpm add @zibot/scdl
|
|
18
22
|
```
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
**Runtime:** Node.js 18+ is recommended (built-in `fetch`/WHATWG streams). Works with ESM or CommonJS.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
### ESM
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import SoundCloud from "@zibot/scdl";
|
|
34
|
+
|
|
35
|
+
const sc = new SoundCloud({ init: true }); // auto-initialize clientId
|
|
36
|
+
|
|
37
|
+
(async () => {
|
|
38
|
+
// Search tracks
|
|
39
|
+
const results = await sc.searchTracks({ query: "lofi hip hop", limit: 5, type: "tracks" });
|
|
40
|
+
console.log(results);
|
|
41
|
+
|
|
42
|
+
// Track details
|
|
43
|
+
const track = await sc.getTrackDetails("https://soundcloud.com/user/track-slug");
|
|
44
|
+
console.log(track.title, track.user.username);
|
|
45
|
+
|
|
46
|
+
// Download a track (Readable stream)
|
|
47
|
+
const stream = await sc.downloadTrack("https://soundcloud.com/user/track-slug", { quality: "high" });
|
|
48
|
+
stream.pipe(process.stdout); // or pipe to fs.createWriteStream("track.mp3")
|
|
49
|
+
|
|
50
|
+
// Related tracks
|
|
51
|
+
const related = await sc.getRelatedTracks(track.id, { limit: 10 });
|
|
52
|
+
console.log(related.map(t => t.title));
|
|
53
|
+
})();
|
|
54
|
+
```
|
|
21
55
|
|
|
22
|
-
###
|
|
56
|
+
### CommonJS
|
|
23
57
|
|
|
24
|
-
|
|
58
|
+
```js
|
|
59
|
+
const SoundCloud = require("@zibot/scdl");
|
|
60
|
+
const fs = require("node:fs");
|
|
25
61
|
|
|
26
|
-
|
|
27
|
-
const { SoundCloud } = require("@zibot/scdl");
|
|
62
|
+
const sc = new SoundCloud({ init: true });
|
|
28
63
|
|
|
29
64
|
(async () => {
|
|
30
|
-
|
|
31
|
-
|
|
65
|
+
const stream = await sc.downloadTrack("https://soundcloud.com/user/track-slug");
|
|
66
|
+
stream.pipe(fs.createWriteStream("track.mp3"));
|
|
32
67
|
})();
|
|
33
68
|
```
|
|
34
69
|
|
|
35
70
|
---
|
|
36
71
|
|
|
37
|
-
|
|
72
|
+
## Initialization
|
|
38
73
|
|
|
39
|
-
|
|
74
|
+
The client can retrieve a valid `clientId` automatically.
|
|
40
75
|
|
|
41
|
-
|
|
76
|
+
```ts
|
|
77
|
+
// Option A: auto-init (recommended)
|
|
78
|
+
const sc = new SoundCloud({ init: true });
|
|
42
79
|
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
80
|
+
// Option B: manual init
|
|
81
|
+
const sc = new SoundCloud();
|
|
82
|
+
await sc.init(); // retrieves clientId
|
|
46
83
|
```
|
|
47
84
|
|
|
48
|
-
|
|
85
|
+
> You usually only need to call `init()` once per process. If you get authentication errors later, re-calling `init()` may refresh the client ID.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## API
|
|
90
|
+
|
|
91
|
+
### `new SoundCloud(options?)`
|
|
49
92
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
93
|
+
Create a client.
|
|
94
|
+
|
|
95
|
+
* `options.init?: boolean` – if `true`, calls `init()` internally.
|
|
96
|
+
|
|
97
|
+
**Properties**
|
|
98
|
+
|
|
99
|
+
* `clientId: string | null` – resolved after `init()`
|
|
100
|
+
* `apiBaseUrl: string` – internal base URL used for API calls
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
### `init(): Promise<void>`
|
|
105
|
+
|
|
106
|
+
Initialize the client (retrieve `clientId`). Call this if you didn’t pass `{ init: true }`.
|
|
53
107
|
|
|
54
108
|
---
|
|
55
109
|
|
|
56
|
-
|
|
110
|
+
### `searchTracks(options: SearchOptions): Promise<(Track | Playlist | User)[]>`
|
|
111
|
+
|
|
112
|
+
Search SoundCloud.
|
|
113
|
+
|
|
114
|
+
**Parameters – `SearchOptions`**
|
|
115
|
+
|
|
116
|
+
* `query: string` – search text
|
|
117
|
+
* `limit?: number` – default depends on endpoint (commonly 10–20)
|
|
118
|
+
* `offset?: number` – for pagination
|
|
119
|
+
* `type?: "all" | "tracks" | "playlists" | "users"` – filter result kinds (default `"all"`)
|
|
57
120
|
|
|
58
|
-
|
|
121
|
+
**Usage**
|
|
59
122
|
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
|
|
123
|
+
```ts
|
|
124
|
+
// Top tracks
|
|
125
|
+
const tracks = await sc.searchTracks({ query: "ambient study", type: "tracks", limit: 10 });
|
|
126
|
+
|
|
127
|
+
// Mixed kinds (tracks/playlists/users)
|
|
128
|
+
const mixed = await sc.searchTracks({ query: "chill", type: "all", limit: 5, offset: 5 });
|
|
63
129
|
```
|
|
64
130
|
|
|
65
|
-
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
### `getTrackDetails(url: string): Promise<Track>`
|
|
134
|
+
|
|
135
|
+
Get rich metadata for a single track by its public URL.
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
const t = await sc.getTrackDetails("https://soundcloud.com/artist/track");
|
|
139
|
+
console.log({
|
|
140
|
+
id: t.id,
|
|
141
|
+
title: t.title,
|
|
142
|
+
by: t.user.username,
|
|
143
|
+
streamables: t.media.transcodings.length,
|
|
144
|
+
});
|
|
145
|
+
```
|
|
66
146
|
|
|
67
|
-
|
|
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
|
+
```
|
|
68
163
|
|
|
69
164
|
---
|
|
70
165
|
|
|
71
|
-
|
|
166
|
+
### `getPlaylistDetails(url: string): Promise<Playlist>`
|
|
72
167
|
|
|
73
|
-
|
|
168
|
+
Fetch playlist metadata and contained tracks.
|
|
74
169
|
|
|
75
|
-
```
|
|
76
|
-
const
|
|
77
|
-
console.log(
|
|
170
|
+
```ts
|
|
171
|
+
const pl = await sc.getPlaylistDetails("https://soundcloud.com/artist/sets/playlist-slug");
|
|
172
|
+
console.log(pl.title, pl.tracks.length);
|
|
78
173
|
```
|
|
79
174
|
|
|
80
|
-
|
|
175
|
+
**`Playlist`**
|
|
81
176
|
|
|
82
|
-
|
|
177
|
+
```ts
|
|
178
|
+
interface Playlist {
|
|
179
|
+
id: number;
|
|
180
|
+
title: string;
|
|
181
|
+
tracks: Track[];
|
|
182
|
+
}
|
|
183
|
+
```
|
|
83
184
|
|
|
84
185
|
---
|
|
85
186
|
|
|
86
|
-
|
|
187
|
+
### `downloadTrack(url: string, options?: DownloadOptions): Promise<Readable>`
|
|
188
|
+
|
|
189
|
+
Download a track as a Node `Readable` stream.
|
|
190
|
+
|
|
191
|
+
**Parameters – `DownloadOptions`**
|
|
87
192
|
|
|
88
|
-
|
|
193
|
+
* `quality?: "high" | "low"` – choose available transcoding (default implementation prefers higher quality when available)
|
|
89
194
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
195
|
+
**Examples**
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
import fs from "node:fs";
|
|
199
|
+
|
|
200
|
+
const read = await sc.downloadTrack("https://soundcloud.com/user/track", { quality: "high" });
|
|
201
|
+
await new Promise((resolve, reject) => {
|
|
202
|
+
read.pipe(fs.createWriteStream("track.mp3"))
|
|
203
|
+
.on("finish", resolve)
|
|
204
|
+
.on("error", reject);
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Pipe to any writable destination (stdout, HTTP response, cloud storage SDKs, etc.).
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
### `getRelatedTracks(track: string | number, opts?: { limit?: number; offset?: number }): Promise<Track[]>`
|
|
213
|
+
|
|
214
|
+
Fetch tracks related to a given track by **URL** or **numeric ID**.
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
// by URL
|
|
218
|
+
const relByUrl = await sc.getRelatedTracks("https://soundcloud.com/artist/track", { limit: 6 });
|
|
219
|
+
|
|
220
|
+
// by ID
|
|
221
|
+
const base = await sc.getTrackDetails("https://soundcloud.com/artist/track");
|
|
222
|
+
const relById = await sc.getRelatedTracks(base.id, { limit: 6 });
|
|
93
223
|
```
|
|
94
224
|
|
|
95
|
-
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## Types
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
export interface SearchOptions {
|
|
231
|
+
query: string;
|
|
232
|
+
limit?: number;
|
|
233
|
+
offset?: number;
|
|
234
|
+
type?: "all" | "tracks" | "playlists" | "users";
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export interface DownloadOptions {
|
|
238
|
+
quality?: "high" | "low";
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export interface User {
|
|
242
|
+
id: number;
|
|
243
|
+
username: string;
|
|
244
|
+
followers_count: number;
|
|
245
|
+
track_count: number;
|
|
246
|
+
}
|
|
247
|
+
```
|
|
96
248
|
|
|
97
|
-
|
|
98
|
-
- `options` (tùy chọn): Cấu hình tải xuống.
|
|
249
|
+
These types are exported for TypeScript consumers.
|
|
99
250
|
|
|
100
251
|
---
|
|
101
252
|
|
|
102
|
-
|
|
253
|
+
## Examples
|
|
254
|
+
|
|
255
|
+
### Save the highest-quality stream to disk
|
|
256
|
+
|
|
257
|
+
```ts
|
|
258
|
+
import fs from "node:fs";
|
|
259
|
+
import SoundCloud from "@zibot/scdl";
|
|
260
|
+
|
|
261
|
+
const sc = new SoundCloud({ init: true });
|
|
262
|
+
|
|
263
|
+
async function save(url: string, file: string) {
|
|
264
|
+
const stream = await sc.downloadTrack(url, { quality: "high" });
|
|
265
|
+
await new Promise<void>((resolve, reject) => {
|
|
266
|
+
stream.pipe(fs.createWriteStream(file))
|
|
267
|
+
.on("finish", resolve)
|
|
268
|
+
.on("error", reject);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
save("https://soundcloud.com/user/track", "output.mp3");
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Basic search → pick first result → download
|
|
276
|
+
|
|
277
|
+
```ts
|
|
278
|
+
const [first] = await sc.searchTracks({ query: "deep house 2024", type: "tracks", limit: 1 });
|
|
279
|
+
if (first && "url" in first) {
|
|
280
|
+
const s = await sc.downloadTrack(first.url);
|
|
281
|
+
s.pipe(process.stdout);
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Paginate results
|
|
286
|
+
|
|
287
|
+
```ts
|
|
288
|
+
const page1 = await sc.searchTracks({ query: "vaporwave", type: "tracks", limit: 20, offset: 0 });
|
|
289
|
+
const page2 = await sc.searchTracks({ query: "vaporwave", type: "tracks", limit: 20, offset: 20 });
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## Error Handling & Tips
|
|
295
|
+
|
|
296
|
+
* **Initialization:** If a method throws due to missing/expired `clientId`, call `await sc.init()` and retry.
|
|
297
|
+
* **Quality selection:** Not all tracks expose multiple transcodings; the library will fall back when needed.
|
|
298
|
+
* **Rate limits / 429:** Back off and retry with an exponential strategy.
|
|
299
|
+
* **Private/geo-restricted tracks:** Details/downloads may be unavailable.
|
|
300
|
+
* **Networking:** Wrap downloads with proper error and close handlers to avoid dangling file descriptors.
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## FAQ
|
|
305
|
+
|
|
306
|
+
**Q: Can I use this in the browser?**
|
|
307
|
+
This package targets Node.js (it returns Node `Readable`). Browser use is not supported.
|
|
308
|
+
|
|
309
|
+
**Q: What audio format do I get?**
|
|
310
|
+
Whatever the selected transcoding provides (commonly progressive MP3 or HLS AAC). You may need to remux/encode if you require a specific container/codec.
|
|
311
|
+
|
|
312
|
+
**Q: Do I need my own client ID?**
|
|
313
|
+
The client auto-discovers a valid `clientId`. If discovery fails due to upstream changes, update the package to the latest version.
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## Contributing
|
|
318
|
+
|
|
319
|
+
PRs and issues are welcome! Please include:
|
|
103
320
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
321
|
+
* A clear description of the change
|
|
322
|
+
* Repro steps (for bugs)
|
|
323
|
+
* Tests where possible
|
|
107
324
|
|
|
108
325
|
---
|
|
109
326
|
|
|
110
|
-
##
|
|
327
|
+
## License
|
|
111
328
|
|
|
112
|
-
|
|
329
|
+
MIT © Zibot
|
|
113
330
|
|
|
114
331
|
---
|
|
115
332
|
|
|
116
|
-
##
|
|
333
|
+
## Disclaimer
|
|
117
334
|
|
|
118
|
-
|
|
335
|
+
This project is not affiliated with SoundCloud. Use responsibly and comply with all applicable laws and SoundCloud’s Terms of Service.
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,35 +1,32 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@zibot/scdl",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Soucloud download",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"types": "index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
-
},
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/
|
|
13
|
-
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
"@zibot/scdl",
|
|
16
|
-
"scdl"
|
|
17
|
-
],
|
|
18
|
-
"author": "Ziji",
|
|
19
|
-
"license": "ISC",
|
|
20
|
-
"bugs": {
|
|
21
|
-
"url": "https://github.com/
|
|
22
|
-
},
|
|
23
|
-
"publishConfig": {
|
|
24
|
-
"access": "public"
|
|
25
|
-
},
|
|
26
|
-
"homepage": "https://github.com/
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"m3u8stream": "^0.8.6"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@zibot/scdl",
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"description": "Soucloud download",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/ZiProject/scdl.git"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"@zibot/scdl",
|
|
16
|
+
"scdl"
|
|
17
|
+
],
|
|
18
|
+
"author": "Ziji",
|
|
19
|
+
"license": "ISC",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/ZiProject/scdl/issues"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/ZiProject/scdl#readme",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"axios": "^1.13.2",
|
|
29
|
+
"events": "^3.3.0",
|
|
30
|
+
"m3u8stream": "^0.8.6"
|
|
31
|
+
}
|
|
32
|
+
}
|