@zibot/scdl 0.0.1 → 0.0.3
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/index.d.ts +60 -65
- package/index.js +20 -8
- package/package.json +2 -1
package/index.d.ts
CHANGED
|
@@ -1,78 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
import { Readable } from "stream";
|
|
1
|
+
import { Readable } from "stream";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export interface DownloadOptions {
|
|
13
|
-
quality?: "high" | "low";
|
|
14
|
-
}
|
|
3
|
+
// Types
|
|
4
|
+
interface SearchOptions {
|
|
5
|
+
query: string;
|
|
6
|
+
limit?: number;
|
|
7
|
+
offset?: number;
|
|
8
|
+
type?: "all" | "tracks" | "playlists" | "users";
|
|
9
|
+
}
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
url: string;
|
|
20
|
-
user: { id: number; username: string };
|
|
21
|
-
media: {
|
|
22
|
-
transcodings: {
|
|
23
|
-
url: string;
|
|
24
|
-
format: { protocol: string; mime_type: string };
|
|
25
|
-
}[];
|
|
26
|
-
};
|
|
27
|
-
}
|
|
11
|
+
interface DownloadOptions {
|
|
12
|
+
quality?: "high" | "low";
|
|
13
|
+
}
|
|
28
14
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
15
|
+
interface Track {
|
|
16
|
+
id: number;
|
|
17
|
+
title: string;
|
|
18
|
+
url: string;
|
|
19
|
+
user: { id: number; username: string };
|
|
20
|
+
media: {
|
|
21
|
+
transcodings: {
|
|
22
|
+
url: string;
|
|
23
|
+
format: { protocol: string; mime_type: string };
|
|
24
|
+
}[];
|
|
25
|
+
};
|
|
26
|
+
}
|
|
34
27
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
28
|
+
interface Playlist {
|
|
29
|
+
id: number;
|
|
30
|
+
title: string;
|
|
31
|
+
tracks: Track[];
|
|
32
|
+
}
|
|
41
33
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
34
|
+
interface User {
|
|
35
|
+
id: number;
|
|
36
|
+
username: string;
|
|
37
|
+
followers_count: number;
|
|
38
|
+
track_count: number;
|
|
39
|
+
}
|
|
46
40
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
declare class SoundCloud {
|
|
42
|
+
clientId: string | null;
|
|
43
|
+
apiBaseUrl: string;
|
|
50
44
|
|
|
51
|
-
|
|
45
|
+
constructor(options?: { init?: boolean });
|
|
52
46
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Initialize the SoundCloud client to retrieve clientId.
|
|
49
|
+
*/
|
|
50
|
+
init(): Promise<void>;
|
|
57
51
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Search for tracks, playlists, or users on SoundCloud.
|
|
54
|
+
*/
|
|
55
|
+
searchTracks(options: SearchOptions): Promise<(Track | Playlist | User)[]>;
|
|
62
56
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Retrieve detailed information about a single track.
|
|
59
|
+
*/
|
|
60
|
+
getTrackDetails(url: string): Promise<Track>;
|
|
67
61
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Retrieve detailed information about a playlist.
|
|
64
|
+
*/
|
|
65
|
+
getPlaylistDetails(url: string): Promise<Playlist>;
|
|
72
66
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
67
|
+
/**
|
|
68
|
+
* Download a track as a stream.
|
|
69
|
+
*/
|
|
70
|
+
downloadTrack(url: string, options?: DownloadOptions): Promise<Readable>;
|
|
78
71
|
}
|
|
72
|
+
|
|
73
|
+
export = SoundCloud;
|
package/index.js
CHANGED
|
@@ -31,15 +31,22 @@ class SoundCloud {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// Search SoundCloud
|
|
34
|
-
async searchTracks({ query, limit =
|
|
34
|
+
async searchTracks({ query, limit = 30, offset = 0, type = "all" }) {
|
|
35
35
|
const path = type === "all" ? "" : `/${type}`;
|
|
36
36
|
const url = `${this.apiBaseUrl}/search${path}?q=${encodeURIComponent(
|
|
37
37
|
query,
|
|
38
38
|
)}&limit=${limit}&offset=${offset}&access=playable&client_id=${this.clientId}`;
|
|
39
|
-
console.log(url);
|
|
40
39
|
try {
|
|
41
40
|
const { data } = await axios.get(url);
|
|
42
|
-
|
|
41
|
+
|
|
42
|
+
if (!data || !data?.collection?.length) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return data.collection.filter((track) => {
|
|
47
|
+
if (!track.permalink_url || !track.title || !track.duration) return false;
|
|
48
|
+
return true;
|
|
49
|
+
});
|
|
43
50
|
} catch (error) {
|
|
44
51
|
console.error("Search error:", error.message || error);
|
|
45
52
|
throw new Error("Search failed");
|
|
@@ -77,13 +84,18 @@ class SoundCloud {
|
|
|
77
84
|
|
|
78
85
|
// Download track stream
|
|
79
86
|
async downloadTrack(trackUrl, options = {}) {
|
|
80
|
-
|
|
81
|
-
|
|
87
|
+
try {
|
|
88
|
+
const track = await this.getTrackDetails(trackUrl);
|
|
89
|
+
const transcoding = track?.media?.transcodings?.find((t) => t.format.protocol === "hls");
|
|
82
90
|
|
|
83
|
-
|
|
91
|
+
if (!transcoding) throw new Error("No valid HLS stream found");
|
|
84
92
|
|
|
85
|
-
|
|
86
|
-
|
|
93
|
+
const m3u8Url = await this.getStreamUrl(transcoding.url);
|
|
94
|
+
return m3u8stream(m3u8Url, options);
|
|
95
|
+
} catch (e) {
|
|
96
|
+
console.error("Failed to download track");
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
87
99
|
}
|
|
88
100
|
|
|
89
101
|
// Fetch single item (track/playlist/user)
|