Skip to content

Commit 7aa377d

Browse files
authored
Merge pull request #314 from root4loot/fix/rust-credentials-compat
Support Rust librespot credential format in stored_file()
2 parents 1ad1e40 + 87171a3 commit 7aa377d

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ session = Session.Builder() \
9191
.create()
9292
```
9393

94+
### Use Stored Credentials for Login
95+
96+
```python
97+
from librespot.core import Session
98+
99+
# Supports both Python and Rust librespot credential formats
100+
101+
session = Session.Builder() \
102+
.stored_file("/path/to/credentials.json") \
103+
.create()
104+
```
105+
94106
### Get Spotify's OAuth token
95107

96108
```python

librespot/core.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1618,14 +1618,23 @@ def stored_file(self,
16181618
pass
16191619
else:
16201620
try:
1621+
# Try Python librespot format first
16211622
self.login_credentials = Authentication.LoginCredentials(
16221623
typ=Authentication.AuthenticationType.Value(
16231624
obj["type"]),
16241625
username=obj["username"],
16251626
auth_data=base64.b64decode(obj["credentials"]),
16261627
)
16271628
except KeyError:
1628-
pass
1629+
# Try Rust librespot format (auth_type as int, auth_data instead of credentials)
1630+
try:
1631+
self.login_credentials = Authentication.LoginCredentials(
1632+
typ=obj["auth_type"],
1633+
username=obj["username"],
1634+
auth_data=base64.b64decode(obj["auth_data"]),
1635+
)
1636+
except KeyError:
1637+
pass
16291638
return self
16301639

16311640
def oauth(self, oauth_url_callback) -> Session.Builder:

0 commit comments

Comments
 (0)