@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/CHANGELOG.md +21 -0
- package/dist/api/api-config.js +31 -0
- package/dist/api/api-config.js.map +1 -0
- package/dist/api/my-instants.api.js +88 -28
- package/dist/api/my-instants.api.js.map +1 -1
- package/dist/api/my-instants.api.mock.js +136 -0
- package/dist/api/my-instants.api.mock.js.map +1 -0
- package/dist/api/validation-schemas.js +67 -0
- package/dist/api/validation-schemas.js.map +1 -0
- package/dist/common/types/query.type.js +3 -0
- package/dist/common/types/query.type.js.map +1 -0
- package/dist/main.js +293 -58
- package/dist/main.js.map +1 -1
- package/dist/service/file-downloader.service.js +0 -1
- package/dist/service/file-downloader.service.js.map +1 -1
- package/dist/service/my-instants.service.js +115 -25
- package/dist/service/my-instants.service.js.map +1 -1
- package/dist/utils/pagination-utils.js +82 -0
- package/dist/utils/pagination-utils.js.map +1 -0
- package/dist/utils/selection-utils.js +65 -0
- package/dist/utils/selection-utils.js.map +1 -0
- package/package.json +3 -2
- package/src/api/README.md +128 -0
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
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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,
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;AAEA,uEAGuC;AACvC,6BAAsB;AACtB,+CAA4D;AAC5D,8CAA8C;AAC9C,+BAAwB;AACxB,+EAAiE;AACjE,6DAMiC;AACjC,+DAGkC;AAElC,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,uBAAuB;IACvB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnC,IAAI,cAA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AAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACvD,CAAC;oBACJ,CAAC;gBACH,CAAC;gBAED,4CAA4C;gBAC5C,aAAa,CAAC,IAAI,EAAE,CAAC;gBAErB,IAAI,eAAe,KAAK,CAAC,EAAE,CAAC;oBAC1B,OAAO,CAAC,GAAG,CACT,4BAA4B,kBAAkB,QAAQ,kBAAkB,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,2BAA2B,CACrH,CAAC;gBACJ,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,GAAG,CACT,oCAAoC,kBAAkB,gBAAgB,eAAe,UAAU,CAChG,CAAC;oBACF,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBAC3B,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;wBAC/B,WAAW,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC;oBAC5D,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CACX,8BAA8B,EAC9B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACvD,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC,CAAC,EAAE,CAAC"}
|
|
@@ -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;
|
|
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.
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
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.
|
|
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,
|
|
1
|
+
{"version":3,"file":"my-instants.service.js","sourceRoot":"","sources":["../../src/service/my-instants.service.ts"],"names":[],"mappings":";;;AAAA,4DAKgC;AAChC,kEAImC;AACnC,+BAA+B;AAG/B,+CAA+C;AAC/C,MAAM,SAAS,GAAG,IAAI,GAAG,EAAkB,CAAC;AAE5C,MAAM,WAAW,GAAG,CAAC,YAAoB,EAAE,IAAY,EAAU,EAAE;IACjE,OAAO,GAAG,YAAY,KAAK,IAAI,EAAE,CAAC;AACpC,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,CAAC,YAAoB,EAAE,IAAY,EAAsB,EAAE;IAC/E,OAAO,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC;AACxD,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,CAAC,YAAoB,EAAE,IAAY,EAAE,IAAY,EAAQ,EAAE;IAC3E,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,YAAY,EAAE,IAAI,CAAC,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