Skip to content

Commit 1dfc8b7

Browse files
committed
Another subset of review comments from @snejus:
- Renamed _extract_* methods to _parse_* - Renamed release to date_parts - Using .get instead of .request("GET"...)
1 parent 4ed5363 commit 1dfc8b7

3 files changed

Lines changed: 24 additions & 27 deletions

File tree

beetsplug/tidal/__init__.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -372,37 +372,37 @@ def _get_album_info(
372372
track_info.index = i
373373
track_infos.append(track_info)
374374

375-
artist_names, artist_ids = self._extract_artists(
375+
artist_names, artist_ids = self._parse_artists(
376376
album["relationships"]["artists"]["data"],
377377
artist_lookup,
378378
)
379-
release = self._extract_release_date(album["attributes"])
379+
date_parts = self._parse_release_date(album["attributes"])
380380
return AlbumInfo(
381381
# Identifier
382382
data_source=self.data_source,
383383
album_id=album["id"],
384384
artists_ids=artist_ids,
385-
data_url=self._extract_data_url(album["attributes"]),
385+
data_url=self._parse_data_url(album["attributes"]),
386386
barcode=album["attributes"]["barcodeId"],
387387
# Meta
388-
album=self._extract_title(album["attributes"]),
388+
album=self._parse_title(album["attributes"]),
389389
tracks=track_infos,
390390
artist=", ".join(artist_names),
391391
artists=artist_names,
392392
duration=self._duration_to_seconds(album["attributes"]["duration"]),
393393
albumtype=album["attributes"]["albumType"],
394-
label=self._extract_label(album["attributes"]),
395-
year=release[0] if release else None,
396-
month=release[1] if release else None,
397-
day=release[2] if release else None,
394+
label=self._parse_label(album["attributes"]),
395+
year=date_parts[0] if date_parts else None,
396+
month=date_parts[1] if date_parts else None,
397+
day=date_parts[2] if date_parts else None,
398398
)
399399

400400
def _get_track_info(
401401
self,
402402
track: TidalTrack,
403403
artist_lookup: dict[str, TidalArtist],
404404
) -> TrackInfo:
405-
artist_names, artist_ids = self._extract_artists(
405+
artist_names, artist_ids = self._parse_artists(
406406
track["relationships"]["artists"]["data"],
407407
artist_lookup,
408408
)
@@ -412,18 +412,18 @@ def _get_track_info(
412412
data_source=self.data_source,
413413
track_id=track["id"],
414414
artists_ids=artist_ids,
415-
data_url=self._extract_data_url(track["attributes"]),
415+
data_url=self._parse_data_url(track["attributes"]),
416416
# Meta
417-
title=self._extract_title(track["attributes"]),
417+
title=self._parse_title(track["attributes"]),
418418
isrc=track["attributes"]["isrc"],
419419
artist=", ".join(artist_names),
420420
artists=artist_names,
421421
duration=self._duration_to_seconds(track["attributes"]["duration"]),
422-
label=self._extract_label(track["attributes"]),
422+
label=self._parse_label(track["attributes"]),
423423
)
424424

425425
@staticmethod
426-
def _extract_artists(
426+
def _parse_artists(
427427
artist_relationships: list[ResourceIdentifier],
428428
artist_lookup: dict[str, TidalArtist],
429429
) -> tuple[list[str], list[str]]:
@@ -447,7 +447,7 @@ def _extract_artists(
447447
return artist_names, artist_ids
448448

449449
@staticmethod
450-
def _extract_title(attributes: AlbumAttributes | TrackAttributes):
450+
def _parse_title(attributes: AlbumAttributes | TrackAttributes):
451451
"""
452452
Tidal UIs append the version string at the end of the title. We do the same here
453453
by formatting it as ``"{title} ({version})"`` to stay consistent.
@@ -458,7 +458,7 @@ def _extract_title(attributes: AlbumAttributes | TrackAttributes):
458458
return attributes["title"]
459459

460460
@staticmethod
461-
def _extract_data_url(
461+
def _parse_data_url(
462462
attributes: AlbumAttributes | TrackAttributes,
463463
) -> str | None:
464464
if external_links := attributes.get("externalLinks"):
@@ -483,15 +483,15 @@ def _duration_to_seconds(duration: str) -> int:
483483
)
484484

485485
@staticmethod
486-
def _extract_label(
486+
def _parse_label(
487487
attributes: AlbumAttributes | TrackAttributes,
488488
) -> str | None:
489489
if copyright := attributes.get("copyright"):
490490
return copyright["text"]
491491
return None
492492

493493
@staticmethod
494-
def _extract_release_date(
494+
def _parse_release_date(
495495
attributes: AlbumAttributes,
496496
) -> tuple[int, int, int] | None:
497497
"""Returns year, month, day from iso YYYY-MM-DD"""

beetsplug/tidal/api.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ def get_paginated(
121121
) -> Document[list[Any]]:
122122
"""
123123
Perform a GET request to the Tidal API with pagination resolution.
124-
125-
This handles both top-level pagination and nested relationship pagination.
126124
"""
127125
include = include or []
128126
params = params or {}
@@ -134,8 +132,7 @@ def get_paginated(
134132
}
135133

136134
while next := doc.get("links", {}).get("next"):
137-
res = self.request(
138-
method="GET",
135+
res = self.get(
139136
url=next,
140137
params={**params, "include": include},
141138
**kwargs,

test/plugins/test_tidal.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,8 @@ class TestStaticHelpers:
535535
({}, None),
536536
],
537537
)
538-
def test_extract_data_url(self, attrs, expected):
539-
assert TidalPlugin._extract_data_url(attrs) == expected
538+
def test_parse_data_url(self, attrs, expected):
539+
assert TidalPlugin._parse_data_url(attrs) == expected
540540

541541
@pytest.mark.parametrize(
542542
"attrs, expected",
@@ -545,8 +545,8 @@ def test_extract_data_url(self, attrs, expected):
545545
({}, None),
546546
],
547547
)
548-
def test_extract_label(self, attrs, expected):
549-
assert TidalPlugin._extract_label(attrs) == expected
548+
def test_parse_label(self, attrs, expected):
549+
assert TidalPlugin._parse_label(attrs) == expected
550550

551551
@pytest.mark.parametrize(
552552
"attrs, expected",
@@ -556,8 +556,8 @@ def test_extract_label(self, attrs, expected):
556556
({"releaseDate": "2024"}, None),
557557
],
558558
)
559-
def test_extract_release_date(self, attrs, expected):
560-
assert TidalPlugin._extract_release_date(attrs) == expected
559+
def test_parse_release_date(self, attrs, expected):
560+
assert TidalPlugin._parse_release_date(attrs) == expected
561561

562562
@pytest.mark.parametrize(
563563
"duration,expected",

0 commit comments

Comments
 (0)