@zibot/scdl 0.0.2 → 0.0.4
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 +1 -6
- package/index.js +24 -7
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -38,11 +38,6 @@ interface User {
|
|
|
38
38
|
track_count: number;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
interface SearchResponse {
|
|
42
|
-
collection: (Track | Playlist | User)[];
|
|
43
|
-
next_href?: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
41
|
declare class SoundCloud {
|
|
47
42
|
clientId: string | null;
|
|
48
43
|
apiBaseUrl: string;
|
|
@@ -57,7 +52,7 @@ declare class SoundCloud {
|
|
|
57
52
|
/**
|
|
58
53
|
* Search for tracks, playlists, or users on SoundCloud.
|
|
59
54
|
*/
|
|
60
|
-
searchTracks(options: SearchOptions): Promise<
|
|
55
|
+
searchTracks(options: SearchOptions): Promise<(Track | Playlist | User)[]>;
|
|
61
56
|
|
|
62
57
|
/**
|
|
63
58
|
* Retrieve detailed information about a single track.
|
package/index.js
CHANGED
|
@@ -38,14 +38,14 @@ class SoundCloud {
|
|
|
38
38
|
)}&limit=${limit}&offset=${offset}&access=playable&client_id=${this.clientId}`;
|
|
39
39
|
try {
|
|
40
40
|
const { data } = await axios.get(url);
|
|
41
|
+
|
|
41
42
|
if (!data || !data?.collection?.length) {
|
|
42
43
|
return [];
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
return data.collection.filter((track) => {
|
|
46
|
-
if (!track.permalink_url) return false;
|
|
47
|
-
|
|
48
|
-
if (!track.duration) return false;
|
|
47
|
+
if (!track.permalink_url || !track.title || !track.duration) return false;
|
|
48
|
+
return true;
|
|
49
49
|
});
|
|
50
50
|
} catch (error) {
|
|
51
51
|
console.error("Search error:", error.message || error);
|
|
@@ -111,12 +111,29 @@ class SoundCloud {
|
|
|
111
111
|
|
|
112
112
|
// Fetch multiple tracks by their IDs
|
|
113
113
|
async fetchTracksByIds(trackIds) {
|
|
114
|
-
const
|
|
115
|
-
const
|
|
114
|
+
const chunkSize = 50; // Adjust chunk size as needed based on API limits
|
|
115
|
+
const chunks = [];
|
|
116
|
+
for (let i = 0; i < trackIds.length; i += chunkSize) {
|
|
117
|
+
chunks.push(trackIds.slice(i, i + chunkSize));
|
|
118
|
+
}
|
|
119
|
+
|
|
116
120
|
try {
|
|
117
|
-
const
|
|
118
|
-
|
|
121
|
+
const results = await Promise.all(
|
|
122
|
+
chunks.map(async (chunk) => {
|
|
123
|
+
const ids = chunk.join(",");
|
|
124
|
+
const url = `${this.apiBaseUrl}/tracks?ids=${ids}&client_id=${this.clientId}`;
|
|
125
|
+
const { data } = await axios.get(url);
|
|
126
|
+
return data;
|
|
127
|
+
}),
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
// Combine results from all chunks
|
|
131
|
+
return results.flat();
|
|
119
132
|
} catch (error) {
|
|
133
|
+
console.error("Failed to fetch tracks by IDs:", {
|
|
134
|
+
clientId: this.clientId,
|
|
135
|
+
error: error.response?.data || error.message,
|
|
136
|
+
});
|
|
120
137
|
throw new Error("Failed to fetch tracks by IDs");
|
|
121
138
|
}
|
|
122
139
|
}
|