From c21f4917b86bcb5b0441a86b2dfa3f86a3723b92 Mon Sep 17 00:00:00 2001 From: Benjamin Ye Date: Sun, 21 Apr 2024 13:35:21 -0700 Subject: [PATCH] Add x-tidal-token authorization for tidal.PrivateAPI --- src/minim/tidal.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/minim/tidal.py b/src/minim/tidal.py index dfa4edf..e4dcec7 100644 --- a/src/minim/tidal.py +++ b/src/minim/tidal.py @@ -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, @@ -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,