Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for get track by ISRC and get album by BarcodeID #274

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

History
=======
v0.7.7
------
* Add support to get tracks by ISRC - M4TH1EU_
* Add support to get albums by Barcode ID (UPC) - M4TH1EU_

v0.7.6
------
Expand Down Expand Up @@ -178,6 +182,7 @@ v0.6.2
.. _arnesongit: https://github.com/arnesongit
.. _Jimmyscene: https://github.com/Jimmyscene
.. _quodrum-glas: https://github.com/quodrum-glas
.. _M4TH1EU: https://github.com/M4TH1EU



2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tidalapi"
version = "0.7.6"
version = "0.7.7"
description = "Unofficial API for TIDAL music streaming service."
authors = ["Thomas Amland <[email protected]>"]
maintainers = ["tehkillerbee <[email protected]>"]
Expand Down
2 changes: 1 addition & 1 deletion tidalapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
User,
)

__version__ = "0.7.6"
__version__ = "0.7.7"
10 changes: 8 additions & 2 deletions tidalapi/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def basic_request(
params: Optional[Params] = None,
data: Optional[JsonObj] = None,
headers: Optional[MutableMapping[str, str]] = None,
base_url: Optional[str] = None,
) -> requests.Response:
request_params = {
"sessionId": self.session.session_id,
Expand All @@ -90,7 +91,10 @@ def basic_request(
headers["authorization"] = (
self.session.token_type + " " + self.session.access_token
)
url = urljoin(self.session.config.api_v1_location, path)
if base_url is None:
base_url = self.session.config.api_v1_location

url = urljoin(base_url, path)
request = self.session.request_session.request(
method, url, params=request_params, data=data, headers=headers
)
Expand Down Expand Up @@ -123,6 +127,7 @@ def request(
params: Optional[Params] = None,
data: Optional[JsonObj] = None,
headers: Optional[MutableMapping[str, str]] = None,
base_url: Optional[str] = None,
) -> requests.Response:
"""Method for tidal requests.

Expand All @@ -133,10 +138,11 @@ def request(
:param params: The parameters you want to supply with the request.
:param data: The data you want to supply with the request.
:param headers: The headers you want to include with the request
:param base_url: The base url to use for the request
:return: The json data at specified api endpoint.
"""

request = self.basic_request(method, path, params, data, headers)
request = self.basic_request(method, path, params, data, headers, base_url)
log.debug("request: %s", request.request.url)
try:
request.raise_for_status()
Expand Down
40 changes: 40 additions & 0 deletions tidalapi/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,46 @@ def track(
log.warning("Track '%s' is unavailable", track_id)
raise

def get_tracks_by_isrc(self, isrc: str) -> list[media.Track]:
"""Function to search all tracks with a specific ISRC code.

:param isrc: The ISRC of the Track.
:return: Returns a list of :class:`.Track` objects that have access to the session instance used.
"""
try:
res = self.request.request(
"GET",
"tracks",
params={
"filter[isrc]": isrc,
},
base_url="https://openapi.tidal.com/v2/").json()

return [self.track(track['id']) for track in res['data']]
except requests.HTTPError:
log.warning("Wrong ISRC code '%s'", isrc)
raise

def get_albums_by_barcode(self, barcode: str) -> list[album.Album]:
"""Function to search all albums with a specific UPC code.

:param barcode: The UPC of the Album.
:return: Returns a list of :class:`.Album` objects that have access to the session instance used.
"""
try:
res = self.request.request(
"GET",
"albums",
params={
"filter[barcodeId]": barcode,
},
base_url="https://openapi.tidal.com/v2/").json()

return [self.album(album['id']) for album in res['data']]
except HTTPError:
log.warning("Wrong barcode '%s'", barcode)
raise

def video(self, video_id: Optional[str] = None) -> media.Video:
"""Function to create a Video object with access to the session instance in a
smoother way. Calls :class:`tidalapi.Video(session=session, video_id=video_id)
Expand Down
Loading