[GH-ISSUE #759] duration_ms and progress_ms times are off #462

Closed
opened 2026-02-27 23:22:46 +03:00 by kerem · 6 comments
Owner

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:

  • OS: Windows 10
  • Python version: 3.9.5 64-bit
  • spotipy version: 2.19.0
  • your IDE: VS Code

Additional context
N/A

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:** - OS: Windows 10 - Python version: 3.9.5 64-bit - spotipy version: 2.19.0 - your IDE: VS Code **Additional context** N/A
kerem 2026-02-27 23:22:46 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@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

<!-- gh-comment-id:1001917615 --> @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
Author
Owner

@Peter-Schorn commented on GitHub (Dec 28, 2021):

but the Spotipy API says its 1:79

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.

<!-- gh-comment-id:1002292777 --> @Peter-Schorn commented on GitHub (Dec 28, 2021): > but the Spotipy API says its 1:79 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.
Author
Owner

@Peter-Schorn commented on GitHub (Dec 28, 2021):

I noticed that the time base isn't using 0 to 59 but rather 0 to 99.

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.

107000 means 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.

<!-- gh-comment-id:1002301264 --> @Peter-Schorn commented on GitHub (Dec 28, 2021): > I noticed that the time base isn't using 0 to 59 but rather 0 to 99. 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. `107000` means 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.
Author
Owner

@Peter-Schorn commented on GitHub (Dec 29, 2021):

Here's how to properly convert a millisecond time interval to a "mm:ss" formatted string:

current_playback = spotify.current_playback()
progess_ms = current_playback["progress_ms"]

total_seconds = progess_ms // 1_000

mins, secs = divmod(total_seconds, 60)

print("{:0>2}:{:0>2}".format(mins, secs))
<!-- gh-comment-id:1002358104 --> @Peter-Schorn commented on GitHub (Dec 29, 2021): Here's how to properly convert a millisecond time interval to a "mm:ss" formatted string: ```python current_playback = spotify.current_playback() progess_ms = current_playback["progress_ms"] total_seconds = progess_ms // 1_000 mins, secs = divmod(total_seconds, 60) print("{:0>2}:{:0>2}".format(mins, secs)) ```
Author
Owner

@pnot0-alt commented on GitHub (Dec 29, 2021):

Here's how to properly convert a millisecond time interval to a "mm:ss" formatted string:

current_playback = spotify.current_playback()
progess_ms = current_playback["progress_ms"]

total_seconds = progess_ms // 1_000

mins, secs = divmod(total_seconds, 60)

print("{:0>2}:{:0>2}".format(mins, secs))

thanks, i figured that out earlier today

<!-- gh-comment-id:1002385702 --> @pnot0-alt commented on GitHub (Dec 29, 2021): > Here's how to properly convert a millisecond time interval to a "mm:ss" formatted string: > > ```python > current_playback = spotify.current_playback() > progess_ms = current_playback["progress_ms"] > > total_seconds = progess_ms // 1_000 > > mins, secs = divmod(total_seconds, 60) > > print("{:0>2}:{:0>2}".format(mins, secs)) > ``` thanks, i figured that out earlier today
Author
Owner

@dieser-niko commented on GitHub (May 23, 2024):

It seems that this issue got resolved. Closing.

<!-- gh-comment-id:2126310215 --> @dieser-niko commented on GitHub (May 23, 2024): It seems that this issue got resolved. Closing.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#462
No description provided.