@audd/sdk 1.5.7 → 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 +65 -2
- package/dist/index.cjs +11 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -3
- package/dist/index.d.ts +23 -3
- package/dist/index.js +11 -9
- package/dist/index.js.map +1 -1
- package/dist/longpoll.cjs +1 -1
- package/dist/longpoll.cjs.map +1 -1
- package/dist/longpoll.js +1 -1
- package/dist/longpoll.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -96,14 +96,14 @@ only what you need — each provider you ask for adds latency:
|
|
|
96
96
|
|
|
97
97
|
```ts
|
|
98
98
|
const song = await audd.recognize("https://audd.tech/example.mp3", {
|
|
99
|
-
|
|
99
|
+
returnMetadata: ["apple_music", "spotify"],
|
|
100
100
|
});
|
|
101
101
|
console.log(song?.appleMusic?.url); // direct Apple Music link
|
|
102
102
|
console.log(song?.spotify?.uri); // spotify:track:...
|
|
103
103
|
console.log(song?.previewUrl()); // first preview across requested providers, or null
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
-
Valid `
|
|
106
|
+
Valid `returnMetadata` values: `apple_music`, `spotify`, `deezer`, `napster`,
|
|
107
107
|
`musicbrainz`. Blocks are `undefined` when not requested.
|
|
108
108
|
|
|
109
109
|
`streamingUrl(provider)` prefers the direct provider URL when you
|
|
@@ -121,6 +121,17 @@ console.log(song.extras); // any non-typed top-level fields
|
|
|
121
121
|
console.log(song.rawResponse); // the whole result object as the server returned it
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
+
For the **request** side, every call accepts an `extraParameters` map for additional form fields the typed options don't cover — undocumented parameters or beta features:
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
await audd.recognize(url, {
|
|
128
|
+
returnMetadata: "apple_music",
|
|
129
|
+
extraParameters: { some_beta_flag: "true" },
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The same `extraParameters` field is on `RecognizeEnterpriseOptions`, `SetCallbackUrlOptions`, and `AddStreamOptions`. Typed options win on collision.
|
|
134
|
+
|
|
124
135
|
## Long files (enterprise)
|
|
125
136
|
|
|
126
137
|
`recognizeEnterprise` accepts files up to several hours and returns a
|
|
@@ -273,6 +284,58 @@ If you already have the body bytes (queue consumer, replay tool), call
|
|
|
273
284
|
`parseCallback(body)` directly — it accepts a parsed JSON object or a
|
|
274
285
|
JSON string and returns the same `{ match, notification }` shape.
|
|
275
286
|
|
|
287
|
+
#### Per-framework wiring
|
|
288
|
+
|
|
289
|
+
The same `handleCallback(req)` works across Node web frameworks — register
|
|
290
|
+
a POST route and pass the request object in.
|
|
291
|
+
|
|
292
|
+
`Fastify`:
|
|
293
|
+
|
|
294
|
+
```ts
|
|
295
|
+
import Fastify from "fastify";
|
|
296
|
+
import { handleCallback } from "@audd/sdk";
|
|
297
|
+
|
|
298
|
+
const app = Fastify();
|
|
299
|
+
app.post("/audd-callback", async (req, reply) => {
|
|
300
|
+
const { match } = await handleCallback(req);
|
|
301
|
+
if (match) console.log(`${match.song.artist} — ${match.song.title}`);
|
|
302
|
+
return { ok: true };
|
|
303
|
+
});
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
`Koa`:
|
|
307
|
+
|
|
308
|
+
```ts
|
|
309
|
+
import Koa from "koa";
|
|
310
|
+
import Router from "@koa/router";
|
|
311
|
+
import bodyParser from "koa-bodyparser";
|
|
312
|
+
import { handleCallback } from "@audd/sdk";
|
|
313
|
+
|
|
314
|
+
const app = new Koa();
|
|
315
|
+
const router = new Router();
|
|
316
|
+
|
|
317
|
+
app.use(bodyParser());
|
|
318
|
+
router.post("/audd-callback", async (ctx) => {
|
|
319
|
+
const { match } = await handleCallback(ctx.request);
|
|
320
|
+
if (match) console.log(`${match.song.artist} — ${match.song.title}`);
|
|
321
|
+
ctx.body = { ok: true };
|
|
322
|
+
});
|
|
323
|
+
app.use(router.routes());
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
`Next.js` (App Router, `app/api/audd-callback/route.ts`):
|
|
327
|
+
|
|
328
|
+
```ts
|
|
329
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
330
|
+
import { handleCallback } from "@audd/sdk";
|
|
331
|
+
|
|
332
|
+
export async function POST(req: NextRequest) {
|
|
333
|
+
const { match } = await handleCallback(req);
|
|
334
|
+
if (match) console.log(`${match.song.artist} — ${match.song.title}`);
|
|
335
|
+
return NextResponse.json({ ok: true });
|
|
336
|
+
}
|
|
337
|
+
```
|
|
338
|
+
|
|
276
339
|
### Receiving events without a callback URL (longpoll)
|
|
277
340
|
|
|
278
341
|
Useful when you can't expose a public HTTPS receiver. The poll handle
|
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.
|
|
28
|
+
var VERSION = "1.5.8";
|
|
29
29
|
|
|
30
30
|
// src/errors.ts
|
|
31
31
|
var AudDError = class extends Error {
|
|
@@ -1127,7 +1127,9 @@ var Streams = class {
|
|
|
1127
1127
|
*/
|
|
1128
1128
|
async setCallbackUrl(url, opts = {}) {
|
|
1129
1129
|
const finalUrl = addReturnToUrl(url, opts.returnMetadata);
|
|
1130
|
-
|
|
1130
|
+
const fields = opts.extraParameters ? { ...opts.extraParameters } : {};
|
|
1131
|
+
fields["url"] = finalUrl;
|
|
1132
|
+
await this.post("setCallbackUrl", fields, this.mutatingPolicy);
|
|
1131
1133
|
}
|
|
1132
1134
|
/** Get the currently registered callback URL. */
|
|
1133
1135
|
async getCallbackUrl() {
|
|
@@ -1136,10 +1138,9 @@ var Streams = class {
|
|
|
1136
1138
|
}
|
|
1137
1139
|
/** Register a new stream for real-time recognition. */
|
|
1138
1140
|
async add(opts) {
|
|
1139
|
-
const fields = {
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
};
|
|
1141
|
+
const fields = opts.extraParameters ? { ...opts.extraParameters } : {};
|
|
1142
|
+
fields["url"] = opts.url;
|
|
1143
|
+
fields["radio_id"] = String(opts.radioId);
|
|
1143
1144
|
if (opts.callbacks !== void 0) fields["callbacks"] = opts.callbacks;
|
|
1144
1145
|
await this.post("addStream", fields, this.mutatingPolicy);
|
|
1145
1146
|
}
|
|
@@ -1393,8 +1394,8 @@ function formatReturn(value) {
|
|
|
1393
1394
|
return Array.isArray(value) ? value.join(",") : value;
|
|
1394
1395
|
}
|
|
1395
1396
|
function buildEnterpriseFields(opts) {
|
|
1396
|
-
const fields = {};
|
|
1397
|
-
const ret = formatReturn(opts.
|
|
1397
|
+
const fields = opts.extraParameters ? { ...opts.extraParameters } : {};
|
|
1398
|
+
const ret = formatReturn(opts.returnMetadata);
|
|
1398
1399
|
if (ret !== void 0) fields["return"] = ret;
|
|
1399
1400
|
if (opts.skip !== void 0) fields["skip"] = String(opts.skip);
|
|
1400
1401
|
if (opts.every !== void 0) fields["every"] = String(opts.every);
|
|
@@ -1563,7 +1564,7 @@ var AudD = class {
|
|
|
1563
1564
|
*/
|
|
1564
1565
|
async recognize(source, opts = {}) {
|
|
1565
1566
|
const reopen = prepareSource(source);
|
|
1566
|
-
const ret = formatReturn(opts.
|
|
1567
|
+
const ret = formatReturn(opts.returnMetadata);
|
|
1567
1568
|
const market = opts.market;
|
|
1568
1569
|
const policy = this.policyFor("recognition");
|
|
1569
1570
|
const url = `${API_BASE3}/`;
|
|
@@ -1583,6 +1584,7 @@ var AudD = class {
|
|
|
1583
1584
|
resp = await runRetried4(async () => {
|
|
1584
1585
|
const prepared = await reopen();
|
|
1585
1586
|
const fields = { ...prepared.fields };
|
|
1587
|
+
if (opts.extraParameters) Object.assign(fields, opts.extraParameters);
|
|
1586
1588
|
if (ret !== void 0) fields["return"] = ret;
|
|
1587
1589
|
if (market !== void 0) fields["market"] = market;
|
|
1588
1590
|
return this._http.postForm(url, fields, {
|