odesli.js 1.1.1 → 1.3.1
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/.eslintrc.js +0 -1
- package/.github/workflows/ci.yml +3 -11
- package/.github/workflows/publish-github-packages.yml +46 -0
- package/.github/workflows/{publish.yml → publish-npm.yml} +11 -2
- package/.prettierignore +30 -30
- package/API_IMPROVEMENTS.md +318 -0
- package/CHANGELOG.md +96 -33
- package/LICENSE +14 -14
- package/README.md +212 -144
- package/examples/README.md +197 -26
- package/examples/advanced-features-example.js +205 -0
- package/examples/advanced-usage.js +217 -36
- package/examples/basic-usage.js +92 -17
- package/examples/cache-test.js +119 -0
- package/examples/test-apple-music-extraction.js +60 -0
- package/examples/user-agent-example.js +46 -0
- package/jest.config.js +3 -1
- package/lib/index.d.ts +663 -484
- package/lib/index.js +1274 -390
- package/lib/index.mjs +3 -0
- package/lib/metrics.js +390 -0
- package/lib/metrics.mjs +3 -0
- package/lib/plugin-system.js +382 -0
- package/lib/plugin-system.mjs +3 -0
- package/lib/rate-limiter.js +148 -0
- package/lib/rate-limiter.mjs +3 -0
- package/package.json +2 -1
- package/tests/advanced-features.test.js +423 -0
- package/tests/odesli.test.js +246 -92
- package/tests/setup.js +2 -0
package/lib/index.d.ts
CHANGED
|
@@ -1,484 +1,663 @@
|
|
|
1
|
-
// Type definitions for odesli.js
|
|
2
|
-
// Project: https://github.com/MattrAus/odesli.js, https://www.npmjs.com/package/odesli.js
|
|
3
|
-
// Definitions by: Mattr <https://github.com/MattrAus>
|
|
4
|
-
// TypeScript Version: 2.7
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
1
|
+
// Type definitions for odesli.js
|
|
2
|
+
// Project: https://github.com/MattrAus/odesli.js, https://www.npmjs.com/package/odesli.js
|
|
3
|
+
// Definitions by: Mattr <https://github.com/MattrAus>
|
|
4
|
+
// TypeScript Version: 2.7
|
|
5
|
+
|
|
6
|
+
// Export the CountryCode type
|
|
7
|
+
type CountryCode =
|
|
8
|
+
| "AF"
|
|
9
|
+
| "AX"
|
|
10
|
+
| "AL"
|
|
11
|
+
| "DZ"
|
|
12
|
+
| "AS"
|
|
13
|
+
| "AD"
|
|
14
|
+
| "AO"
|
|
15
|
+
| "AI"
|
|
16
|
+
| "AQ"
|
|
17
|
+
| "AG"
|
|
18
|
+
| "AR"
|
|
19
|
+
| "AM"
|
|
20
|
+
| "AW"
|
|
21
|
+
| "AU"
|
|
22
|
+
| "AT"
|
|
23
|
+
| "AZ"
|
|
24
|
+
| "BS"
|
|
25
|
+
| "BH"
|
|
26
|
+
| "BD"
|
|
27
|
+
| "BB"
|
|
28
|
+
| "BY"
|
|
29
|
+
| "BE"
|
|
30
|
+
| "BZ"
|
|
31
|
+
| "BJ"
|
|
32
|
+
| "BM"
|
|
33
|
+
| "BT"
|
|
34
|
+
| "BO"
|
|
35
|
+
| "BQ"
|
|
36
|
+
| "BA"
|
|
37
|
+
| "BW"
|
|
38
|
+
| "BV"
|
|
39
|
+
| "BR"
|
|
40
|
+
| "IO"
|
|
41
|
+
| "BN"
|
|
42
|
+
| "BG"
|
|
43
|
+
| "BF"
|
|
44
|
+
| "BI"
|
|
45
|
+
| "KH"
|
|
46
|
+
| "CM"
|
|
47
|
+
| "CA"
|
|
48
|
+
| "CV"
|
|
49
|
+
| "KY"
|
|
50
|
+
| "CF"
|
|
51
|
+
| "TD"
|
|
52
|
+
| "CL"
|
|
53
|
+
| "CN"
|
|
54
|
+
| "CX"
|
|
55
|
+
| "CC"
|
|
56
|
+
| "CO"
|
|
57
|
+
| "KM"
|
|
58
|
+
| "CG"
|
|
59
|
+
| "CD"
|
|
60
|
+
| "CK"
|
|
61
|
+
| "CR"
|
|
62
|
+
| "CI"
|
|
63
|
+
| "HR"
|
|
64
|
+
| "CU"
|
|
65
|
+
| "CW"
|
|
66
|
+
| "CY"
|
|
67
|
+
| "CZ"
|
|
68
|
+
| "DK"
|
|
69
|
+
| "DJ"
|
|
70
|
+
| "DM"
|
|
71
|
+
| "DO"
|
|
72
|
+
| "EC"
|
|
73
|
+
| "EG"
|
|
74
|
+
| "SV"
|
|
75
|
+
| "GQ"
|
|
76
|
+
| "ER"
|
|
77
|
+
| "EE"
|
|
78
|
+
| "ET"
|
|
79
|
+
| "FK"
|
|
80
|
+
| "FO"
|
|
81
|
+
| "FJ"
|
|
82
|
+
| "FI"
|
|
83
|
+
| "FR"
|
|
84
|
+
| "GF"
|
|
85
|
+
| "PF"
|
|
86
|
+
| "TF"
|
|
87
|
+
| "GA"
|
|
88
|
+
| "GM"
|
|
89
|
+
| "GE"
|
|
90
|
+
| "DE"
|
|
91
|
+
| "GH"
|
|
92
|
+
| "GI"
|
|
93
|
+
| "GR"
|
|
94
|
+
| "GL"
|
|
95
|
+
| "GD"
|
|
96
|
+
| "GP"
|
|
97
|
+
| "GU"
|
|
98
|
+
| "GT"
|
|
99
|
+
| "GG"
|
|
100
|
+
| "GN"
|
|
101
|
+
| "GW"
|
|
102
|
+
| "GY"
|
|
103
|
+
| "HT"
|
|
104
|
+
| "HM"
|
|
105
|
+
| "VA"
|
|
106
|
+
| "HN"
|
|
107
|
+
| "HK"
|
|
108
|
+
| "HU"
|
|
109
|
+
| "IS"
|
|
110
|
+
| "IN"
|
|
111
|
+
| "ID"
|
|
112
|
+
| "IR"
|
|
113
|
+
| "IQ"
|
|
114
|
+
| "IE"
|
|
115
|
+
| "IM"
|
|
116
|
+
| "IL"
|
|
117
|
+
| "IT"
|
|
118
|
+
| "JM"
|
|
119
|
+
| "JP"
|
|
120
|
+
| "JE"
|
|
121
|
+
| "JO"
|
|
122
|
+
| "KZ"
|
|
123
|
+
| "KE"
|
|
124
|
+
| "KI"
|
|
125
|
+
| "KR"
|
|
126
|
+
| "KP"
|
|
127
|
+
| "KW"
|
|
128
|
+
| "KG"
|
|
129
|
+
| "LA"
|
|
130
|
+
| "LV"
|
|
131
|
+
| "LB"
|
|
132
|
+
| "LS"
|
|
133
|
+
| "LR"
|
|
134
|
+
| "LY"
|
|
135
|
+
| "LI"
|
|
136
|
+
| "LT"
|
|
137
|
+
| "LU"
|
|
138
|
+
| "MO"
|
|
139
|
+
| "MK"
|
|
140
|
+
| "MG"
|
|
141
|
+
| "MW"
|
|
142
|
+
| "MY"
|
|
143
|
+
| "MV"
|
|
144
|
+
| "ML"
|
|
145
|
+
| "MT"
|
|
146
|
+
| "MH"
|
|
147
|
+
| "MQ"
|
|
148
|
+
| "MR"
|
|
149
|
+
| "MU"
|
|
150
|
+
| "YT"
|
|
151
|
+
| "MX"
|
|
152
|
+
| "FM"
|
|
153
|
+
| "MD"
|
|
154
|
+
| "MC"
|
|
155
|
+
| "MN"
|
|
156
|
+
| "ME"
|
|
157
|
+
| "MS"
|
|
158
|
+
| "MA"
|
|
159
|
+
| "MZ"
|
|
160
|
+
| "MM"
|
|
161
|
+
| "NA"
|
|
162
|
+
| "NR"
|
|
163
|
+
| "NP"
|
|
164
|
+
| "NL"
|
|
165
|
+
| "NC"
|
|
166
|
+
| "NZ"
|
|
167
|
+
| "NI"
|
|
168
|
+
| "NE"
|
|
169
|
+
| "NG"
|
|
170
|
+
| "NU"
|
|
171
|
+
| "NF"
|
|
172
|
+
| "MP"
|
|
173
|
+
| "NO"
|
|
174
|
+
| "OM"
|
|
175
|
+
| "PK"
|
|
176
|
+
| "PW"
|
|
177
|
+
| "PS"
|
|
178
|
+
| "PA"
|
|
179
|
+
| "PG"
|
|
180
|
+
| "PY"
|
|
181
|
+
| "PE"
|
|
182
|
+
| "PH"
|
|
183
|
+
| "PN"
|
|
184
|
+
| "PL"
|
|
185
|
+
| "PT"
|
|
186
|
+
| "PR"
|
|
187
|
+
| "QA"
|
|
188
|
+
| "RE"
|
|
189
|
+
| "RO"
|
|
190
|
+
| "RU"
|
|
191
|
+
| "RW"
|
|
192
|
+
| "BL"
|
|
193
|
+
| "SH"
|
|
194
|
+
| "KN"
|
|
195
|
+
| "LC"
|
|
196
|
+
| "MF"
|
|
197
|
+
| "PM"
|
|
198
|
+
| "VC"
|
|
199
|
+
| "WS"
|
|
200
|
+
| "SM"
|
|
201
|
+
| "ST"
|
|
202
|
+
| "SA"
|
|
203
|
+
| "SN"
|
|
204
|
+
| "RS"
|
|
205
|
+
| "SC"
|
|
206
|
+
| "SL"
|
|
207
|
+
| "SG"
|
|
208
|
+
| "SX"
|
|
209
|
+
| "SK"
|
|
210
|
+
| "SI"
|
|
211
|
+
| "SB"
|
|
212
|
+
| "SO"
|
|
213
|
+
| "ZA"
|
|
214
|
+
| "GS"
|
|
215
|
+
| "SS"
|
|
216
|
+
| "ES"
|
|
217
|
+
| "LK"
|
|
218
|
+
| "SD"
|
|
219
|
+
| "SR"
|
|
220
|
+
| "SJ"
|
|
221
|
+
| "SZ"
|
|
222
|
+
| "SE"
|
|
223
|
+
| "CH"
|
|
224
|
+
| "SY"
|
|
225
|
+
| "TW"
|
|
226
|
+
| "TJ"
|
|
227
|
+
| "TZ"
|
|
228
|
+
| "TH"
|
|
229
|
+
| "TL"
|
|
230
|
+
| "TG"
|
|
231
|
+
| "TK"
|
|
232
|
+
| "TO"
|
|
233
|
+
| "TT"
|
|
234
|
+
| "TN"
|
|
235
|
+
| "TR"
|
|
236
|
+
| "TM"
|
|
237
|
+
| "TC"
|
|
238
|
+
| "TV"
|
|
239
|
+
| "UG"
|
|
240
|
+
| "UA"
|
|
241
|
+
| "AE"
|
|
242
|
+
| "GB"
|
|
243
|
+
| "US"
|
|
244
|
+
| "UM"
|
|
245
|
+
| "UY"
|
|
246
|
+
| "UZ"
|
|
247
|
+
| "VU"
|
|
248
|
+
| "VE"
|
|
249
|
+
| "VN"
|
|
250
|
+
| "VG"
|
|
251
|
+
| "VI"
|
|
252
|
+
| "WF"
|
|
253
|
+
| "EH"
|
|
254
|
+
| "YE"
|
|
255
|
+
| "ZM"
|
|
256
|
+
| "ZW";
|
|
257
|
+
|
|
258
|
+
// Core Odesli class
|
|
259
|
+
declare class Odesli {
|
|
260
|
+
constructor(options?: OdesliOptions);
|
|
261
|
+
|
|
262
|
+
// Core methods
|
|
263
|
+
fetch(urlOrUrls: string | string[], options?: FetchOptions): Promise<SongData | SongData[]>;
|
|
264
|
+
getByParams(platform: string, type: string, id: string, options?: FetchOptions): Promise<SongData>;
|
|
265
|
+
getById(id: string, options?: FetchOptions): Promise<SongData>;
|
|
266
|
+
|
|
267
|
+
// Utility methods
|
|
268
|
+
detectPlatform(url: string): string | null;
|
|
269
|
+
extractId(url: string): string | null;
|
|
270
|
+
getSupportedPlatforms(): string[];
|
|
271
|
+
getUserAgent(): string;
|
|
272
|
+
|
|
273
|
+
// Cache methods
|
|
274
|
+
clearCache(): void;
|
|
275
|
+
getCacheStats(): CacheStats;
|
|
276
|
+
|
|
277
|
+
// Static methods
|
|
278
|
+
static getCountryOptions(): Array<{ code: CountryCode; name: string }>;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Configuration options
|
|
282
|
+
interface OdesliOptions {
|
|
283
|
+
apiKey?: string;
|
|
284
|
+
version?: string;
|
|
285
|
+
cache?: boolean;
|
|
286
|
+
timeout?: number;
|
|
287
|
+
maxRetries?: number;
|
|
288
|
+
retryDelay?: number;
|
|
289
|
+
headers?: Record<string, string>;
|
|
290
|
+
baseUrl?: string;
|
|
291
|
+
validateParams?: boolean;
|
|
292
|
+
logger?: (message: string, level: string) => void;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Fetch options
|
|
296
|
+
interface FetchOptions {
|
|
297
|
+
country?: CountryCode;
|
|
298
|
+
skipCache?: boolean;
|
|
299
|
+
timeout?: number;
|
|
300
|
+
concurrency?: number;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// Song/Album data structure
|
|
304
|
+
interface SongData {
|
|
305
|
+
entityUniqueId: string;
|
|
306
|
+
entitiesByUniqueId: Record<string, EntityData>;
|
|
307
|
+
linksByPlatform: Record<string, PlatformLink>;
|
|
308
|
+
id: string;
|
|
309
|
+
title: string;
|
|
310
|
+
artist: string[];
|
|
311
|
+
type: string;
|
|
312
|
+
thumbnail: string;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
interface EntityData {
|
|
316
|
+
id: string;
|
|
317
|
+
title: string;
|
|
318
|
+
artistName: string[];
|
|
319
|
+
type: string;
|
|
320
|
+
thumbnailUrl: string;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
interface PlatformLink {
|
|
324
|
+
url: string;
|
|
325
|
+
nativeAppUriMobile?: string;
|
|
326
|
+
nativeAppUriDesktop?: string;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Cache statistics
|
|
330
|
+
interface CacheStats {
|
|
331
|
+
size: number;
|
|
332
|
+
ttl: number;
|
|
333
|
+
hitCount: number;
|
|
334
|
+
missCount: number;
|
|
335
|
+
hitRate: number;
|
|
336
|
+
totalRequests: number;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Rate Limiter
|
|
340
|
+
declare class RateLimiter {
|
|
341
|
+
constructor(options?: RateLimiterOptions);
|
|
342
|
+
waitForSlot(): Promise<void>;
|
|
343
|
+
handleRateLimitResponse(retryAfterSeconds?: number): Promise<void>;
|
|
344
|
+
getStatus(): RateLimiterStatus;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
interface RateLimiterOptions {
|
|
348
|
+
maxRequests?: number;
|
|
349
|
+
windowMs?: number;
|
|
350
|
+
strategy?: 'token-bucket' | 'leaky-bucket' | 'sliding-window';
|
|
351
|
+
retryAfterMs?: number;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
interface RateLimiterStatus {
|
|
355
|
+
available?: number;
|
|
356
|
+
max?: number;
|
|
357
|
+
refillRate?: number;
|
|
358
|
+
used?: number;
|
|
359
|
+
windowMs?: number;
|
|
360
|
+
queued?: number;
|
|
361
|
+
processing?: boolean;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// Metrics Collector
|
|
365
|
+
declare class MetricsCollector {
|
|
366
|
+
constructor(options?: MetricsOptions);
|
|
367
|
+
recordRequest(options: RequestMetrics): void;
|
|
368
|
+
recordError(error: Error, context?: Record<string, any>): void;
|
|
369
|
+
recordRateLimit(delayMs: number): void;
|
|
370
|
+
updateCacheMetrics(size: number): void;
|
|
371
|
+
getSummary(): MetricsSummary;
|
|
372
|
+
getDetailedMetrics(options?: DetailedMetricsOptions): Record<string, any>;
|
|
373
|
+
cleanup(): void;
|
|
374
|
+
reset(): void;
|
|
375
|
+
export(): {
|
|
376
|
+
summary: MetricsSummary;
|
|
377
|
+
detailed: Record<string, any>;
|
|
378
|
+
raw: {
|
|
379
|
+
metrics: any;
|
|
380
|
+
counters: any;
|
|
381
|
+
};
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
interface MetricsOptions {
|
|
386
|
+
enabled?: boolean;
|
|
387
|
+
retentionMs?: number;
|
|
388
|
+
maxDataPoints?: number;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
interface RequestMetrics {
|
|
392
|
+
url: string;
|
|
393
|
+
method?: string;
|
|
394
|
+
startTime: number;
|
|
395
|
+
endTime?: number;
|
|
396
|
+
success?: boolean;
|
|
397
|
+
statusCode?: number;
|
|
398
|
+
error?: string;
|
|
399
|
+
responseTime?: number;
|
|
400
|
+
platform?: string;
|
|
401
|
+
country?: string;
|
|
402
|
+
cacheHit?: boolean;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
interface MetricsSummary {
|
|
406
|
+
counters: {
|
|
407
|
+
totalRequests: number;
|
|
408
|
+
successfulRequests: number;
|
|
409
|
+
failedRequests: number;
|
|
410
|
+
cacheHits: number;
|
|
411
|
+
cacheMisses: number;
|
|
412
|
+
rateLimitHits: number;
|
|
413
|
+
};
|
|
414
|
+
recent: {
|
|
415
|
+
requests: number;
|
|
416
|
+
errors: number;
|
|
417
|
+
avgResponseTime: number;
|
|
418
|
+
requestsPerMinute: number;
|
|
419
|
+
};
|
|
420
|
+
rates: {
|
|
421
|
+
successRate: number;
|
|
422
|
+
cacheHitRate: number;
|
|
423
|
+
errorRate: number;
|
|
424
|
+
};
|
|
425
|
+
cache: {
|
|
426
|
+
hits: number;
|
|
427
|
+
misses: number;
|
|
428
|
+
size: number;
|
|
429
|
+
};
|
|
430
|
+
rateLimits: {
|
|
431
|
+
hits: number;
|
|
432
|
+
avgDelay: number;
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
interface DetailedMetricsOptions {
|
|
437
|
+
startTime?: number;
|
|
438
|
+
endTime?: number;
|
|
439
|
+
groupBy?: 'hour' | 'minute' | 'platform' | 'country';
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// Plugin System
|
|
443
|
+
declare class PluginSystem {
|
|
444
|
+
constructor();
|
|
445
|
+
registerPlugin(name: string, plugin: Plugin): PluginSystem;
|
|
446
|
+
unregisterPlugin(name: string): PluginSystem;
|
|
447
|
+
registerHook(name: string, defaultHandlers?: any[]): PluginSystem;
|
|
448
|
+
registerHookHandler(hookName: string, handler: (context: any) => Promise<void> | void, pluginName?: string): PluginSystem;
|
|
449
|
+
executeHook(hookName: string, context?: Record<string, any>): Promise<void>;
|
|
450
|
+
executeMiddleware(context: any, next: () => Promise<any>): Promise<any>;
|
|
451
|
+
transformData(data: any, type: string, context?: Record<string, any>): Promise<any>;
|
|
452
|
+
getPlugin(name: string): Plugin | undefined;
|
|
453
|
+
getPlugins(): string[];
|
|
454
|
+
hasPlugin(name: string): boolean;
|
|
455
|
+
getPluginInfo(name: string): PluginInfo | null;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
interface Plugin {
|
|
459
|
+
name?: string;
|
|
460
|
+
version?: string;
|
|
461
|
+
description?: string;
|
|
462
|
+
init?: () => void;
|
|
463
|
+
cleanup?: () => void;
|
|
464
|
+
hooks?: Record<string, (context: any) => Promise<void> | void>;
|
|
465
|
+
middleware?: (context: any, next: () => Promise<any>) => Promise<any>;
|
|
466
|
+
transformers?: Record<string, (data: any, context: any) => Promise<any> | any>;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
interface PluginInfo {
|
|
470
|
+
name: string;
|
|
471
|
+
hooks: string[];
|
|
472
|
+
hasMiddleware: boolean;
|
|
473
|
+
hasTransformers: boolean;
|
|
474
|
+
version?: string;
|
|
475
|
+
description?: string;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// Built-in plugins
|
|
479
|
+
declare const loggingPlugin: Plugin;
|
|
480
|
+
declare const cachingPlugin: Plugin;
|
|
481
|
+
declare const analyticsPlugin: Plugin;
|
|
482
|
+
declare const responseTransformerPlugin: Plugin;
|
|
483
|
+
|
|
484
|
+
declare namespace Page {
|
|
485
|
+
interface Response {
|
|
486
|
+
/**
|
|
487
|
+
* The unique ID for the input entity that was supplied in the request.
|
|
488
|
+
*
|
|
489
|
+
* The data for this entity, such as title, artistName, etc. will be found in an object at `entitiesByUniqueId[entityUniqueId]`
|
|
490
|
+
*/
|
|
491
|
+
entityUniqueId: string,
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Song/Album Title of the given response, same as `Response.entitiesByUniqueId[Response.entityUniqueId].title`
|
|
495
|
+
*/
|
|
496
|
+
title: string,
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Artist's Name of the given response, same as `Response.entitiesByUniqueId[Response.entityUniqueId].artistName`
|
|
500
|
+
*/
|
|
501
|
+
artist: string,
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Type (song or album) of the given response, same as `Response.entitiesByUniqueId[Response.entityUniqueId].type`
|
|
505
|
+
*/
|
|
506
|
+
type: entityType,
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Thumbnail of the given response, same as `Response.entitiesByUniqueId[Response.entityUniqueId].thumbnailUrl`
|
|
510
|
+
*/
|
|
511
|
+
thumbnail: string,
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* The userCountry query param that was supplied in the request. It signals
|
|
515
|
+
* the country/availability we use to query the streaming platforms. Defaults
|
|
516
|
+
* to 'US' if no userCountry supplied in the request.
|
|
517
|
+
*
|
|
518
|
+
* NOTE: As a fallback, our service may respond with matches that were found
|
|
519
|
+
* in a locale other than the userCountry supplied
|
|
520
|
+
*/
|
|
521
|
+
userCountry: CountryCode,
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* A URL that will render the Songlink page for this entity
|
|
525
|
+
*/
|
|
526
|
+
pageUrl: string,
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* A collection of objects. Each key is a platform, and each value is an
|
|
530
|
+
* object that contains data for linking to the match
|
|
531
|
+
*/
|
|
532
|
+
linksByPlatform: {
|
|
533
|
+
/**
|
|
534
|
+
* Each key in `linksByPlatform` is a Platform. A Platform will exist here
|
|
535
|
+
* only if there is a match found. E.g. if there is no YouTube match found,
|
|
536
|
+
* then neither `youtube` or `youtubeMusic` properties will exist here
|
|
537
|
+
*/
|
|
538
|
+
[key in Platform]: {
|
|
539
|
+
/**
|
|
540
|
+
* The unique ID for this entity. Use it to look up data about this entity
|
|
541
|
+
* at `entitiesByUniqueId[entityUniqueId]`
|
|
542
|
+
*/
|
|
543
|
+
entityUniqueId: string,
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* The URL for this match
|
|
547
|
+
*/
|
|
548
|
+
url: string,
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* The native app URI that can be used on mobile devices to open this
|
|
552
|
+
* entity directly in the native app
|
|
553
|
+
*/
|
|
554
|
+
nativeAppUriMobile?: string,
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* The native app URI that can be used on desktop devices to open this
|
|
558
|
+
* entity directly in the native app
|
|
559
|
+
*/
|
|
560
|
+
nativeAppUriDesktop?: string,
|
|
561
|
+
};
|
|
562
|
+
},
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* A collection of objects. Each key is a unique identifier for a streaming
|
|
566
|
+
* entity, and each value is an object that contains data for that entity,
|
|
567
|
+
* such as `title`, `artistName`, `thumbnailUrl`, etc.
|
|
568
|
+
*/
|
|
569
|
+
entitiesByUniqueId: {
|
|
570
|
+
/**
|
|
571
|
+
* The unique identifier key for a streaming entitiy
|
|
572
|
+
*/
|
|
573
|
+
[entityUniqueId: string]: {
|
|
574
|
+
/**
|
|
575
|
+
* This is the unique identifier on the streaming platform/API provider
|
|
576
|
+
*/
|
|
577
|
+
id: string,
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* The type of media this entity is
|
|
581
|
+
*/
|
|
582
|
+
type: entityType,
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* The title of the `song`/`album`
|
|
586
|
+
*/
|
|
587
|
+
title?: string,
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* The artist/s of the `song`/`album`
|
|
591
|
+
*/
|
|
592
|
+
artistName?: [string],
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* The coverart image URL of the `song`/`album`
|
|
596
|
+
*/
|
|
597
|
+
thumbnailUrl?: string,
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Coverart's width
|
|
601
|
+
*/
|
|
602
|
+
thumbnailWidth?: number,
|
|
603
|
+
/**
|
|
604
|
+
* Coverart's height
|
|
605
|
+
*/
|
|
606
|
+
thumbnailHeight?: number,
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* The API provider that powered this match. Useful if you'd like to use
|
|
610
|
+
* this entity's data to query the API directly
|
|
611
|
+
*/
|
|
612
|
+
apiProvider: APIProvider,
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* An array of platforms that are "powered" by this entity. E.g. an entity
|
|
616
|
+
* from Apple Music will generally have a `platforms` array of
|
|
617
|
+
* `["appleMusic", "itunes"]` since both those platforms/links are derived
|
|
618
|
+
* from this single entity
|
|
619
|
+
*/
|
|
620
|
+
platforms: Platform[],
|
|
621
|
+
},
|
|
622
|
+
},
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
type Platform =
|
|
627
|
+
| 'spotify'
|
|
628
|
+
| 'itunes'
|
|
629
|
+
| 'appleMusic'
|
|
630
|
+
| 'youtube'
|
|
631
|
+
| 'youtubeMusic'
|
|
632
|
+
| 'google'
|
|
633
|
+
| 'googleStore'
|
|
634
|
+
| 'pandora'
|
|
635
|
+
| 'deezer'
|
|
636
|
+
| 'tidal'
|
|
637
|
+
| 'amazonStore'
|
|
638
|
+
| 'amazonMusic'
|
|
639
|
+
| 'soundcloud'
|
|
640
|
+
| 'napster'
|
|
641
|
+
| 'yandex'
|
|
642
|
+
| 'spinrilla';
|
|
643
|
+
|
|
644
|
+
type APIProvider =
|
|
645
|
+
| 'spotify'
|
|
646
|
+
| 'itunes'
|
|
647
|
+
| 'youtube'
|
|
648
|
+
| 'google'
|
|
649
|
+
| 'pandora'
|
|
650
|
+
| 'deezer'
|
|
651
|
+
| 'tidal'
|
|
652
|
+
| 'amazon'
|
|
653
|
+
| 'soundcloud'
|
|
654
|
+
| 'napster'
|
|
655
|
+
| 'yandex'
|
|
656
|
+
| 'spinrilla';
|
|
657
|
+
|
|
658
|
+
type entityType =
|
|
659
|
+
| 'song'
|
|
660
|
+
| 'album'
|
|
661
|
+
|
|
662
|
+
// Export the main class
|
|
663
|
+
export = Odesli;
|