Skip to content

Commit 4ed5363

Browse files
committed
A subset of review comments from @snejus:
- Renamed id to _id - Aligned line breaks for some comment with actual ruff line length - Removed comment dividers - Removed a number of unnecessary or duplicate comments
1 parent 865a799 commit 4ed5363

3 files changed

Lines changed: 8 additions & 33 deletions

File tree

beetsplug/tidal/__init__.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@
3636

3737

3838
class TidalPlugin(MetadataSourcePlugin):
39-
"""Tidal metadata plugin.
40-
41-
Allows to fetch metadata candidates from tidal.
42-
"""
43-
4439
def __init__(self) -> None:
4540
super().__init__()
4641

@@ -168,8 +163,6 @@ def item_candidates(
168163
log.debug("Found {0} candidates", len(candidates))
169164
return candidates
170165

171-
# ---------------------------------- Search ---------------------------------- #
172-
173166
@staticmethod
174167
def _item_queries(item: Item) -> Iterable[str]:
175168
"""Search queries for items."""
@@ -272,9 +265,8 @@ def search_tracks_by_ids(
272265
if item["type"] == "artists"
273266
}
274267

275-
# Yield for IDs first
276-
for id in _ids:
277-
if id is not None and (track := track_lookup.get(id)):
268+
for _id in _ids:
269+
if _id is not None and (track := track_lookup.get(_id)):
278270
yield self._get_track_info(track, artist_lookup=artist_lookup)
279271
else:
280272
yield None
@@ -339,9 +331,8 @@ def search_albums_by_ids(
339331
if item["type"] == "artists"
340332
}
341333

342-
# Yield for IDs first
343-
for id in _ids:
344-
if id is not None and (album := album_lookup.get(id)):
334+
for _id in _ids:
335+
if _id is not None and (album := album_lookup.get(_id)):
345336
yield self._get_album_info(
346337
album,
347338
track_lookup=track_lookup,
@@ -365,8 +356,6 @@ def search_albums_by_ids(
365356
else:
366357
yield None
367358

368-
# ---------------------------------- Parsing --------------------------------- #
369-
370359
def _get_album_info(
371360
self,
372361
album: TidalAlbum,
@@ -413,7 +402,6 @@ def _get_track_info(
413402
track: TidalTrack,
414403
artist_lookup: dict[str, TidalArtist],
415404
) -> TrackInfo:
416-
# Artists are sorted in the track relationship
417405
artist_names, artist_ids = self._extract_artists(
418406
track["relationships"]["artists"]["data"],
419407
artist_lookup,
@@ -441,9 +429,8 @@ def _extract_artists(
441429
) -> tuple[list[str], list[str]]:
442430
"""Extract artists from a relationship.
443431
444-
Needed because artists are ordered in the track relationship,
445-
while the included response data is accessed by id via
446-
``artist_lookup``.
432+
Artists are sorted in the track/album response relationship but not in the
433+
track/album responses included items.
447434
"""
448435
artist_names = []
449436
artist_ids = []
@@ -462,9 +449,8 @@ def _extract_artists(
462449
@staticmethod
463450
def _extract_title(attributes: AlbumAttributes | TrackAttributes):
464451
"""
465-
Tidal UIs append the version string at the end of the
466-
title. We do the same here by formatting it as
467-
``"{title} ({version})"`` to stay consistent.
452+
Tidal UIs append the version string at the end of the title. We do the same here
453+
by formatting it as ``"{title} ({version})"`` to stay consistent.
468454
"""
469455
if version := attributes.get("version"):
470456
return f"{attributes['title']} ({version})"

beetsplug/tidal/api_types.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
from typing_extensions import NotRequired
66

7-
# ----------------------------------- Core ----------------------------------- #
8-
97

108
class ResourceIdentifier(TypedDict):
119
id: str
@@ -36,9 +34,6 @@ class Copyright(TypedDict):
3634
text: str
3735

3836

39-
# -------------------------------- Attributes -------------------------------- #
40-
41-
4237
class ArtistAttributes(TypedDict):
4338
name: str
4439
popularity: float # 0.0 - 1.0, required
@@ -130,9 +125,6 @@ class SearchAttributes(TypedDict):
130125
trackingId: str
131126

132127

133-
# --------------------------------- Resources -------------------------------- #
134-
135-
136128
class TidalArtist(TypedDict):
137129
id: str
138130
type: Literal["artists"]
@@ -172,5 +164,3 @@ class Document(TypedDict, Generic[T]):
172164
AlbumDocument = Document[list[TidalAlbum]]
173165
TrackDocument = Document[list[TidalTrack]]
174166
SearchDocument = Document[TidalSearch]
175-
176-
# ----------------------------------- Search ---------------------------------- #

test/plugins/test_tidal.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
)
2222

2323

24-
# --------------------------------- Mock Data -------------------------------- #
2524
def _make_artist(id: str, name: str) -> TidalArtist:
2625
return {
2726
"id": id,

0 commit comments

Comments
 (0)