Skip to content

Commit 5e1e4ba

Browse files
authored
Merge pull request #390 from EbbLabs/feature/bugfixes
Feature/bugfixes
2 parents 5164a23 + 0874236 commit 5e1e4ba

File tree

5 files changed

+30
-17
lines changed

5 files changed

+30
-17
lines changed

tests/test_media.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -504,25 +504,18 @@ def test_video_image(session):
504504
verify_image_resolution(session, video.image(1080, 720), 1270, 1270)
505505

506506

507-
def test_full_name_track_1(session):
508-
track = session.track(149119714)
509-
assert track.name == "Fibonacci Progressions (Keemiyo Remix)"
510-
assert track.version is None
511-
assert track.full_name == "Fibonacci Progressions (Keemiyo Remix)"
512-
513-
514-
def test_full_name_track_2(session):
507+
def test_full_name_track_version_available(session):
515508
track = session.track(78495659)
516509
assert track.name == "Bullitt"
517510
assert track.version == "Bonus Track"
518511
assert track.full_name == "Bullitt (Bonus Track)"
519512

520513

521-
def test_full_name_track_3(session):
522-
track = session.track(98849340)
523-
assert track.name == "Magical place (feat. IOVA)"
524-
assert track.version == "Dj Dark & MD Dj Remix"
525-
assert track.full_name == "Magical place (feat. IOVA) (Dj Dark & MD Dj Remix)"
514+
def test_full_name_track_version_none(session):
515+
track = session.track(113210329)
516+
assert track.name == "Enormous"
517+
assert track.version is None
518+
assert track.full_name == "Enormous"
526519

527520

528521
def test_track_media_metadata_tags(session):

tests/test_user.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,8 @@ def test_get_favorite_tracks(session):
430430
favorites = session.user.favorites
431431
tracks = favorites.tracks_paginated()
432432
tracks_count = favorites.get_tracks_count()
433-
assert len(tracks) > 0 # and tracks_count == len(tracks)
433+
# Only the available tracks are returned so the final track count might be lower
434+
assert len(tracks) > 0 and tracks_count >= len(tracks)
434435
assert isinstance(tracks[0], tidalapi.Track)
435436

436437

@@ -486,7 +487,7 @@ def test_get_favorite_videos(session):
486487
favorites = session.user.favorites
487488
videos = favorites.videos_paginated()
488489
videos_count = favorites.get_videos_count()
489-
assert len(videos) == videos_count and videos_count > 0
490+
assert videos_count > 0 and len(videos) == videos_count
490491
assert isinstance(videos[0], tidalapi.media.Video)
491492

492493

@@ -496,6 +497,14 @@ def test_add_remove_favorite_video(session):
496497
add_remove(video_id, favorites.add_video, favorites.remove_video, favorites.videos)
497498

498499

500+
def test_get_favorite_playlists(session):
501+
favorites = session.user.favorites
502+
playlists = favorites.playlists_paginated()
503+
playlists_count = favorites.get_playlists_count()
504+
assert len(playlists) > 0 and playlists_count == len(playlists)
505+
assert isinstance(playlists[0], tidalapi.Playlist)
506+
507+
499508
def test_get_favorite_playlists_order(session):
500509
# Add 5 favourite playlists to ensure enough playlists exist for the tests
501510
playlist_ids = [

tidalapi/media.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def parse_track(self, json_obj: JsonObj, album: Optional[Album] = None) -> Track
367367

368368
self.date_added = self.user_date_added
369369
self.description = json_obj.get("description")
370-
self.version = json_obj.get("version")
370+
self.version = json_obj.get("version") if json_obj.get("version") else None
371371
self.copyright = json_obj.get("copyright")
372372

373373
self.bpm = json_obj.get("bpm")

tidalapi/user.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,7 @@ def get_tracks_count(
840840
This performs a minimal API request (limit=1) to fetch metadata about the tracks
841841
without retrieving all of them. The API response contains 'totalNumberOfItems',
842842
which represents the total items (tracks) available.
843+
Note: This number also includes track that may not be available for playback
843844
:return: The number of items available.
844845
"""
845846
params = {"limit": 1, "offset": 0}

tidalapi/workers.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,17 @@ def get_items(
4141
items = []
4242

4343
with ThreadPoolExecutor(processes) as pool:
44-
args_list = [(func, chunk_size, offset, *args) for offset in offsets]
44+
# Build argument tuples for each worker.
45+
# The limit is capped using `total_count` so the final chunk does not exceed
46+
# the available number of items (e.g., last chunk may be smaller than chunk_size).
47+
# i.e. for a total number of 123 tracks, the following ranges will be generated
48+
# (func, 50, 0, ...)
49+
# (func, 50, 50, ...)
50+
# (func, 23, 100, ...)
51+
args_list = [
52+
(func, min(chunk_size, total_count - offset), offset, *args)
53+
for offset in offsets
54+
]
4555

4656
for page_items in pool.map(func_wrapper, args_list):
4757
items.extend(page_items)

0 commit comments

Comments
 (0)