@audd/sdk 1.5.10 → 1.5.11

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 CHANGED
@@ -145,10 +145,15 @@ for (const m of matches) {
145
145
  }
146
146
  ```
147
147
 
148
- `EnterpriseMatch` carries the same core tags plus `score`, `startOffset`,
149
- `endOffset`, `isrc`, `upc`. Access to `isrc`, `upc`, and `score` requires
150
- a Startup plan or higher — [contact us](mailto:api@audd.io) for enterprise
151
- features.
148
+ `EnterpriseMatch` carries the same core tags plus `score`, `startSeconds`,
149
+ `endSeconds`, `startOffset`, `endOffset`, `isrc`, `upc`. `startSeconds` and
150
+ `endSeconds` are where this song plays in your file, in seconds (e.g. 64.2 to
151
+ 71.8) — feed straight to a player or ffmpeg; computed while parsing the chunked
152
+ response, and `recognizeEnterprise` requests accurate offsets by default so
153
+ they're precise. `startOffset`/`endOffset` are the raw millisecond positions
154
+ within AudD's internal 12-second scan fragment behind them. Access to `isrc`,
155
+ `upc`, and `score` requires a Startup plan or higher — [contact
156
+ us](mailto:api@audd.io) for enterprise features.
152
157
 
153
158
  The default per-call timeout is **1 hour** for this endpoint (60s for
154
159
  standard recognition); override with `timeoutMs`.
package/dist/index.cjs CHANGED
@@ -285,6 +285,20 @@ function asNumber(v) {
285
285
  function asBoolean(v) {
286
286
  return typeof v === "boolean" ? v : void 0;
287
287
  }
288
+ function parseOffsetToSeconds(o) {
289
+ if (o === void 0 || o === null) return void 0;
290
+ if (typeof o === "number") return Number.isFinite(o) ? o : void 0;
291
+ const t = String(o).trim();
292
+ if (t === "") return void 0;
293
+ let total = 0;
294
+ for (const part of t.split(":")) {
295
+ if (part.trim() === "") return void 0;
296
+ const n = Number(part);
297
+ if (!Number.isFinite(n)) return void 0;
298
+ total = total * 60 + n;
299
+ }
300
+ return total;
301
+ }
288
302
  var STREAMING_PROVIDERS = [
289
303
  "spotify",
290
304
  "apple_music",
@@ -434,7 +448,9 @@ var ENTERPRISE_MATCH_KEYS = [
434
448
  "upc",
435
449
  "song_link",
436
450
  "start_offset",
437
- "end_offset"
451
+ "end_offset",
452
+ "start_seconds",
453
+ "end_seconds"
438
454
  ];
439
455
  function parseEnterpriseMatch(raw) {
440
456
  const r = requireObject(raw, "EnterpriseMatch");
@@ -454,6 +470,8 @@ function parseEnterpriseMatch(raw) {
454
470
  songLink,
455
471
  startOffset: asNumber(r.start_offset),
456
472
  endOffset: asNumber(r.end_offset),
473
+ startSeconds: void 0,
474
+ endSeconds: void 0,
457
475
  extras: pickExtras(r, ENTERPRISE_MATCH_KEYS),
458
476
  rawResponse: r,
459
477
  streamingUrl(provider) {
@@ -488,8 +506,17 @@ function parseEnterpriseChunkResult(raw) {
488
506
  const r = requireObject(raw, "EnterpriseChunkResult");
489
507
  const songsRaw = Array.isArray(r.songs) ? r.songs : [];
490
508
  const offset = asString(r.offset);
509
+ const base = parseOffsetToSeconds(r.offset);
510
+ const songs = songsRaw.map((s) => {
511
+ const match = parseEnterpriseMatch(s);
512
+ if (base !== void 0) {
513
+ match.startSeconds = base + (match.startOffset ?? 0) / 1e3;
514
+ match.endSeconds = base + (match.endOffset ?? 0) / 1e3;
515
+ }
516
+ return match;
517
+ });
491
518
  return {
492
- songs: songsRaw.map(parseEnterpriseMatch),
519
+ songs,
493
520
  offset,
494
521
  extras: pickExtras(r, ENTERPRISE_CHUNK_KEYS),
495
522
  rawResponse: r
@@ -1376,8 +1403,8 @@ function buildEnterpriseFields(opts) {
1376
1403
  if (opts.skipFirstSeconds !== void 0)
1377
1404
  fields["skip_first_seconds"] = String(opts.skipFirstSeconds);
1378
1405
  if (opts.useTimecode !== void 0) fields["use_timecode"] = opts.useTimecode ? "true" : "false";
1379
- if (opts.accurateOffsets !== void 0)
1380
- fields["accurate_offsets"] = opts.accurateOffsets ? "true" : "false";
1406
+ const accurate = opts.accurateOffsets ?? true;
1407
+ fields["accurate_offsets"] = accurate ? "true" : "false";
1381
1408
  return fields;
1382
1409
  }
1383
1410
  function isDeprecationPassThrough(body) {