@audd/sdk 1.5.12 → 1.5.14
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 +3 -3
- package/dist/index.cjs +44 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +44 -18
- package/dist/index.js.map +1 -1
- package/dist/longpoll.cjs +33 -8
- package/dist/longpoll.cjs.map +1 -1
- package/dist/longpoll.js +33 -8
- package/dist/longpoll.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -104,7 +104,7 @@ console.log(song?.spotify?.uri); // spotify:track:...
|
|
|
104
104
|
console.log(song?.previewUrl()); // first preview across requested providers, or null
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
-
Valid `returnMetadata` values: `apple_music`, `spotify`, `deezer`,
|
|
107
|
+
Valid `returnMetadata` values: `apple_music`, `spotify`, `deezer`,
|
|
108
108
|
`musicbrainz`. Blocks are `undefined` when not requested.
|
|
109
109
|
|
|
110
110
|
`streamingUrl(provider)` prefers the direct provider URL when you
|
|
@@ -135,8 +135,8 @@ The same `extraParameters` field is on `RecognizeEnterpriseOptions`, `SetCallbac
|
|
|
135
135
|
|
|
136
136
|
## Long files (enterprise)
|
|
137
137
|
|
|
138
|
-
`recognizeEnterprise`
|
|
139
|
-
|
|
138
|
+
`recognizeEnterprise` scans the whole file and returns a flat array of
|
|
139
|
+
matches:
|
|
140
140
|
|
|
141
141
|
```ts
|
|
142
142
|
const matches = await audd.recognizeEnterprise("./show.mp3", { limit: 20 });
|
package/dist/index.cjs
CHANGED
|
@@ -25,7 +25,7 @@ function _interopNamespace(e) {
|
|
|
25
25
|
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
26
26
|
|
|
27
27
|
// src/version.ts
|
|
28
|
-
var VERSION = "1.5.
|
|
28
|
+
var VERSION = "1.5.14";
|
|
29
29
|
|
|
30
30
|
// src/errors.ts
|
|
31
31
|
var AudDError = class extends Error {
|
|
@@ -155,7 +155,7 @@ function brandedMessageOf(result) {
|
|
|
155
155
|
if (typeof r.title === "string" && r.title.length > 0) parts.push(r.title);
|
|
156
156
|
return parts.length === 0 ? null : parts.join(" \u2014 ");
|
|
157
157
|
}
|
|
158
|
-
var CUSTOM_CATALOG_PREFIX = "Adding songs to your custom catalog requires enterprise access that isn't enabled on your account.\n\nNote: the custom-catalog endpoint is for adding songs to your private fingerprint database, not for music recognition. If you intended to identify music, use recognize(...) (or recognizeEnterprise(...)
|
|
158
|
+
var CUSTOM_CATALOG_PREFIX = "Adding songs to your custom catalog requires enterprise access that isn't enabled on your account.\n\nNote: the custom-catalog endpoint is for adding songs to your private fingerprint database, not for music recognition. If you intended to identify music, use recognize(...) (or recognizeEnterprise(...) to scan beyond the first 12 seconds of a file) instead.\n\nTo request custom-catalog access, contact api@audd.io.\n\n";
|
|
159
159
|
function raiseFromErrorResponse(body, opts) {
|
|
160
160
|
const code = body.error?.error_code ?? 0;
|
|
161
161
|
const message = body.error?.error_message ?? "";
|
|
@@ -339,13 +339,38 @@ function asObjectLenient(raw) {
|
|
|
339
339
|
return asObject(raw) ?? {};
|
|
340
340
|
}
|
|
341
341
|
function asString(v) {
|
|
342
|
-
|
|
342
|
+
if (typeof v === "string") return v;
|
|
343
|
+
if (typeof v === "number" || typeof v === "boolean") return String(v);
|
|
344
|
+
return void 0;
|
|
345
|
+
}
|
|
346
|
+
function toFiniteNumber(v) {
|
|
347
|
+
if (typeof v === "number") return Number.isFinite(v) ? v : void 0;
|
|
348
|
+
if (typeof v === "boolean") return v ? 1 : 0;
|
|
349
|
+
if (typeof v === "string") {
|
|
350
|
+
const t = v.trim();
|
|
351
|
+
if (t === "") return void 0;
|
|
352
|
+
const n = Number(t);
|
|
353
|
+
return Number.isFinite(n) ? n : void 0;
|
|
354
|
+
}
|
|
355
|
+
return void 0;
|
|
343
356
|
}
|
|
344
357
|
function asNumber(v) {
|
|
345
|
-
return
|
|
358
|
+
return toFiniteNumber(v);
|
|
359
|
+
}
|
|
360
|
+
function asInteger(v) {
|
|
361
|
+
const n = toFiniteNumber(v);
|
|
362
|
+
return n === void 0 ? void 0 : Math.trunc(n);
|
|
346
363
|
}
|
|
347
364
|
function asBoolean(v) {
|
|
348
|
-
|
|
365
|
+
if (typeof v === "boolean") return v;
|
|
366
|
+
if (typeof v === "number") return v !== 0;
|
|
367
|
+
if (typeof v === "string") {
|
|
368
|
+
const t = v.trim().toLowerCase();
|
|
369
|
+
if (t === "true" || t === "1" || t === "yes" || t === "on") return true;
|
|
370
|
+
if (t === "false" || t === "0" || t === "no" || t === "off" || t === "") return false;
|
|
371
|
+
return void 0;
|
|
372
|
+
}
|
|
373
|
+
return void 0;
|
|
349
374
|
}
|
|
350
375
|
function parseOffsetToSeconds(o) {
|
|
351
376
|
if (o === void 0 || o === null) return void 0;
|
|
@@ -442,7 +467,7 @@ var RECOGNITION_KEYS = [
|
|
|
442
467
|
function parseRecognitionResult(raw) {
|
|
443
468
|
const r = asObjectLenient(raw);
|
|
444
469
|
const timecode = asString(r.timecode);
|
|
445
|
-
const audioId =
|
|
470
|
+
const audioId = asInteger(r.audio_id);
|
|
446
471
|
const artist = asString(r.artist);
|
|
447
472
|
const title = asString(r.title);
|
|
448
473
|
const songLink = asString(r.song_link);
|
|
@@ -530,8 +555,8 @@ function parseEnterpriseMatch(raw) {
|
|
|
530
555
|
isrc: asString(r.isrc),
|
|
531
556
|
upc: asString(r.upc),
|
|
532
557
|
songLink,
|
|
533
|
-
startOffset:
|
|
534
|
-
endOffset:
|
|
558
|
+
startOffset: asInteger(r.start_offset),
|
|
559
|
+
endOffset: asInteger(r.end_offset),
|
|
535
560
|
startSeconds: void 0,
|
|
536
561
|
endSeconds: void 0,
|
|
537
562
|
extras: pickExtras(r, ENTERPRISE_MATCH_KEYS),
|
|
@@ -587,7 +612,7 @@ function parseEnterpriseChunkResult(raw) {
|
|
|
587
612
|
var STREAM_KEYS = ["radio_id", "url", "stream_running", "longpoll_category"];
|
|
588
613
|
function parseStream(raw) {
|
|
589
614
|
const r = asObjectLenient(raw);
|
|
590
|
-
const radioId =
|
|
615
|
+
const radioId = asInteger(r.radio_id);
|
|
591
616
|
const url = asString(r.url);
|
|
592
617
|
const streamRunning = asBoolean(r.stream_running);
|
|
593
618
|
return {
|
|
@@ -647,14 +672,14 @@ var STREAM_CALLBACK_MATCH_KEYS = [
|
|
|
647
672
|
];
|
|
648
673
|
function parseStreamCallbackMatch(raw) {
|
|
649
674
|
const r = asObjectLenient(raw);
|
|
650
|
-
const radioId =
|
|
675
|
+
const radioId = asInteger(r.radio_id);
|
|
651
676
|
const resultsRaw = Array.isArray(r.results) ? r.results : [];
|
|
652
677
|
const songs = resultsRaw.filter((x) => asObject(x) !== void 0).map(parseStreamCallbackSong);
|
|
653
678
|
const [first, ...rest] = songs;
|
|
654
679
|
return {
|
|
655
680
|
radioId,
|
|
656
681
|
timestamp: asString(r.timestamp),
|
|
657
|
-
playLength:
|
|
682
|
+
playLength: asInteger(r.play_length),
|
|
658
683
|
song: first,
|
|
659
684
|
alternatives: rest,
|
|
660
685
|
extras: pickExtras(r, STREAM_CALLBACK_MATCH_KEYS),
|
|
@@ -669,8 +694,8 @@ var STREAM_CALLBACK_NOTIFICATION_KEYS = [
|
|
|
669
694
|
];
|
|
670
695
|
function parseStreamCallbackNotification(raw) {
|
|
671
696
|
const r = asObjectLenient(raw);
|
|
672
|
-
const radioId =
|
|
673
|
-
const code =
|
|
697
|
+
const radioId = asInteger(r.radio_id);
|
|
698
|
+
const code = asInteger(r.notification_code);
|
|
674
699
|
const message = asString(r.notification_message);
|
|
675
700
|
return {
|
|
676
701
|
radioId,
|
|
@@ -699,9 +724,9 @@ function parseLyricsResult(raw) {
|
|
|
699
724
|
artist,
|
|
700
725
|
title,
|
|
701
726
|
lyrics: asString(r.lyrics),
|
|
702
|
-
songId:
|
|
727
|
+
songId: asInteger(r.song_id),
|
|
703
728
|
fullTitle: asString(r.full_title),
|
|
704
|
-
artistId:
|
|
729
|
+
artistId: asInteger(r.artist_id),
|
|
705
730
|
songLink: asString(r.song_link),
|
|
706
731
|
media: asString(r.media),
|
|
707
732
|
extras: pickExtras(r, LYRICS_KEYS),
|
|
@@ -1347,8 +1372,8 @@ var CustomCatalog = class {
|
|
|
1347
1372
|
onEvent;
|
|
1348
1373
|
/**
|
|
1349
1374
|
* **This is NOT how you submit audio for music recognition.** For
|
|
1350
|
-
* recognition, use `audd.recognize()` (or `audd.recognizeEnterprise()`
|
|
1351
|
-
*
|
|
1375
|
+
* recognition, use `audd.recognize()` (or `audd.recognizeEnterprise()` to scan
|
|
1376
|
+
* beyond the first 12 seconds of a file). This method adds a song to your
|
|
1352
1377
|
* **private fingerprint catalog** so AudD's recognition can later identify
|
|
1353
1378
|
* *your own* tracks for *your account only*. Requires special access —
|
|
1354
1379
|
* contact api@audd.io if you need it enabled.
|
|
@@ -1604,7 +1629,8 @@ var AudD = class {
|
|
|
1604
1629
|
return this._advanced;
|
|
1605
1630
|
}
|
|
1606
1631
|
/**
|
|
1607
|
-
* Recognize a
|
|
1632
|
+
* Recognize a song from an audio clip given as a URL, file path, Blob, or
|
|
1633
|
+
* bytes; only the first 12 seconds are analyzed.
|
|
1608
1634
|
*
|
|
1609
1635
|
* Returns `null` when the server returns `status=success` with `result=null`
|
|
1610
1636
|
* (no match) — distinct from a thrown error.
|