Skip to content

Commit 6728663

Browse files
committed
Requests: Cleanup comments. Move request variables to their appropriate location. Hardcode locale.
1 parent 3222541 commit 6728663

2 files changed

Lines changed: 18 additions & 22 deletions

File tree

tidalapi/request.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Requests(object):
5757
def __init__(self, session: "Session"):
5858
# More Android User-Agents here: https://user-agents.net/browsers/android
5959
self.user_agent = "Mozilla/5.0 (Linux; Android 12; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/91.0.4472.114 Safari/537.36"
60+
self.client_version = "2025.7.16"
6061
self.session = session
6162
self.config = session.config
6263
self.latest_err_response = requests.Response()
@@ -85,7 +86,8 @@ def basic_request(
8586
if not headers:
8687
headers = {}
8788

88-
headers["x-tidal-client-version"] = "2025.7.16"
89+
if "x-tidal-client-version" not in headers:
90+
headers["x-tidal-client-version"] = self.client_version
8991

9092
if "User-Agent" not in headers:
9193
headers["User-Agent"] = self.user_agent
@@ -172,18 +174,22 @@ def request(
172174
return request
173175

174176
def get_latest_err_response(self) -> dict:
175-
"""Get the latest request Response that resulted in an Exception :return: The
176-
request Response that resulted in the Exception, returned as a dict An empty
177-
dict will be returned, if no response was returned."""
177+
"""Get the latest request Response that resulted in an Exception.
178+
179+
:return: The request Response that resulted in the Exception, returned as a dict
180+
An empty dict will be returned, if no response was returned.
181+
"""
178182
if self.latest_err_response.content:
179183
return self.latest_err_response.json()
180184
else:
181185
return {}
182186

183187
def get_latest_err_response_str(self) -> str:
184-
"""Get the latest request response message as a string :return: The contents of
185-
the (detailed) error response Response, returned as a string An empty str will
186-
be returned, if no response was returned."""
188+
"""Get the latest request response message as a string.
189+
190+
:return: The contents of the (detailed) error response, returned as a string An
191+
empty str will be returned, if no response was returned.
192+
"""
187193
if self.latest_err_response.content:
188194
resp = self.latest_err_response.json()
189195
return resp["errors"][0]["detail"]

tidalapi/session.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,10 @@ class Session:
268268
refresh_token: Optional[str] = None
269269
#: The type of access token, e.g. Bearer
270270
token_type: Optional[str] = None
271-
#: The id for a TIDAL session, you also need this to use load_oauth_session
271+
#: The session id for a TIDAL session, you also need this to use load_oauth_session
272272
session_id: Optional[str] = None
273273
country_code: Optional[str] = None
274+
locale: Optional[str] = None
274275
#: A :class:`.User` object containing the currently logged in user.
275276
user: Optional[Union["FetchedUser", "LoggedInUser", "PlaylistCreator"]] = None
276277

@@ -282,15 +283,6 @@ def __init__(self, config: Config = Config()):
282283
self.request = request.Requests(session=self)
283284
self.genre = genre.Genre(session=self)
284285

285-
# self.parse_artists = self.artist().parse_artists
286-
# self.parse_playlist = self.playlist().parse
287-
288-
# self.parse_track = self.track().parse_track
289-
# self.parse_video = self.video().parse_video
290-
# self.parse_media = self.track().parse_media
291-
# self.parse_mix = self.mix().parse
292-
# self.parse_v2_mix = self.mixv2().parse
293-
294286
self.parse_user = user.User(self, None).parse
295287
self.page = page.Page(self, "")
296288
self.parse_page = self.page.parse
@@ -453,6 +445,7 @@ def load_oauth_session(
453445

454446
self.session_id = json["sessionId"]
455447
self.country_code = json["countryCode"]
448+
self.locale = "en_US" # TODO Get locale from system configuration
456449
self.user = user.User(self, user_id=json["userId"]).factory()
457450

458451
return True
@@ -719,6 +712,7 @@ def process_auth_token(
719712
json = session.json()
720713
self.session_id = json["sessionId"]
721714
self.country_code = json["countryCode"]
715+
self.locale = "en_US" # TODO Set locale from system configuration
722716
self.user = user.User(self, user_id=json["userId"]).factory()
723717
self.is_pkce = is_pkce_token
724718

@@ -1094,11 +1088,7 @@ def home(self) -> page.Page:
10941088
10951089
:return: A :class:`.Page` object with the :class:`.PageCategory` list from the home page
10961090
"""
1097-
params = {}
1098-
params["deviceType"] = "BROWSER"
1099-
params["countryCode"] = "IT"
1100-
params["locale"] = "en_US"
1101-
params["platform"] = "WEB"
1091+
params = {"deviceType": "BROWSER", "locale": self.locale, "platform": "WEB"}
11021092

11031093
json_obj = self.request.request(
11041094
"GET",

0 commit comments

Comments
 (0)