@zibot/scdl 0.0.3 → 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.
Files changed (2) hide show
  1. package/index.js +21 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -111,12 +111,29 @@ class SoundCloud {
111
111
 
112
112
  // Fetch multiple tracks by their IDs
113
113
  async fetchTracksByIds(trackIds) {
114
- const ids = trackIds.join(",");
115
- const url = `${this.apiBaseUrl}/tracks?ids=${ids}&client_id=${this.clientId}`;
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 { data } = await axios.get(url);
118
- return data;
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zibot/scdl",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Soucloud download",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",