|
25 | 25 | AudDServerError, |
26 | 26 | raise_from_error_response, |
27 | 27 | ) |
28 | | -from audd.models import EnterpriseChunkResult, EnterpriseMatch, RecognitionResult |
| 28 | +from audd.models import ( |
| 29 | + EnterpriseChunkResult, |
| 30 | + EnterpriseMatch, |
| 31 | + RecognitionResult, |
| 32 | + _offset_to_seconds, |
| 33 | +) |
29 | 34 |
|
30 | 35 | API_BASE = "https://api.audd.io" |
31 | 36 | ENTERPRISE_BASE = "https://enterprise.audd.io" |
@@ -208,6 +213,14 @@ def _decode_enterprise(resp: HTTPResponse) -> list[EnterpriseMatch]: |
208 | 213 | chunk = EnterpriseChunkResult.model_validate(chunk_dict) |
209 | 214 | except Exception: # degrade, never raise on response parse |
210 | 215 | continue |
| 216 | + # The file position lives on the chunk; the API drops it once we flatten |
| 217 | + # to a song list. Resolve each match's absolute position in the file |
| 218 | + # here (chunk offset + in-fragment offset) so callers don't lose it. |
| 219 | + base = _offset_to_seconds(chunk.offset) |
| 220 | + if base is not None: |
| 221 | + for song in chunk.songs: |
| 222 | + song.start_seconds = base + (song.start_offset or 0) / 1000 |
| 223 | + song.end_seconds = base + (song.end_offset or 0) / 1000 |
211 | 224 | out.extend(chunk.songs) |
212 | 225 | return out |
213 | 226 |
|
@@ -411,7 +424,7 @@ def recognize_enterprise( |
411 | 424 | limit: int | None = None, |
412 | 425 | skip_first_seconds: int | None = None, |
413 | 426 | use_timecode: bool | None = None, |
414 | | - accurate_offsets: bool | None = None, |
| 427 | + accurate_offsets: bool = True, |
415 | 428 | timeout: float | None = None, |
416 | 429 | extra_parameters: dict[str, str] | None = None, |
417 | 430 | ) -> list[EnterpriseMatch]: |
@@ -603,7 +616,7 @@ async def recognize_enterprise( |
603 | 616 | limit: int | None = None, |
604 | 617 | skip_first_seconds: int | None = None, |
605 | 618 | use_timecode: bool | None = None, |
606 | | - accurate_offsets: bool | None = None, |
| 619 | + accurate_offsets: bool = True, |
607 | 620 | timeout: float | None = None, |
608 | 621 | extra_parameters: dict[str, str] | None = None, |
609 | 622 | ) -> list[EnterpriseMatch]: |
|
0 commit comments