Convert track duration to milliseconds in search results
Updated the duration field in TrackResult to store duration in milliseconds instead of seconds, matching Spotify's expected format. This ensures consistency when integrating with services that use millisecond-based durations.
This commit is contained in:
parent
d20609c33b
commit
8f15dc039d
1 changed files with 6 additions and 2 deletions
|
|
@ -18,7 +18,7 @@ class SearchResult:
|
|||
filename: str
|
||||
size: int
|
||||
bitrate: Optional[int]
|
||||
duration: Optional[int]
|
||||
duration: Optional[int] # Duration in milliseconds (converted from slskd's seconds)
|
||||
quality: str
|
||||
free_upload_slots: int
|
||||
upload_speed: int
|
||||
|
|
@ -429,12 +429,16 @@ class SoulseekClient:
|
|||
quality = file_ext if file_ext in ['flac', 'mp3', 'ogg', 'aac', 'wma'] else 'unknown'
|
||||
|
||||
# Create TrackResult
|
||||
# Convert duration from seconds to milliseconds (slskd returns seconds, Spotify uses ms)
|
||||
raw_duration = file_data.get('length')
|
||||
duration_ms = raw_duration * 1000 if raw_duration else None
|
||||
|
||||
track = TrackResult(
|
||||
username=username,
|
||||
filename=filename,
|
||||
size=size,
|
||||
bitrate=file_data.get('bitRate'),
|
||||
duration=file_data.get('length'),
|
||||
duration=duration_ms,
|
||||
quality=quality,
|
||||
free_upload_slots=response_data.get('freeUploadSlots', 0),
|
||||
upload_speed=response_data.get('uploadSpeed', 0),
|
||||
|
|
|
|||
Loading…
Reference in a new issue