Merge pull request #314 from root4loot/fix/rust-credentials-compat
Support Rust librespot credential format in stored_file()
This commit is contained in:
12
README.md
12
README.md
@@ -91,6 +91,18 @@ session = Session.Builder() \
|
|||||||
.create()
|
.create()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Use Stored Credentials for Login
|
||||||
|
|
||||||
|
```python
|
||||||
|
from librespot.core import Session
|
||||||
|
|
||||||
|
# Supports both Python and Rust librespot credential formats
|
||||||
|
|
||||||
|
session = Session.Builder() \
|
||||||
|
.stored_file("/path/to/credentials.json") \
|
||||||
|
.create()
|
||||||
|
```
|
||||||
|
|
||||||
### Get Spotify's OAuth token
|
### Get Spotify's OAuth token
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
|||||||
@@ -1618,12 +1618,21 @@ class Session(Closeable, MessageListener, SubListener):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
# Try Python librespot format first
|
||||||
self.login_credentials = Authentication.LoginCredentials(
|
self.login_credentials = Authentication.LoginCredentials(
|
||||||
typ=Authentication.AuthenticationType.Value(
|
typ=Authentication.AuthenticationType.Value(
|
||||||
obj["type"]),
|
obj["type"]),
|
||||||
username=obj["username"],
|
username=obj["username"],
|
||||||
auth_data=base64.b64decode(obj["credentials"]),
|
auth_data=base64.b64decode(obj["credentials"]),
|
||||||
)
|
)
|
||||||
|
except KeyError:
|
||||||
|
# Try Rust librespot format (auth_type as int, auth_data instead of credentials)
|
||||||
|
try:
|
||||||
|
self.login_credentials = Authentication.LoginCredentials(
|
||||||
|
typ=obj["auth_type"],
|
||||||
|
username=obj["username"],
|
||||||
|
auth_data=base64.b64decode(obj["auth_data"]),
|
||||||
|
)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
return self
|
return self
|
||||||
|
|||||||
Reference in New Issue
Block a user