Skip to content

Commit c424f32

Browse files
committed
Add support for videos, paginated
1 parent 6f40e33 commit c424f32

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tidalapi/user.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,22 @@ def get_tracks_count(
847847
json_obj = self.requests.map_request(f"{self.base_url}/tracks", params=params)
848848
return json_obj.get("totalNumberOfItems", 0)
849849

850+
def videos_paginated(
851+
self,
852+
order: Optional[ItemOrder] = None,
853+
order_direction: Optional[OrderDirection] = None,
854+
) -> List["Video"]:
855+
"""Get the users favorite videos, using pagination.
856+
857+
:param order: Optional; A :class:`ItemOrder` describing the ordering type when returning the user items. eg.: "NAME, "DATE"
858+
:param order_direction: Optional; A :class:`OrderDirection` describing the ordering direction when sorting by `order`. eg.: "ASC", "DESC"
859+
:return: A :class:`list` :class:`~tidalapi.media.Video` objects containing the favorite videos.
860+
"""
861+
count = self.session.user.favorites.get_videos_count()
862+
return get_items(
863+
self.session.user.favorites.videos, count, order, order_direction
864+
)
865+
850866
def videos(
851867
self,
852868
limit: int = 50,
@@ -877,6 +893,21 @@ def videos(
877893
),
878894
)
879895

896+
def get_videos_count(
897+
self,
898+
) -> int:
899+
"""Get the total number of videos in the user's collection.
900+
901+
This performs a minimal API request (limit=1) to fetch metadata about the tracks
902+
without retrieving all of them. The API response contains 'totalNumberOfItems',
903+
which represents the total items (videos) available.
904+
:return: The number of items available.
905+
"""
906+
params = {"limit": 1, "offset": 0}
907+
908+
json_obj = self.requests.map_request(f"{self.base_url}/videos", params=params)
909+
return json_obj.get("totalNumberOfItems", 0)
910+
880911
def mixes(
881912
self,
882913
limit: int = 50,

0 commit comments

Comments
 (0)