kokarare1212 / librespot-python

Open Source Spotify Client
http://librespot-python.rtfd.io
Apache License 2.0
235 stars 45 forks source link

[BUG] Tokens expiring too fast #267

Closed geogamba closed 5 months ago

geogamba commented 6 months ago

Describe the bug The token expiration conversion of seconds to microseconds is incorrect. I've been having problems with tokens expiring too fast, and narrowed it down to this problem.

Currently on core.py line 2281

def expired(self) -> bool:
            """ """
            return self.timestamp + (self.expires_in - TokenProvider.
                                     token_expire_threshold) * 1000 < int(
                                         time.time_ns() / 1000)

it should be

def expired(self) -> bool:
            """ """
            return self.timestamp + (self.expires_in - TokenProvider.
                                     token_expire_threshold) * 1000000 < int(
                                         time.time_ns() / 1000)

This should convert seconds to microseconds to match the self.timestamp and the time.time_ns() / 1000 (nanosecond converted to microseconds)

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Client Information (please complete the following information):

Additional context Add any other context about the problem here.