mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-27 00:25:54 +03:00
[GH-ISSUE #759] duration_ms and progress_ms times are off #462
Labels
No labels
api-bug
bug
dependencies
documentation
duplicate
enhancement
external-ide
headless-mode
implicit-grant-flow
invalid
missing-endpoint
pr-welcome
private-api
pull-request
question
spotipy3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotipy#462
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @QuestionLife on GitHub (Dec 19, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/759
Describe the bug
When I try to get the length and progress of each song, sometimes the times are off by 10-50 seconds compared to what is displayed on Spotify. I am not sure if this is an issue on Spotify's or Spotipy's end, but it is a minor detail that is slightly annoying.
Your code
progress = (result['progress_ms'] / 1000) / 60
duration = (result['item']['duration_ms'] / 1000) / 60
print(f"Progress: {progress:.2f} / {duration:.2f}".replace(".", ":"))
Expected behavior
Currently playing: songname • artist
Progress: 0:12 / 1:21
Output
Currently playing: songname • artist
Progress: 0:20 / 1:49
Environment:
Additional context
N/A
@pnot0-alt commented on GitHub (Dec 28, 2021):
I tested the code you provided with the exact same enviroment. I noticed that the time base isn't using 0 to 59 but rather 0 to 99. E.G: The Spotify App says the song progress is 1:47 but the Spotipy API says its 1:79, Spotify App says the duration is 3:55 but the Spotipy API says its 3:93, it seems that the problem currently comes from the API itself rather than your code, we can only wait for a fix
@Peter-Schorn commented on GitHub (Dec 28, 2021):
No, the Spotify API gives you the progress in terms of milliseconds. If, during the process of converting that number to "mm:ss" format, you get "1:79", then you have done something wrong. I don't see how you can blame Spotify for this.
@Peter-Schorn commented on GitHub (Dec 28, 2021):
Whenever a time interval (such as the track progress) is stored in a single number, as opposed to a formatted string such as "1:47", the number is base-ten. I'm surprised you interpreted it any other way.
107000means 107000 milliseconds, which means 107 seconds, which means 1 minute and 47 seconds (1 * 60 + 47 = 107). You can't just divide 107 by 60 (1.78) and replace the decimal place with a colon. 1.78 means 1.78 minutes, not 1 minute and 78 seconds. There's a difference because there are 60 seconds in a minute, not 100.@Peter-Schorn commented on GitHub (Dec 29, 2021):
Here's how to properly convert a millisecond time interval to a "mm:ss" formatted string:
@pnot0-alt commented on GitHub (Dec 29, 2021):
thanks, i figured that out earlier today
@dieser-niko commented on GitHub (May 23, 2024):
It seems that this issue got resolved. Closing.