Skip to content

Commit

Permalink
Add x-tidal-token authorization for tidal.PrivateAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
bbye98 committed Apr 21, 2024
1 parent 9e78059 commit c21f491
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/minim/tidal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2532,17 +2532,21 @@ def set_access_token(
with open(DIR_HOME / "minim.cfg", "w") as f:
_config.write(f)

self.session.headers["Authorization"] = f"Bearer {access_token}"
self._refresh_token = refresh_token
self._expiry = (
datetime.datetime.strptime(expiry, "%Y-%m-%dT%H:%M:%SZ")
if isinstance(expiry, str) else expiry
)
if len(access_token) == 16:
self.session.headers["x-tidal-token"] = access_token
self._refresh_token = self._expiry = None
else:
self.session.headers["Authorization"] = f"Bearer {access_token}"
self._refresh_token = refresh_token
self._expiry = (
datetime.datetime.strptime(expiry, "%Y-%m-%dT%H:%M:%SZ")
if isinstance(expiry, str) else expiry
)

if self._flow is not None:
me = self.get_profile()
self._country_code = me["countryCode"]
self._user_id = me["userId"]
if self._flow is not None:
me = self.get_profile()
self._country_code = me["countryCode"]
self._user_id = me["userId"]

def set_flow(
self, flow: str, client_id: str, *, client_secret: str = None,
Expand Down Expand Up @@ -7413,6 +7417,8 @@ def get_track_playback_info(
raise ValueError(emsg)

url = f"{self.API_URL}/v1/tracks/{track_id}/playbackinfo"
# if self._flow:
# url += "postpaywall"
url += "postpaywall" if self._flow else "prepaywall"
return self._get_json(
url,
Expand Down

0 comments on commit c21f491

Please sign in to comment.