Skip to content
Merged
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
19 changes: 6 additions & 13 deletions tests/test_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,25 +504,18 @@ def test_video_image(session):
verify_image_resolution(session, video.image(1080, 720), 1270, 1270)


def test_full_name_track_1(session):
track = session.track(149119714)
assert track.name == "Fibonacci Progressions (Keemiyo Remix)"
assert track.version is None
assert track.full_name == "Fibonacci Progressions (Keemiyo Remix)"


def test_full_name_track_2(session):
def test_full_name_track_version_available(session):
track = session.track(78495659)
assert track.name == "Bullitt"
assert track.version == "Bonus Track"
assert track.full_name == "Bullitt (Bonus Track)"


def test_full_name_track_3(session):
track = session.track(98849340)
assert track.name == "Magical place (feat. IOVA)"
assert track.version == "Dj Dark & MD Dj Remix"
assert track.full_name == "Magical place (feat. IOVA) (Dj Dark & MD Dj Remix)"
def test_full_name_track_version_none(session):
track = session.track(113210329)
assert track.name == "Enormous"
assert track.version is None
assert track.full_name == "Enormous"


def test_track_media_metadata_tags(session):
Expand Down
13 changes: 11 additions & 2 deletions tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ def test_get_favorite_tracks(session):
favorites = session.user.favorites
tracks = favorites.tracks_paginated()
tracks_count = favorites.get_tracks_count()
assert len(tracks) > 0 # and tracks_count == len(tracks)
# Only the available tracks are returned so the final track count might be lower
assert len(tracks) > 0 and tracks_count >= len(tracks)
assert isinstance(tracks[0], tidalapi.Track)


Expand Down Expand Up @@ -486,7 +487,7 @@ def test_get_favorite_videos(session):
favorites = session.user.favorites
videos = favorites.videos_paginated()
videos_count = favorites.get_videos_count()
assert len(videos) == videos_count and videos_count > 0
assert videos_count > 0 and len(videos) == videos_count
assert isinstance(videos[0], tidalapi.media.Video)


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


def test_get_favorite_playlists(session):
favorites = session.user.favorites
playlists = favorites.playlists_paginated()
playlists_count = favorites.get_playlists_count()
assert len(playlists) > 0 and playlists_count == len(playlists)
assert isinstance(playlists[0], tidalapi.Playlist)


def test_get_favorite_playlists_order(session):
# Add 5 favourite playlists to ensure enough playlists exist for the tests
playlist_ids = [
Expand Down
2 changes: 1 addition & 1 deletion tidalapi/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def parse_track(self, json_obj: JsonObj, album: Optional[Album] = None) -> Track

self.date_added = self.user_date_added
self.description = json_obj.get("description")
self.version = json_obj.get("version")
self.version = json_obj.get("version") if json_obj.get("version") else None
self.copyright = json_obj.get("copyright")

self.bpm = json_obj.get("bpm")
Expand Down
1 change: 1 addition & 0 deletions tidalapi/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ def get_tracks_count(
This performs a minimal API request (limit=1) to fetch metadata about the tracks
without retrieving all of them. The API response contains 'totalNumberOfItems',
which represents the total items (tracks) available.
Note: This number also includes track that may not be available for playback
:return: The number of items available.
"""
params = {"limit": 1, "offset": 0}
Expand Down
12 changes: 11 additions & 1 deletion tidalapi/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ def get_items(
items = []

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

for page_items in pool.map(func_wrapper, args_list):
items.extend(page_items)
Expand Down