@audd/sdk 1.5.6 → 1.5.8
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/README.md +67 -4
- package/dist/index.cjs +25 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -7
- package/dist/index.d.ts +36 -7
- package/dist/index.js +25 -14
- package/dist/index.js.map +1 -1
- package/dist/longpoll.cjs +5 -1
- package/dist/longpoll.cjs.map +1 -1
- package/dist/longpoll.js +5 -1
- package/dist/longpoll.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { S as StreamCallbackMatch, a as StreamCallbackNotification, H as HttpClient, b as Stream, L as LongpollPoll, c as LyricsResult, F as FetchLike, R as RecognitionResult, E as EnterpriseMatch } from './longpollCore-DMBdcGSM.cjs';
|
|
2
2
|
export { d as EnterpriseChunkResult, e as StreamCallbackSong, f as StreamingProvider } from './longpollCore-DMBdcGSM.cjs';
|
|
3
3
|
|
|
4
|
-
declare const VERSION = "1.
|
|
4
|
+
declare const VERSION = "1.5.8";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Auto-detect what kind of audio source the caller passed and convert to
|
|
@@ -38,11 +38,15 @@ type Source = string | URL | Blob | Uint8Array;
|
|
|
38
38
|
* - RECOGNITION — `recognize`, `recognizeEnterprise`, `advanced.findLyrics`:
|
|
39
39
|
* retry on pre-upload connection failures + 5xx.
|
|
40
40
|
* DO NOT retry on read-timeout-after-upload (cost protection).
|
|
41
|
-
* - MUTATING — `streams.add`, `streams.delete`, etc
|
|
41
|
+
* - MUTATING — `streams.add`, `streams.delete`, etc.:
|
|
42
42
|
* retry only on pre-upload connection failures. DO NOT retry
|
|
43
43
|
* 5xx (the side effect may have happened).
|
|
44
|
+
* - NONE — `customCatalog.add`: never retry. Custom-catalog upload is
|
|
45
|
+
* metered; auto-retry on transport failure could double-charge
|
|
46
|
+
* for the same audio fingerprinting. Surface a clean error and
|
|
47
|
+
* let the caller decide.
|
|
44
48
|
*/
|
|
45
|
-
type RetryClass = "read" | "recognition" | "mutating";
|
|
49
|
+
type RetryClass = "read" | "recognition" | "mutating" | "none";
|
|
46
50
|
interface RetryPolicy {
|
|
47
51
|
retryClass: RetryClass;
|
|
48
52
|
maxAttempts: number;
|
|
@@ -215,12 +219,22 @@ declare function handleCallback(req: CallbackRequestLike): Promise<ParsedCallbac
|
|
|
215
219
|
|
|
216
220
|
interface SetCallbackUrlOptions {
|
|
217
221
|
returnMetadata?: string | string[];
|
|
222
|
+
/**
|
|
223
|
+
* Additional form fields the typed options don't cover. Typed options
|
|
224
|
+
* (`url`) win on collision.
|
|
225
|
+
*/
|
|
226
|
+
extraParameters?: Record<string, string>;
|
|
218
227
|
}
|
|
219
228
|
interface AddStreamOptions {
|
|
220
229
|
url: string;
|
|
221
230
|
radioId: number;
|
|
222
231
|
/** "before" delivers callbacks at song start; default delivers at song end. */
|
|
223
232
|
callbacks?: "before" | string;
|
|
233
|
+
/**
|
|
234
|
+
* Additional form fields the typed options don't cover. Typed options
|
|
235
|
+
* (`url`, `radioId`, `callbacks`) win on collision.
|
|
236
|
+
*/
|
|
237
|
+
extraParameters?: Record<string, string>;
|
|
224
238
|
}
|
|
225
239
|
interface LongpollOptions {
|
|
226
240
|
sinceTime?: number;
|
|
@@ -318,8 +332,8 @@ interface CustomCatalogAddOptions {
|
|
|
318
332
|
}
|
|
319
333
|
declare class CustomCatalog {
|
|
320
334
|
private readonly http;
|
|
321
|
-
private readonly
|
|
322
|
-
constructor(http: HttpClient,
|
|
335
|
+
private readonly noRetryPolicy;
|
|
336
|
+
constructor(http: HttpClient, noRetryPolicy: RetryPolicy);
|
|
323
337
|
/**
|
|
324
338
|
* **This is NOT how you submit audio for music recognition.** For
|
|
325
339
|
* recognition, use `audd.recognize()` (or `audd.recognizeEnterprise()` for
|
|
@@ -331,6 +345,11 @@ declare class CustomCatalog {
|
|
|
331
345
|
* Calling this again with the same `audioId` re-fingerprints that slot.
|
|
332
346
|
* There is no public list/delete endpoint; track `audioId` ↔ song
|
|
333
347
|
* mappings on your side.
|
|
348
|
+
*
|
|
349
|
+
* **No automatic retry.** Custom-catalog upload is metered, and a transport
|
|
350
|
+
* failure could otherwise cause a silent re-upload that double-charges. Any
|
|
351
|
+
* 5xx or pre-upload connection error surfaces as a clean exception — the
|
|
352
|
+
* caller decides whether to retry.
|
|
334
353
|
*/
|
|
335
354
|
add(opts: CustomCatalogAddOptions): Promise<void>;
|
|
336
355
|
}
|
|
@@ -388,7 +407,7 @@ interface AudDOptions {
|
|
|
388
407
|
}
|
|
389
408
|
type ReturnMetadata = "apple_music" | "spotify" | "deezer" | "napster" | "musicbrainz" | string;
|
|
390
409
|
interface RecognizeOptions {
|
|
391
|
-
|
|
410
|
+
returnMetadata?: ReturnMetadata | ReturnMetadata[];
|
|
392
411
|
market?: string;
|
|
393
412
|
/** Per-call timeout in ms; overrides the client default. */
|
|
394
413
|
timeoutMs?: number;
|
|
@@ -399,9 +418,14 @@ interface RecognizeOptions {
|
|
|
399
418
|
* already done metered work and the credit is consumed regardless.
|
|
400
419
|
*/
|
|
401
420
|
signal?: AbortSignal;
|
|
421
|
+
/**
|
|
422
|
+
* Additional form fields the typed options don't cover — undocumented
|
|
423
|
+
* parameters, beta features. Typed options win on collision.
|
|
424
|
+
*/
|
|
425
|
+
extraParameters?: Record<string, string>;
|
|
402
426
|
}
|
|
403
427
|
interface RecognizeEnterpriseOptions {
|
|
404
|
-
|
|
428
|
+
returnMetadata?: ReturnMetadata | ReturnMetadata[];
|
|
405
429
|
skip?: number;
|
|
406
430
|
every?: number;
|
|
407
431
|
limit?: number;
|
|
@@ -414,6 +438,11 @@ interface RecognizeEnterpriseOptions {
|
|
|
414
438
|
* For multi-hour enterprise calls, this is the right way to cancel.
|
|
415
439
|
*/
|
|
416
440
|
signal?: AbortSignal;
|
|
441
|
+
/**
|
|
442
|
+
* Additional form fields the typed options don't cover. Typed options
|
|
443
|
+
* win on collision.
|
|
444
|
+
*/
|
|
445
|
+
extraParameters?: Record<string, string>;
|
|
417
446
|
}
|
|
418
447
|
/**
|
|
419
448
|
* The AudD client. Async-only — every method returns a `Promise`.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { S as StreamCallbackMatch, a as StreamCallbackNotification, H as HttpClient, b as Stream, L as LongpollPoll, c as LyricsResult, F as FetchLike, R as RecognitionResult, E as EnterpriseMatch } from './longpollCore-DMBdcGSM.js';
|
|
2
2
|
export { d as EnterpriseChunkResult, e as StreamCallbackSong, f as StreamingProvider } from './longpollCore-DMBdcGSM.js';
|
|
3
3
|
|
|
4
|
-
declare const VERSION = "1.
|
|
4
|
+
declare const VERSION = "1.5.8";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Auto-detect what kind of audio source the caller passed and convert to
|
|
@@ -38,11 +38,15 @@ type Source = string | URL | Blob | Uint8Array;
|
|
|
38
38
|
* - RECOGNITION — `recognize`, `recognizeEnterprise`, `advanced.findLyrics`:
|
|
39
39
|
* retry on pre-upload connection failures + 5xx.
|
|
40
40
|
* DO NOT retry on read-timeout-after-upload (cost protection).
|
|
41
|
-
* - MUTATING — `streams.add`, `streams.delete`, etc
|
|
41
|
+
* - MUTATING — `streams.add`, `streams.delete`, etc.:
|
|
42
42
|
* retry only on pre-upload connection failures. DO NOT retry
|
|
43
43
|
* 5xx (the side effect may have happened).
|
|
44
|
+
* - NONE — `customCatalog.add`: never retry. Custom-catalog upload is
|
|
45
|
+
* metered; auto-retry on transport failure could double-charge
|
|
46
|
+
* for the same audio fingerprinting. Surface a clean error and
|
|
47
|
+
* let the caller decide.
|
|
44
48
|
*/
|
|
45
|
-
type RetryClass = "read" | "recognition" | "mutating";
|
|
49
|
+
type RetryClass = "read" | "recognition" | "mutating" | "none";
|
|
46
50
|
interface RetryPolicy {
|
|
47
51
|
retryClass: RetryClass;
|
|
48
52
|
maxAttempts: number;
|
|
@@ -215,12 +219,22 @@ declare function handleCallback(req: CallbackRequestLike): Promise<ParsedCallbac
|
|
|
215
219
|
|
|
216
220
|
interface SetCallbackUrlOptions {
|
|
217
221
|
returnMetadata?: string | string[];
|
|
222
|
+
/**
|
|
223
|
+
* Additional form fields the typed options don't cover. Typed options
|
|
224
|
+
* (`url`) win on collision.
|
|
225
|
+
*/
|
|
226
|
+
extraParameters?: Record<string, string>;
|
|
218
227
|
}
|
|
219
228
|
interface AddStreamOptions {
|
|
220
229
|
url: string;
|
|
221
230
|
radioId: number;
|
|
222
231
|
/** "before" delivers callbacks at song start; default delivers at song end. */
|
|
223
232
|
callbacks?: "before" | string;
|
|
233
|
+
/**
|
|
234
|
+
* Additional form fields the typed options don't cover. Typed options
|
|
235
|
+
* (`url`, `radioId`, `callbacks`) win on collision.
|
|
236
|
+
*/
|
|
237
|
+
extraParameters?: Record<string, string>;
|
|
224
238
|
}
|
|
225
239
|
interface LongpollOptions {
|
|
226
240
|
sinceTime?: number;
|
|
@@ -318,8 +332,8 @@ interface CustomCatalogAddOptions {
|
|
|
318
332
|
}
|
|
319
333
|
declare class CustomCatalog {
|
|
320
334
|
private readonly http;
|
|
321
|
-
private readonly
|
|
322
|
-
constructor(http: HttpClient,
|
|
335
|
+
private readonly noRetryPolicy;
|
|
336
|
+
constructor(http: HttpClient, noRetryPolicy: RetryPolicy);
|
|
323
337
|
/**
|
|
324
338
|
* **This is NOT how you submit audio for music recognition.** For
|
|
325
339
|
* recognition, use `audd.recognize()` (or `audd.recognizeEnterprise()` for
|
|
@@ -331,6 +345,11 @@ declare class CustomCatalog {
|
|
|
331
345
|
* Calling this again with the same `audioId` re-fingerprints that slot.
|
|
332
346
|
* There is no public list/delete endpoint; track `audioId` ↔ song
|
|
333
347
|
* mappings on your side.
|
|
348
|
+
*
|
|
349
|
+
* **No automatic retry.** Custom-catalog upload is metered, and a transport
|
|
350
|
+
* failure could otherwise cause a silent re-upload that double-charges. Any
|
|
351
|
+
* 5xx or pre-upload connection error surfaces as a clean exception — the
|
|
352
|
+
* caller decides whether to retry.
|
|
334
353
|
*/
|
|
335
354
|
add(opts: CustomCatalogAddOptions): Promise<void>;
|
|
336
355
|
}
|
|
@@ -388,7 +407,7 @@ interface AudDOptions {
|
|
|
388
407
|
}
|
|
389
408
|
type ReturnMetadata = "apple_music" | "spotify" | "deezer" | "napster" | "musicbrainz" | string;
|
|
390
409
|
interface RecognizeOptions {
|
|
391
|
-
|
|
410
|
+
returnMetadata?: ReturnMetadata | ReturnMetadata[];
|
|
392
411
|
market?: string;
|
|
393
412
|
/** Per-call timeout in ms; overrides the client default. */
|
|
394
413
|
timeoutMs?: number;
|
|
@@ -399,9 +418,14 @@ interface RecognizeOptions {
|
|
|
399
418
|
* already done metered work and the credit is consumed regardless.
|
|
400
419
|
*/
|
|
401
420
|
signal?: AbortSignal;
|
|
421
|
+
/**
|
|
422
|
+
* Additional form fields the typed options don't cover — undocumented
|
|
423
|
+
* parameters, beta features. Typed options win on collision.
|
|
424
|
+
*/
|
|
425
|
+
extraParameters?: Record<string, string>;
|
|
402
426
|
}
|
|
403
427
|
interface RecognizeEnterpriseOptions {
|
|
404
|
-
|
|
428
|
+
returnMetadata?: ReturnMetadata | ReturnMetadata[];
|
|
405
429
|
skip?: number;
|
|
406
430
|
every?: number;
|
|
407
431
|
limit?: number;
|
|
@@ -414,6 +438,11 @@ interface RecognizeEnterpriseOptions {
|
|
|
414
438
|
* For multi-hour enterprise calls, this is the right way to cancel.
|
|
415
439
|
*/
|
|
416
440
|
signal?: AbortSignal;
|
|
441
|
+
/**
|
|
442
|
+
* Additional form fields the typed options don't cover. Typed options
|
|
443
|
+
* win on collision.
|
|
444
|
+
*/
|
|
445
|
+
extraParameters?: Record<string, string>;
|
|
417
446
|
}
|
|
418
447
|
/**
|
|
419
448
|
* The AudD client. Async-only — every method returns a `Promise`.
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as path from 'path';
|
|
|
3
3
|
import { createHash } from 'crypto';
|
|
4
4
|
|
|
5
5
|
// src/version.ts
|
|
6
|
-
var VERSION = "1.
|
|
6
|
+
var VERSION = "1.5.8";
|
|
7
7
|
|
|
8
8
|
// src/errors.ts
|
|
9
9
|
var AudDError = class extends Error {
|
|
@@ -662,6 +662,8 @@ function shouldRetryResponse(resp, retryClass) {
|
|
|
662
662
|
return s >= HTTP_SERVER_ERROR_FLOOR;
|
|
663
663
|
case "mutating":
|
|
664
664
|
return false;
|
|
665
|
+
case "none":
|
|
666
|
+
return false;
|
|
665
667
|
}
|
|
666
668
|
}
|
|
667
669
|
function shouldRetryError(err, retryClass) {
|
|
@@ -672,6 +674,8 @@ function shouldRetryError(err, retryClass) {
|
|
|
672
674
|
return isPreUploadConnectionError(err);
|
|
673
675
|
case "mutating":
|
|
674
676
|
return isPreUploadConnectionError(err);
|
|
677
|
+
case "none":
|
|
678
|
+
return false;
|
|
675
679
|
}
|
|
676
680
|
}
|
|
677
681
|
function sleep(ms) {
|
|
@@ -1101,7 +1105,9 @@ var Streams = class {
|
|
|
1101
1105
|
*/
|
|
1102
1106
|
async setCallbackUrl(url, opts = {}) {
|
|
1103
1107
|
const finalUrl = addReturnToUrl(url, opts.returnMetadata);
|
|
1104
|
-
|
|
1108
|
+
const fields = opts.extraParameters ? { ...opts.extraParameters } : {};
|
|
1109
|
+
fields["url"] = finalUrl;
|
|
1110
|
+
await this.post("setCallbackUrl", fields, this.mutatingPolicy);
|
|
1105
1111
|
}
|
|
1106
1112
|
/** Get the currently registered callback URL. */
|
|
1107
1113
|
async getCallbackUrl() {
|
|
@@ -1110,10 +1116,9 @@ var Streams = class {
|
|
|
1110
1116
|
}
|
|
1111
1117
|
/** Register a new stream for real-time recognition. */
|
|
1112
1118
|
async add(opts) {
|
|
1113
|
-
const fields = {
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
};
|
|
1119
|
+
const fields = opts.extraParameters ? { ...opts.extraParameters } : {};
|
|
1120
|
+
fields["url"] = opts.url;
|
|
1121
|
+
fields["radio_id"] = String(opts.radioId);
|
|
1117
1122
|
if (opts.callbacks !== void 0) fields["callbacks"] = opts.callbacks;
|
|
1118
1123
|
await this.post("addStream", fields, this.mutatingPolicy);
|
|
1119
1124
|
}
|
|
@@ -1244,12 +1249,12 @@ async function runRetried2(fn, policy) {
|
|
|
1244
1249
|
}
|
|
1245
1250
|
}
|
|
1246
1251
|
var CustomCatalog = class {
|
|
1247
|
-
constructor(http,
|
|
1252
|
+
constructor(http, noRetryPolicy) {
|
|
1248
1253
|
this.http = http;
|
|
1249
|
-
this.
|
|
1254
|
+
this.noRetryPolicy = noRetryPolicy;
|
|
1250
1255
|
}
|
|
1251
1256
|
http;
|
|
1252
|
-
|
|
1257
|
+
noRetryPolicy;
|
|
1253
1258
|
/**
|
|
1254
1259
|
* **This is NOT how you submit audio for music recognition.** For
|
|
1255
1260
|
* recognition, use `audd.recognize()` (or `audd.recognizeEnterprise()` for
|
|
@@ -1261,6 +1266,11 @@ var CustomCatalog = class {
|
|
|
1261
1266
|
* Calling this again with the same `audioId` re-fingerprints that slot.
|
|
1262
1267
|
* There is no public list/delete endpoint; track `audioId` ↔ song
|
|
1263
1268
|
* mappings on your side.
|
|
1269
|
+
*
|
|
1270
|
+
* **No automatic retry.** Custom-catalog upload is metered, and a transport
|
|
1271
|
+
* failure could otherwise cause a silent re-upload that double-charges. Any
|
|
1272
|
+
* 5xx or pre-upload connection error surfaces as a clean exception — the
|
|
1273
|
+
* caller decides whether to retry.
|
|
1264
1274
|
*/
|
|
1265
1275
|
async add(opts) {
|
|
1266
1276
|
const reopen = prepareSource(opts.source);
|
|
@@ -1269,7 +1279,7 @@ var CustomCatalog = class {
|
|
|
1269
1279
|
const prepared = await reopen();
|
|
1270
1280
|
const fields = { ...prepared.fields, audio_id: audioId };
|
|
1271
1281
|
return this.http.postForm(UPLOAD_URL, fields);
|
|
1272
|
-
}, this.
|
|
1282
|
+
}, this.noRetryPolicy);
|
|
1273
1283
|
decodeSuccess2(resp.jsonBody, resp.httpStatus, resp.requestId);
|
|
1274
1284
|
}
|
|
1275
1285
|
};
|
|
@@ -1362,8 +1372,8 @@ function formatReturn(value) {
|
|
|
1362
1372
|
return Array.isArray(value) ? value.join(",") : value;
|
|
1363
1373
|
}
|
|
1364
1374
|
function buildEnterpriseFields(opts) {
|
|
1365
|
-
const fields = {};
|
|
1366
|
-
const ret = formatReturn(opts.
|
|
1375
|
+
const fields = opts.extraParameters ? { ...opts.extraParameters } : {};
|
|
1376
|
+
const ret = formatReturn(opts.returnMetadata);
|
|
1367
1377
|
if (ret !== void 0) fields["return"] = ret;
|
|
1368
1378
|
if (opts.skip !== void 0) fields["skip"] = String(opts.skip);
|
|
1369
1379
|
if (opts.every !== void 0) fields["every"] = String(opts.every);
|
|
@@ -1513,7 +1523,7 @@ var AudD = class {
|
|
|
1513
1523
|
/** Sub-namespace for the private fingerprint catalog. NOT for recognition. */
|
|
1514
1524
|
get customCatalog() {
|
|
1515
1525
|
if (this._customCatalog === void 0) {
|
|
1516
|
-
this._customCatalog = new CustomCatalog(this._http, this.policyFor("
|
|
1526
|
+
this._customCatalog = new CustomCatalog(this._http, this.policyFor("none"));
|
|
1517
1527
|
}
|
|
1518
1528
|
return this._customCatalog;
|
|
1519
1529
|
}
|
|
@@ -1532,7 +1542,7 @@ var AudD = class {
|
|
|
1532
1542
|
*/
|
|
1533
1543
|
async recognize(source, opts = {}) {
|
|
1534
1544
|
const reopen = prepareSource(source);
|
|
1535
|
-
const ret = formatReturn(opts.
|
|
1545
|
+
const ret = formatReturn(opts.returnMetadata);
|
|
1536
1546
|
const market = opts.market;
|
|
1537
1547
|
const policy = this.policyFor("recognition");
|
|
1538
1548
|
const url = `${API_BASE3}/`;
|
|
@@ -1552,6 +1562,7 @@ var AudD = class {
|
|
|
1552
1562
|
resp = await runRetried4(async () => {
|
|
1553
1563
|
const prepared = await reopen();
|
|
1554
1564
|
const fields = { ...prepared.fields };
|
|
1565
|
+
if (opts.extraParameters) Object.assign(fields, opts.extraParameters);
|
|
1555
1566
|
if (ret !== void 0) fields["return"] = ret;
|
|
1556
1567
|
if (market !== void 0) fields["market"] = market;
|
|
1557
1568
|
return this._http.postForm(url, fields, {
|