4242 from tidalapi .request import Requests
4343 from tidalapi .session import Session
4444
45+ from . import album , artist , media , mix , playlist
46+
4547PageCategories = Union [
4648 "Album" ,
4749 "PageLinks" ,
@@ -114,6 +116,17 @@ def parse(self, json_obj: JsonObj) -> "Page":
114116
115117 return copy .copy (self )
116118
119+ def parseV2 (self , json_obj : JsonObj ) -> "Page" :
120+ """Goes through everything in the page, and gets the title and adds all the rows
121+ to the categories field :param json_obj: The json to be parsed :return: A copy
122+ of the Page that you can use to browse all the items."""
123+ self .categories = []
124+ for item in json_obj ["items" ]:
125+ page_item = self .page_category .parse (item )
126+ self .categories .append (page_item )
127+
128+ return copy .copy (self )
129+
117130 def get (self , endpoint : str , params : Optional [Dict [str , Any ]] = None ) -> "Page" :
118131 """Retrieve a page from the specified endpoint, overwrites the calling page.
119132
@@ -196,6 +209,10 @@ def parse(self, json_obj: JsonObj) -> AllCategories:
196209 elif category_type == "SOCIAL" :
197210 json_obj ["items" ] = json_obj ["socialProfiles" ]
198211 category = LinkList (self .session )
212+ elif category_type == "SHORTCUT_LIST" :
213+ category = ShortcutList (self .session )
214+ elif category_type == "HORIZONTAL_LIST" :
215+ category = HorizontalList (self .session )
199216 else :
200217 raise NotImplementedError (f"PageType { category_type } not implemented" )
201218
@@ -215,6 +232,51 @@ def show_more(self) -> Optional[Page]:
215232 )
216233
217234
235+ class SimpleList (PageCategory ):
236+ """A simple list of different items for the home page V2"""
237+
238+ items : Optional [List [Any ]] = None
239+
240+ def __init__ (self , session : "Session" ):
241+ super ().__init__ (session )
242+ self .session = session
243+
244+ def parse (self , json_obj : JsonObj ) -> "SimpleList" :
245+ self .items = []
246+ self .title = json_obj ["title" ]
247+
248+ for item in json_obj ["items" ]:
249+ self .items .append (self .get_item (item ))
250+
251+ return self
252+
253+ def get_item (self , json_obj ):
254+ item_type = json_obj ["type" ]
255+ item_data = json_obj ["data" ]
256+
257+ if item_type == "PLAYLIST" :
258+ return self .session .parse_playlist (item_data )
259+ elif item_type == "VIDEO" :
260+ return self .session .parse_video (item_data )
261+ elif item_type == "TRACK" :
262+ return self .session .parse_track (item_data )
263+ elif item_type == "ARTIST" :
264+ return self .session .parse_artist (item_data )
265+ elif item_type == "ALBUM" :
266+ return self .session .parse_album (item_data )
267+ elif item_type == "MIX" :
268+ return self .session .parse_mix (item_data )
269+ raise NotImplementedError
270+
271+
272+ class HorizontalList (SimpleList ):
273+ ...
274+
275+
276+ class ShortcutList (SimpleList ):
277+ ...
278+
279+
218280class FeaturedItems (PageCategory ):
219281 """Items that have been featured by TIDAL."""
220282
0 commit comments