@audd/sdk 1.5.9 → 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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
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
- export { d as EnterpriseChunkResult, e as StreamCallbackSong, f as StreamingProvider } from './longpollCore-DMBdcGSM.cjs';
1
+ import { c as StreamCallbackMatch, d as StreamCallbackNotification, H as HttpClient, S as Stream, L as LongpollPoll, b as LyricsResult, F as FetchLike, R as RecognitionResult, a as EnterpriseMatch } from './longpollCore-ZtFOyojP.cjs';
2
+ export { E as EnterpriseChunkResult, e as StreamCallbackSong, f as StreamingProvider } from './longpollCore-ZtFOyojP.cjs';
3
3
 
4
4
  declare const VERSION = "1.5.8";
5
5
 
@@ -431,6 +431,7 @@ interface RecognizeEnterpriseOptions {
431
431
  limit?: number;
432
432
  skipFirstSeconds?: number;
433
433
  useTimecode?: boolean;
434
+ /** Request precise within-fragment offsets. Defaults to `true`; pass `false` to opt out. */
434
435
  accurateOffsets?: boolean;
435
436
  timeoutMs?: number;
436
437
  /**
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
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
- export { d as EnterpriseChunkResult, e as StreamCallbackSong, f as StreamingProvider } from './longpollCore-DMBdcGSM.js';
1
+ import { c as StreamCallbackMatch, d as StreamCallbackNotification, H as HttpClient, S as Stream, L as LongpollPoll, b as LyricsResult, F as FetchLike, R as RecognitionResult, a as EnterpriseMatch } from './longpollCore-ZtFOyojP.js';
2
+ export { E as EnterpriseChunkResult, e as StreamCallbackSong, f as StreamingProvider } from './longpollCore-ZtFOyojP.js';
3
3
 
4
4
  declare const VERSION = "1.5.8";
5
5
 
@@ -431,6 +431,7 @@ interface RecognizeEnterpriseOptions {
431
431
  limit?: number;
432
432
  skipFirstSeconds?: number;
433
433
  useTimecode?: boolean;
434
+ /** Request precise within-fragment offsets. Defaults to `true`; pass `false` to opt out. */
434
435
  accurateOffsets?: boolean;
435
436
  timeoutMs?: number;
436
437
  /**
package/dist/index.js CHANGED
@@ -263,6 +263,20 @@ function asNumber(v) {
263
263
  function asBoolean(v) {
264
264
  return typeof v === "boolean" ? v : void 0;
265
265
  }
266
+ function parseOffsetToSeconds(o) {
267
+ if (o === void 0 || o === null) return void 0;
268
+ if (typeof o === "number") return Number.isFinite(o) ? o : void 0;
269
+ const t = String(o).trim();
270
+ if (t === "") return void 0;
271
+ let total = 0;
272
+ for (const part of t.split(":")) {
273
+ if (part.trim() === "") return void 0;
274
+ const n = Number(part);
275
+ if (!Number.isFinite(n)) return void 0;
276
+ total = total * 60 + n;
277
+ }
278
+ return total;
279
+ }
266
280
  var STREAMING_PROVIDERS = [
267
281
  "spotify",
268
282
  "apple_music",
@@ -344,9 +358,6 @@ var RECOGNITION_KEYS = [
344
358
  function parseRecognitionResult(raw) {
345
359
  const r = requireObject(raw, "RecognitionResult");
346
360
  const timecode = asString(r.timecode);
347
- if (timecode === void 0) {
348
- throw new TypeError("RecognitionResult: timecode missing or not string");
349
- }
350
361
  const audioId = asNumber(r.audio_id);
351
362
  const artist = asString(r.artist);
352
363
  const title = asString(r.title);
@@ -415,14 +426,14 @@ var ENTERPRISE_MATCH_KEYS = [
415
426
  "upc",
416
427
  "song_link",
417
428
  "start_offset",
418
- "end_offset"
429
+ "end_offset",
430
+ "start_seconds",
431
+ "end_seconds"
419
432
  ];
420
433
  function parseEnterpriseMatch(raw) {
421
434
  const r = requireObject(raw, "EnterpriseMatch");
422
435
  const score = asNumber(r.score);
423
436
  const timecode = asString(r.timecode);
424
- if (score === void 0) throw new TypeError("EnterpriseMatch: score not number");
425
- if (timecode === void 0) throw new TypeError("EnterpriseMatch: timecode not string");
426
437
  const songLink = asString(r.song_link);
427
438
  return {
428
439
  score,
@@ -437,6 +448,8 @@ function parseEnterpriseMatch(raw) {
437
448
  songLink,
438
449
  startOffset: asNumber(r.start_offset),
439
450
  endOffset: asNumber(r.end_offset),
451
+ startSeconds: void 0,
452
+ endSeconds: void 0,
440
453
  extras: pickExtras(r, ENTERPRISE_MATCH_KEYS),
441
454
  rawResponse: r,
442
455
  streamingUrl(provider) {
@@ -469,14 +482,19 @@ function parseEnterpriseMatch(raw) {
469
482
  var ENTERPRISE_CHUNK_KEYS = ["songs", "offset"];
470
483
  function parseEnterpriseChunkResult(raw) {
471
484
  const r = requireObject(raw, "EnterpriseChunkResult");
472
- const songsRaw = r.songs;
473
- if (!Array.isArray(songsRaw)) {
474
- throw new TypeError("EnterpriseChunkResult: songs not array");
475
- }
485
+ const songsRaw = Array.isArray(r.songs) ? r.songs : [];
476
486
  const offset = asString(r.offset);
477
- if (offset === void 0) throw new TypeError("EnterpriseChunkResult: offset not string");
487
+ const base = parseOffsetToSeconds(r.offset);
488
+ const songs = songsRaw.map((s) => {
489
+ const match = parseEnterpriseMatch(s);
490
+ if (base !== void 0) {
491
+ match.startSeconds = base + (match.startOffset ?? 0) / 1e3;
492
+ match.endSeconds = base + (match.endOffset ?? 0) / 1e3;
493
+ }
494
+ return match;
495
+ });
478
496
  return {
479
- songs: songsRaw.map(parseEnterpriseMatch),
497
+ songs,
480
498
  offset,
481
499
  extras: pickExtras(r, ENTERPRISE_CHUNK_KEYS),
482
500
  rawResponse: r
@@ -488,9 +506,6 @@ function parseStream(raw) {
488
506
  const radioId = asNumber(r.radio_id);
489
507
  const url = asString(r.url);
490
508
  const streamRunning = asBoolean(r.stream_running);
491
- if (radioId === void 0) throw new TypeError("Stream: radio_id not number");
492
- if (url === void 0) throw new TypeError("Stream: url not string");
493
- if (streamRunning === void 0) throw new TypeError("Stream: stream_running not boolean");
494
509
  return {
495
510
  radioId,
496
511
  url,
@@ -521,9 +536,6 @@ function parseStreamCallbackSong(raw) {
521
536
  const artist = asString(r.artist);
522
537
  const title = asString(r.title);
523
538
  const score = asNumber(r.score);
524
- if (artist === void 0) throw new TypeError("StreamCallbackSong: artist not string");
525
- if (title === void 0) throw new TypeError("StreamCallbackSong: title not string");
526
- if (score === void 0) throw new TypeError("StreamCallbackSong: score not number");
527
539
  const musicbrainz = Array.isArray(r.musicbrainz) ? r.musicbrainz.filter((x) => asObject(x) !== void 0) : void 0;
528
540
  return {
529
541
  artist,
@@ -552,13 +564,9 @@ var STREAM_CALLBACK_MATCH_KEYS = [
552
564
  function parseStreamCallbackMatch(raw) {
553
565
  const r = requireObject(raw, "StreamCallbackMatch");
554
566
  const radioId = asNumber(r.radio_id);
555
- if (radioId === void 0) throw new TypeError("StreamCallbackMatch: radio_id not number");
556
- const resultsRaw = r.results;
557
- if (!Array.isArray(resultsRaw)) throw new TypeError("StreamCallbackMatch: results not array");
558
- if (resultsRaw.length === 0) throw new TypeError("StreamCallbackMatch: results is empty");
559
- const songs = resultsRaw.map(parseStreamCallbackSong);
567
+ const resultsRaw = Array.isArray(r.results) ? r.results : [];
568
+ const songs = resultsRaw.filter((x) => asObject(x) !== void 0).map(parseStreamCallbackSong);
560
569
  const [first, ...rest] = songs;
561
- if (first === void 0) throw new TypeError("StreamCallbackMatch: results is empty");
562
570
  return {
563
571
  radioId,
564
572
  timestamp: asString(r.timestamp),
@@ -578,14 +586,8 @@ var STREAM_CALLBACK_NOTIFICATION_KEYS = [
578
586
  function parseStreamCallbackNotification(raw) {
579
587
  const r = requireObject(raw, "StreamCallbackNotification");
580
588
  const radioId = asNumber(r.radio_id);
581
- if (radioId === void 0)
582
- throw new TypeError("StreamCallbackNotification: radio_id not number");
583
589
  const code = asNumber(r.notification_code);
584
- if (code === void 0)
585
- throw new TypeError("StreamCallbackNotification: notification_code not number");
586
590
  const message = asString(r.notification_message);
587
- if (message === void 0)
588
- throw new TypeError("StreamCallbackNotification: notification_message not string");
589
591
  return {
590
592
  radioId,
591
593
  streamRunning: asBoolean(r.stream_running),
@@ -609,8 +611,6 @@ function parseLyricsResult(raw) {
609
611
  const r = requireObject(raw, "LyricsResult");
610
612
  const artist = asString(r.artist);
611
613
  const title = asString(r.title);
612
- if (artist === void 0) throw new TypeError("LyricsResult: artist not string");
613
- if (title === void 0) throw new TypeError("LyricsResult: title not string");
614
614
  return {
615
615
  artist,
616
616
  title,
@@ -1381,8 +1381,8 @@ function buildEnterpriseFields(opts) {
1381
1381
  if (opts.skipFirstSeconds !== void 0)
1382
1382
  fields["skip_first_seconds"] = String(opts.skipFirstSeconds);
1383
1383
  if (opts.useTimecode !== void 0) fields["use_timecode"] = opts.useTimecode ? "true" : "false";
1384
- if (opts.accurateOffsets !== void 0)
1385
- fields["accurate_offsets"] = opts.accurateOffsets ? "true" : "false";
1384
+ const accurate = opts.accurateOffsets ?? true;
1385
+ fields["accurate_offsets"] = accurate ? "true" : "false";
1386
1386
  return fields;
1387
1387
  }
1388
1388
  function isDeprecationPassThrough(body) {