@purpleproser/soundboard-downloader-cli 1.4.0 → 1.6.0

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/dist/main.js CHANGED
@@ -4,8 +4,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const my_instants_service_1 = require("./service/my-instants.service");
5
5
  const ora_1 = require("ora");
6
6
  const prompts_1 = require("@inquirer/prompts");
7
+ const inquirer = require("@inquirer/prompts");
7
8
  const open_1 = require("open");
8
9
  const file_downloader_service_1 = require("./service/file-downloader.service");
10
+ const selection_utils_1 = require("./utils/selection-utils");
11
+ const pagination_utils_1 = require("./utils/pagination-utils");
9
12
  process.on("uncaughtException", (error) => {
10
13
  if (error instanceof Error && error.name === "ExitPromptError") {
11
14
  console.log("👋 see ya!");
@@ -16,71 +19,303 @@ process.on("uncaughtException", (error) => {
16
19
  }
17
20
  });
18
21
  (async function () {
19
- const answer = await (0, prompts_1.input)({
22
+ // Check for --all flag
23
+ const args = process.argv.slice(2);
24
+ let shouldFetchAll = args.includes("--all");
25
+ let answer = await (0, prompts_1.input)({
20
26
  message: "🔍 What sound effects are you looking for?",
21
27
  required: true,
22
28
  default: "wilhelm scream",
23
29
  });
24
- const spinner = (0, ora_1.default)({
25
- text: "Loading result...",
26
- color: "magenta",
27
- spinner: "bouncingBall",
28
- }).start();
29
- const sounds = await (0, my_instants_service_1.getSoundNodes)(answer);
30
- spinner.stop();
31
- console.log(`🎉 Found ${sounds.length} sound${sounds.length !== 1 ? 's' : ''}!`);
32
- const selection = await (0, prompts_1.select)({
33
- message: "🎵 Which one to download? (use the keyboard arrows to navigate, search for something directly)",
34
- pageSize: 30,
35
- choices: sounds.map((sound) => ({
36
- name: `${sound.label} 🎵`,
37
- value: `${sound.label}||${sound.download_url}`,
38
- })),
39
- });
40
- const [label, downloadUrl] = selection.split("||");
41
- if (!downloadUrl) {
42
- throw new ReferenceError(`There is no download URL for: ${label}`);
43
- }
44
- const actions = [
45
- {
46
- name: "💾 Download",
47
- value: "action:download",
48
- },
49
- {
50
- name: "▶️ Play",
51
- value: "action:play",
52
- },
53
- {
54
- name: "🔗 Show download URL (you can pipe this to other commands)",
55
- value: "action:show-url",
56
- },
57
- ];
58
- const action = await (0, prompts_1.select)({
59
- message: `Selected: ${label}`,
60
- choices: actions,
61
- });
62
- if (action === "action:show-url") {
63
- console.log(downloadUrl);
64
- }
65
- if (action === "action:play") {
66
- (0, open_1.default)(downloadUrl);
30
+ // Pagination flow
31
+ if (!shouldFetchAll) {
32
+ let currentPage = 1;
33
+ let shouldContinuePagination = true;
34
+ while (shouldContinuePagination) {
35
+ const spinner = (0, ora_1.default)({
36
+ text: `Loading page ${currentPage}...`,
37
+ color: "magenta",
38
+ spinner: "bouncingBall",
39
+ }).start();
40
+ try {
41
+ const { results, hasNextPage, hasPreviousPage } = await (0, my_instants_service_1.getPaginatedResults)(answer, currentPage);
42
+ spinner.stop();
43
+ console.log((0, pagination_utils_1.getPaginationInfo)(currentPage, results.length, hasNextPage));
44
+ // Prepare sound choices
45
+ const soundChoices = results.map((sound) => ({
46
+ name: `${sound.label} 🎵`,
47
+ value: `${sound.label}||${sound.download_url}`,
48
+ }));
49
+ // Add navigation choices as separate actions
50
+ const navigationChoices = [
51
+ new inquirer.Separator("=== Navigation ==="),
52
+ {
53
+ name: hasPreviousPage ? "⏮️ Previous page" : "⏮️ Previous page (disabled)",
54
+ value: "action:prev-page",
55
+ disabled: !hasPreviousPage
56
+ },
57
+ {
58
+ name: hasNextPage ? "⏭️ Next page" : "⏭️ Next page (disabled)",
59
+ value: "action:next-page",
60
+ disabled: !hasNextPage
61
+ },
62
+ {
63
+ name: "🔍 New search",
64
+ value: "action:new-search"
65
+ },
66
+ {
67
+ name: "📋 Show all results",
68
+ value: "action:show-all"
69
+ }
70
+ ];
71
+ const allChoices = [...soundChoices, ...navigationChoices];
72
+ // Use radio selection instead of checkbox for single selection
73
+ const selection = await (0, prompts_1.select)({
74
+ message: "🎵 Select a sound or choose a navigation option:",
75
+ choices: allChoices,
76
+ });
77
+ // Handle navigation actions
78
+ if ((0, pagination_utils_1.isNavigationAction)(selection)) {
79
+ switch (selection) {
80
+ case "action:prev-page":
81
+ if (hasPreviousPage)
82
+ currentPage--;
83
+ continue;
84
+ case "action:next-page":
85
+ if (hasNextPage)
86
+ currentPage++;
87
+ continue;
88
+ case "action:new-search":
89
+ // Reset for new search
90
+ answer = await (0, prompts_1.input)({
91
+ message: "🔍 What sound effects are you looking for?",
92
+ required: true,
93
+ default: answer,
94
+ });
95
+ currentPage = 1;
96
+ continue;
97
+ case "action:show-all":
98
+ // Switch to fetch-all mode
99
+ shouldFetchAll = true;
100
+ shouldContinuePagination = false;
101
+ break;
102
+ }
103
+ continue;
104
+ }
105
+ // If we get here, user selected a sound
106
+ shouldContinuePagination = false;
107
+ // Process the single sound selection
108
+ const selections = (0, selection_utils_1.parseSelections)([selection]);
109
+ // Available actions for single sound selection
110
+ const actions = [
111
+ {
112
+ name: "💾 Download",
113
+ value: "action:download",
114
+ },
115
+ {
116
+ name: "▶️ Play",
117
+ value: "action:play",
118
+ },
119
+ {
120
+ name: "🔗 Show download URL (you can pipe this to other commands)",
121
+ value: "action:show-url",
122
+ },
123
+ ];
124
+ const action = await (0, prompts_1.select)({
125
+ message: (0, selection_utils_1.getSelectionMessage)(selections),
126
+ choices: actions,
127
+ });
128
+ if (action === "action:show-url") {
129
+ const firstSelection = (0, selection_utils_1.getFirstSelection)(selections);
130
+ if (firstSelection) {
131
+ console.log(firstSelection.downloadUrl);
132
+ }
133
+ }
134
+ if (action === "action:play") {
135
+ const firstSelection = (0, selection_utils_1.getFirstSelection)(selections);
136
+ if (firstSelection) {
137
+ (0, open_1.default)(firstSelection.downloadUrl);
138
+ }
139
+ }
140
+ if (action === "action:download") {
141
+ const totalDownloads = selections.length;
142
+ let completedDownloads = 0;
143
+ let failedDownloads = 0;
144
+ const failedFiles = [];
145
+ const masterSpinner = (0, ora_1.default)({
146
+ text: `Preparing to download ${totalDownloads} file${totalDownloads !== 1 ? "s" : ""}...`,
147
+ color: "cyan",
148
+ spinner: "growHorizontal",
149
+ }).start();
150
+ // Process all downloads sequentially
151
+ for (const [index, selection] of selections.entries()) {
152
+ masterSpinner.text = `Downloading ${selection.label} (${index + 1}/${totalDownloads})...`;
153
+ try {
154
+ const downloadFileName = selection.downloadUrl.split("/").pop();
155
+ if (!downloadFileName) {
156
+ throw new ReferenceError(`Could not find download file name for: [${selection.downloadUrl}], could it be a malformed link?`);
157
+ }
158
+ // Download directly to current working directory
159
+ await (0, file_downloader_service_1.downloadFile)(selection.downloadUrl, {
160
+ destination: downloadFileName,
161
+ });
162
+ completedDownloads++;
163
+ masterSpinner.text = `Downloaded ${completedDownloads}/${totalDownloads} files...`;
164
+ }
165
+ catch (error) {
166
+ failedDownloads++;
167
+ failedFiles.push(selection.label);
168
+ masterSpinner.text = `Error downloading ${selection.label} (${completedDownloads} successful, ${failedDownloads} failed)`;
169
+ console.error(`\nFailed to download ${selection.label}:`, error instanceof Error ? error.message : String(error));
170
+ }
171
+ }
172
+ // Final summary - only show once at the end
173
+ masterSpinner.stop();
174
+ if (failedDownloads === 0) {
175
+ console.log(`✅ Download complete! All ${completedDownloads} file${completedDownloads !== 1 ? "s" : ""} downloaded successfully.`);
176
+ }
177
+ else {
178
+ console.log(`⚠️ Download partially complete: ${completedDownloads} successful, ${failedDownloads} failed.`);
179
+ if (failedFiles.length > 0) {
180
+ console.log("\nFailed files:");
181
+ failedFiles.forEach((file) => console.log(` - ${file}`));
182
+ }
183
+ }
184
+ }
185
+ }
186
+ catch (error) {
187
+ spinner.stop();
188
+ console.error("❌ Error loading results:", error instanceof Error ? error.message : String(error));
189
+ const retry = await (0, prompts_1.select)({
190
+ message: "What would you like to do?",
191
+ choices: [
192
+ { name: "🔍 Try a new search", value: "new-search" },
193
+ { name: "🚪 Exit", value: "exit" },
194
+ ],
195
+ });
196
+ if (retry === "new-search") {
197
+ answer = await (0, prompts_1.input)({
198
+ message: "🔍 What sound effects are you looking for?",
199
+ required: true,
200
+ default: answer,
201
+ });
202
+ currentPage = 1;
203
+ continue;
204
+ }
205
+ else {
206
+ process.exit(0);
207
+ }
208
+ }
209
+ }
67
210
  }
68
- if (action === "action:download") {
69
- const downloadSpinner = (0, ora_1.default)({
70
- text: "Downloading file...",
71
- color: "cyan",
72
- spinner: "growHorizontal",
211
+ // Fetch-all mode
212
+ if (shouldFetchAll) {
213
+ const spinner = (0, ora_1.default)({
214
+ text: "Loading all results...",
215
+ color: "magenta",
216
+ spinner: "bouncingBall",
73
217
  }).start();
74
- const downloadFileName = downloadUrl.split("/").pop();
75
- if (!downloadFileName) {
76
- throw new ReferenceError(`Could not find download file name for: [${downloadUrl}], could it be a malformed link?`);
218
+ try {
219
+ const allResults = await (0, my_instants_service_1.getAllResults)(answer);
220
+ spinner.stop();
221
+ console.log(`🎉 Found ${allResults.length} sound${allResults.length !== 1 ? "s" : ""}!`);
222
+ const rawSelections = await (0, prompts_1.checkbox)({
223
+ message: "🎵 Which sounds to download? (use space to select multiple, arrows to navigate, search for something directly)",
224
+ choices: allResults.map((sound) => ({
225
+ name: `${sound.label} 🎵`,
226
+ value: `${sound.label}||${sound.download_url}`,
227
+ })),
228
+ });
229
+ // Parse and validate selections
230
+ const selections = (0, selection_utils_1.parseSelections)(rawSelections);
231
+ const multipleSelected = (0, selection_utils_1.isMultipleSelection)(selections);
232
+ // Determine available actions based on selection count
233
+ let actions = [
234
+ {
235
+ name: "💾 Download",
236
+ value: "action:download",
237
+ },
238
+ ];
239
+ // For single selection, add additional options
240
+ if (!multipleSelected) {
241
+ actions = [
242
+ ...actions,
243
+ {
244
+ name: "▶️ Play",
245
+ value: "action:play",
246
+ },
247
+ {
248
+ name: "🔗 Show download URL (you can pipe this to other commands)",
249
+ value: "action:show-url",
250
+ },
251
+ ];
252
+ }
253
+ const action = await (0, prompts_1.select)({
254
+ message: (0, selection_utils_1.getSelectionMessage)(selections),
255
+ choices: actions,
256
+ });
257
+ if (action === "action:show-url" && !multipleSelected) {
258
+ const firstSelection = (0, selection_utils_1.getFirstSelection)(selections);
259
+ if (firstSelection) {
260
+ console.log(firstSelection.downloadUrl);
261
+ }
262
+ }
263
+ if (action === "action:play" && !multipleSelected) {
264
+ const firstSelection = (0, selection_utils_1.getFirstSelection)(selections);
265
+ if (firstSelection) {
266
+ (0, open_1.default)(firstSelection.downloadUrl);
267
+ }
268
+ }
269
+ if (action === "action:download") {
270
+ const totalDownloads = selections.length;
271
+ let completedDownloads = 0;
272
+ let failedDownloads = 0;
273
+ const failedFiles = [];
274
+ const masterSpinner = (0, ora_1.default)({
275
+ text: `Preparing to download ${totalDownloads} file${totalDownloads !== 1 ? "s" : ""}...`,
276
+ color: "cyan",
277
+ spinner: "growHorizontal",
278
+ }).start();
279
+ // Process all downloads sequentially
280
+ for (const [index, selection] of selections.entries()) {
281
+ masterSpinner.text = `Downloading ${selection.label} (${index + 1}/${totalDownloads})...`;
282
+ try {
283
+ const downloadFileName = selection.downloadUrl.split("/").pop();
284
+ if (!downloadFileName) {
285
+ throw new ReferenceError(`Could not find download file name for: [${selection.downloadUrl}], could it be a malformed link?`);
286
+ }
287
+ // Download directly to current working directory
288
+ await (0, file_downloader_service_1.downloadFile)(selection.downloadUrl, {
289
+ destination: downloadFileName,
290
+ });
291
+ completedDownloads++;
292
+ masterSpinner.text = `Downloaded ${completedDownloads}/${totalDownloads} files...`;
293
+ }
294
+ catch (error) {
295
+ failedDownloads++;
296
+ failedFiles.push(selection.label);
297
+ masterSpinner.text = `Error downloading ${selection.label} (${completedDownloads} successful, ${failedDownloads} failed)`;
298
+ console.error(`\nFailed to download ${selection.label}:`, error instanceof Error ? error.message : String(error));
299
+ }
300
+ }
301
+ // Final summary - only show once at the end
302
+ masterSpinner.stop();
303
+ if (failedDownloads === 0) {
304
+ console.log(`✅ Download complete! All ${completedDownloads} file${completedDownloads !== 1 ? "s" : ""} downloaded successfully.`);
305
+ }
306
+ else {
307
+ console.log(`⚠️ Download partially complete: ${completedDownloads} successful, ${failedDownloads} failed.`);
308
+ if (failedFiles.length > 0) {
309
+ console.log("\nFailed files:");
310
+ failedFiles.forEach((file) => console.log(` - ${file}`));
311
+ }
312
+ }
313
+ }
314
+ }
315
+ catch (error) {
316
+ spinner.stop();
317
+ console.error("❌ Error loading all results:", error instanceof Error ? error.message : String(error));
77
318
  }
78
- // Download directly to current working directory
79
- (0, file_downloader_service_1.downloadFile)(downloadUrl, {
80
- destination: downloadFileName,
81
- onStart: () => downloadSpinner.start(),
82
- onFinish: () => downloadSpinner.stop(),
83
- });
84
319
  }
85
320
  })();
86
321
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;AAEA,uEAA8D;AAC9D,6BAAsB;AACtB,+CAAkD;AAClD,+BAAwB;AACxB,+EAAiE;AAEjE,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,KAAK,EAAE,EAAE;IACxC,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;QAC/D,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC5B,CAAC;SAAM,CAAC;QACN,yBAAyB;QACzB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,CAAC,KAAK;IACJ,MAAM,MAAM,GAAG,MAAM,IAAA,eAAK,EAAC;QACzB,OAAO,EAAE,4CAA4C;QACrD,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,gBAAgB;KAC1B,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,IAAA,aAAG,EAAC;QAClB,IAAI,EAAE,mBAAmB;QACzB,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,cAAc;KACxB,CAAC,CAAC,KAAK,EAAE,CAAC;IAEX,MAAM,MAA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.();
16
- console.log("Download Completed");
17
16
  });
18
17
  });
19
18
  };
@@ -1 +1 @@
1
- {"version":3,"file":"file-downloader.service.js","sourceRoot":"","sources":["../../src/service/file-downloader.service.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,yBAAyB;AAElB,MAAM,YAAY,GAAG,CAC1B,GAAW,EACX,MAIC,EACD,EAAE;IACF,MAAM,IAAI,GAAG,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAEtD,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,UAAU,QAAQ;QAC/B,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEpB,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;YACnB,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;YACrB,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAvBW,QAAA,YAAY,gBAuBvB"}
1
+ {"version":3,"file":"file-downloader.service.js","sourceRoot":"","sources":["../../src/service/file-downloader.service.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,yBAAyB;AAElB,MAAM,YAAY,GAAG,CAC1B,GAAW,EACX,MAIC,EACD,EAAE;IACF,MAAM,IAAI,GAAG,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAEtD,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,UAAU,QAAQ;QAC/B,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEpB,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;YACnB,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;YACrB,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;QACtB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAtBW,QAAA,YAAY,gBAsBvB"}
@@ -1,8 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSoundNodes = void 0;
3
+ exports.getAllResults = exports.getPaginatedResults = exports.getSoundNodesPage = void 0;
4
4
  const my_instants_api_1 = require("../api/my-instants.api");
5
+ const validation_schemas_1 = require("../api/validation-schemas");
5
6
  const jsdom = require("jsdom");
7
+ // Simple in-memory cache for paginated results
8
+ const pageCache = new Map();
9
+ const getCacheKey = (searchString, page) => {
10
+ return `${searchString}||${page}`;
11
+ };
12
+ const getCachedPage = (searchString, page) => {
13
+ return pageCache.get(getCacheKey(searchString, page));
14
+ };
15
+ const cachePage = (searchString, page, html) => {
16
+ pageCache.set(getCacheKey(searchString, page), html);
17
+ };
18
+ const clearCache = (searchString) => {
19
+ // Clear all cached pages for this search
20
+ for (const key of pageCache.keys()) {
21
+ if (key.startsWith(`${searchString}||`)) {
22
+ pageCache.delete(key);
23
+ }
24
+ }
25
+ };
6
26
  const getDownloadUrl = async (originalUrl) => {
7
27
  if (!originalUrl) {
8
28
  return "not-found";
@@ -21,34 +41,104 @@ const getDownloadUrl = async (originalUrl) => {
21
41
  const cleanSoundName = originalUrl
22
42
  .replace("/en/instant/", "")
23
43
  .replace("/", "");
24
- const downloadPage = await (0, my_instants_api_1.getNodeDownloadPage)(originalUrl);
25
- const downloadLink = Array.from(new jsdom.JSDOM(downloadPage).window.document.querySelectorAll("a")).find((node) => {
26
- return node.href.includes(".mp3") && node.hasAttribute("download");
27
- });
28
- if (downloadLink) {
29
- return `https://www.myinstants.com${downloadLink.href}`;
44
+ try {
45
+ const downloadPage = await (0, my_instants_api_1.getNodeDownloadPage)(originalUrl);
46
+ const downloadLink = Array.from(new jsdom.JSDOM(downloadPage).window.document.querySelectorAll("a")).find((node) => {
47
+ return node.href.includes(".mp3") && node.hasAttribute("download");
48
+ });
49
+ if (downloadLink) {
50
+ return `https://www.myinstants.com${downloadLink.href}`;
51
+ }
52
+ }
53
+ catch (error) {
54
+ console.error(`Failed to fetch download URL for ${originalUrl}:`, error);
30
55
  }
31
56
  return "not-found";
32
57
  };
33
- const getSoundNodes = async (searchString) => {
34
- const result = await (0, my_instants_api_1.getSoundNodes)(searchString);
35
- const allLabels = [];
36
- const allDownloadLinks = [];
37
- for (const page of result) {
38
- const document = new jsdom.JSDOM(page);
39
- document.window.document
40
- .querySelectorAll("div.instant > a.instant-link")
41
- .forEach((node) => {
42
- allLabels.push(node.textContent);
43
- allDownloadLinks.push(getDownloadUrl(node.getAttribute("href")));
44
- });
58
+ /**
59
+ * Get sound nodes for a specific page with caching
60
+ */
61
+ const getSoundNodesPage = async (params) => {
62
+ const page = params.page || 1;
63
+ const cacheKey = getCacheKey(params.searchString, page);
64
+ let html = getCachedPage(params.searchString, page);
65
+ if (!html) {
66
+ html = await (0, my_instants_api_1.getSoundNodesPage)(params);
67
+ cachePage(params.searchString, page, html);
45
68
  }
46
- const allLinksResolved = await Promise.all(allDownloadLinks);
47
- const finalList = allLabels.map((label, index) => ({
48
- label,
49
- download_url: allLinksResolved[index] ?? "not-found",
69
+ const document = new jsdom.JSDOM(html);
70
+ const soundNodes = Array.from(document.window.document.querySelectorAll("div.instant > a.instant-link"));
71
+ const results = [];
72
+ // First, extract labels and detail URLs
73
+ soundNodes.forEach((node) => {
74
+ const detailUrl = node.getAttribute("href");
75
+ if (detailUrl) {
76
+ results.push({
77
+ label: node.textContent?.trim() || "Unknown",
78
+ download_url: "pending",
79
+ detail_url: detailUrl
80
+ });
81
+ }
82
+ });
83
+ // Resolve download URLs in parallel by fetching each detail page
84
+ const downloadPromises = results.map(result => getDownloadUrl(result.detail_url));
85
+ const downloadUrls = await Promise.all(downloadPromises);
86
+ return results.map((result, index) => ({
87
+ label: result.label,
88
+ download_url: downloadUrls[index] || "not-found"
50
89
  }));
51
- return finalList.toSorted((a, b) => a.label.localeCompare(b.label));
52
90
  };
53
- exports.getSoundNodes = getSoundNodes;
91
+ exports.getSoundNodesPage = getSoundNodesPage;
92
+ /**
93
+ * Get paginated results with navigation information
94
+ */
95
+ const getPaginatedResults = async (searchString, page = 1) => {
96
+ // Clear cache for new searches
97
+ if (page === 1) {
98
+ clearCache(searchString);
99
+ }
100
+ const currentResults = await (0, exports.getSoundNodesPage)({ searchString, page });
101
+ const hasNext = await (0, my_instants_api_1.hasNextPage)({ searchString, page });
102
+ // Validate the results before returning
103
+ const validatedResults = (0, validation_schemas_1.validatePaginatedResults)({
104
+ results: currentResults,
105
+ hasNextPage: hasNext,
106
+ hasPreviousPage: page > 1,
107
+ currentPage: page
108
+ });
109
+ return validatedResults;
110
+ };
111
+ exports.getPaginatedResults = getPaginatedResults;
112
+ /**
113
+ * Get all results (for --all flag)
114
+ */
115
+ const getAllResults = async (searchString) => {
116
+ const allPages = await (0, my_instants_api_1.getAllSoundNodes)({ searchString });
117
+ const allResults = [];
118
+ // First collect all detail URLs
119
+ const soundDetails = [];
120
+ for (const pageHtml of allPages) {
121
+ const document = new jsdom.JSDOM(pageHtml);
122
+ const soundNodes = Array.from(document.window.document.querySelectorAll("div.instant > a.instant-link"));
123
+ soundNodes.forEach((node) => {
124
+ const detailUrl = node.getAttribute("href");
125
+ if (detailUrl) {
126
+ soundDetails.push({
127
+ label: node.textContent?.trim() || "Unknown",
128
+ detail_url: detailUrl
129
+ });
130
+ }
131
+ });
132
+ }
133
+ // Resolve all download URLs
134
+ const downloadPromises = soundDetails.map(detail => getDownloadUrl(detail.detail_url));
135
+ const downloadUrls = await Promise.all(downloadPromises);
136
+ const finalResults = soundDetails.map((detail, index) => ({
137
+ label: detail.label,
138
+ download_url: downloadUrls[index] || "not-found"
139
+ })).sort((a, b) => a.label.localeCompare(b.label));
140
+ // Validate all results before returning
141
+ return (0, validation_schemas_1.validateSoundsArray)(finalResults);
142
+ };
143
+ exports.getAllResults = getAllResults;
54
144
  //# sourceMappingURL=my-instants.service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"my-instants.service.js","sourceRoot":"","sources":["../../src/service/my-instants.service.ts"],"names":[],"mappings":";;;AAAA,4DAGgC;AAChC,+BAA+B;AAE/B,MAAM,cAAc,GAAG,KAAK,EAAE,WAA0B,EAAE,EAAE;IAC1D,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,WAAW,CAAC;IACrB,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,cAAc,GAAG,WAAW;SAC/B,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;SAC3B,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAEpB,MAAM,YAAY,GAAG,MAAM,IAAA,qCAAmB,EAAC,WAAW,CAAC,CAAC;IAE5D,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAC7B,IAAI,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,GAAG,CAAC,CACpE,CAAC,IAAI,CAAC,CAAC,IAAuB,EAAE,EAAE;QACjC,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;IAEH,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,6BAA6B,YAAY,CAAC,IAAI,EAAE,CAAC;IAC1D,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAEK,MAAM,aAAa,GAAG,KAAK,EAAE,YAAoB,EAAE,EAAE;IAC1D,MAAM,MAAM,GAAG,MAAM,I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