From 8caa90b15fe1105e8e7f71cc48718fda78719059 Mon Sep 17 00:00:00 2001 From: Jozef Kruszynski Date: Mon, 27 Nov 2023 19:10:18 +0100 Subject: [PATCH] Remove all the nonsense and simplify --- tidalapi/request.py | 11 +++-------- tidalapi/session.py | 4 ---- tidalapi/user.py | 4 ++-- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/tidalapi/request.py b/tidalapi/request.py index 6eb990f..0037f79 100644 --- a/tidalapi/request.py +++ b/tidalapi/request.py @@ -55,11 +55,9 @@ def __init__(self, session: "Session"): self.config = session.config def basic_request( - self, method: Methods, path: str, - api_version: str = "v1/", params: Optional[Params] = None, data: Optional[JsonObj] = None, headers: Optional[MutableMapping[str, str]] = None @@ -83,8 +81,7 @@ def basic_request( headers["authorization"] = ( self.session.token_type + " " + self.session.access_token ) - - url = urljoin(f"{self.session.config.api_location}{api_version}", path) + url = urljoin(self.session.config.api_location, path) request = self.session.request_session.request( method, url, params=request_params, data=data, headers=headers ) @@ -114,7 +111,6 @@ def request( self, method: Methods, path: str, - api_version: str = "v1/", params: Optional[Params] = None, data: Optional[JsonObj] = None, headers: Optional[MutableMapping[str, str]] = None, @@ -131,7 +127,7 @@ def request( :return: The json data at specified api endpoint. """ - request = self.basic_request(method, path, api_version, params, data, headers) + request = self.basic_request(method, path, params, data, headers) log.debug("request: %s", request.request.url) request.raise_for_status() if request.content: @@ -141,7 +137,6 @@ def request( def map_request( self, url: str, - api_version: str = "v1/", params: Optional[Params] = None, parse: Optional[Callable[..., Any]] = None, ) -> Any: @@ -156,7 +151,7 @@ def map_request( :return: The object(s) at the url, with the same type as the class of the parse method. """ - json_obj = self.request("GET", url, api_version, params).json() + json_obj = self.request("GET", url, params).json() return self.map_json(json_obj, parse=parse) diff --git a/tidalapi/session.py b/tidalapi/session.py index ae4da44..c7df230 100644 --- a/tidalapi/session.py +++ b/tidalapi/session.py @@ -112,10 +112,6 @@ def __init__( ): self.quality = quality.value self.video_quality = video_quality.value - self.api_location = "https://api.tidal.com/" - self.image_url = "https://resources.tidal.com/images/%s/%ix%i.jpg" - self.video_url = "https://resources.tidal.com/videos/%s/%ix%i.mp4" - self.alac = alac if item_limit > 10000: diff --git a/tidalapi/user.py b/tidalapi/user.py index 6e22e33..99496a8 100644 --- a/tidalapi/user.py +++ b/tidalapi/user.py @@ -25,6 +25,7 @@ from copy import copy from typing import TYPE_CHECKING, Dict, List, Optional, Union, cast +from urllib.parse import urljoin from tidalapi.types import JsonObj @@ -392,8 +393,7 @@ def mixes(self, limit: Optional[int] = 50, offset: int = 0) -> List["MixV2"]: return cast( List["MixV2"], self.requests.map_request( - f"{self.v2_base_url}/mixes", - api_version="v2/", + url=urljoin("https://api.tidal.com/v2", f"{self.v2_base_url}/mixes"), params=params, parse=self.session.parse_v2_mix, ),