@@ -70,13 +70,15 @@ class Page:
70
70
_categories_iter : Optional [Iterator ["AllCategories" ]] = None
71
71
_items_iter : Optional [Iterator [Callable [..., Any ]]] = None
72
72
page_category : "PageCategory"
73
+ page_category_v2 : "PageCategoryV2"
73
74
request : "Requests"
74
75
75
76
def __init__ (self , session : "Session" , title : str ):
76
77
self .request = session .request
77
78
self .categories = None
78
79
self .title = title
79
80
self .page_category = PageCategory (session )
81
+ self .page_category_v2 = PageCategoryV2 (session )
80
82
81
83
def __iter__ (self ) -> "Page" :
82
84
if self .categories is None :
@@ -117,12 +119,9 @@ def parse(self, json_obj: JsonObj) -> "Page":
117
119
return copy .copy (self )
118
120
119
121
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
122
self .categories = []
124
123
for item in json_obj ["items" ]:
125
- page_item = self .page_category .parse (item )
124
+ page_item = self .page_category_v2 .parse (item )
126
125
self .categories .append (page_item )
127
126
128
127
return copy .copy (self )
@@ -181,6 +180,7 @@ def __init__(self, session: "Session"):
181
180
def parse (self , json_obj : JsonObj ) -> AllCategories :
182
181
result = None
183
182
category_type = json_obj ["type" ]
183
+ print (category_type )
184
184
if category_type in ("PAGE_LINKS_CLOUD" , "PAGE_LINKS" ):
185
185
category : PageCategories = PageLinks (self .session )
186
186
elif category_type in ("FEATURED_PROMOTIONS" , "MULTIPLE_TOP_PROMOTIONS" ):
@@ -209,10 +209,6 @@ def parse(self, json_obj: JsonObj) -> AllCategories:
209
209
elif category_type == "SOCIAL" :
210
210
json_obj ["items" ] = json_obj ["socialProfiles" ]
211
211
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 )
216
212
else :
217
213
raise NotImplementedError (f"PageType { category_type } not implemented" )
218
214
@@ -232,6 +228,41 @@ def show_more(self) -> Optional[Page]:
232
228
)
233
229
234
230
231
+ class PageCategoryV2 :
232
+ type = None
233
+ title : Optional [str ] = None
234
+ description : Optional [str ] = ""
235
+ request : "Requests"
236
+
237
+ def __init__ (self , session : "Session" ):
238
+ self .session = session
239
+ self .request = session .request
240
+ self .item_types : Dict [str , Callable [..., Any ]] = {
241
+ "ALBUM_LIST" : self .session .parse_album ,
242
+ "ARTIST_LIST" : self .session .parse_artist ,
243
+ "TRACK_LIST" : self .session .parse_track ,
244
+ "PLAYLIST_LIST" : self .session .parse_playlist ,
245
+ "VIDEO_LIST" : self .session .parse_video ,
246
+ "MIX_LIST" : self .session .parse_mix ,
247
+ }
248
+
249
+ def parse (self , json_obj : JsonObj ) -> AllCategories :
250
+ category_type = json_obj ["type" ]
251
+ print (category_type )
252
+ # if category_type in self.item_types.keys():
253
+ # category = ItemListV2(self.session)
254
+ # el
255
+ if category_type == "SHORTCUT_LIST" :
256
+ category = ShortcutList (self .session )
257
+ elif category_type == "HORIZONTAL_LIST" :
258
+ category = HorizontalList (self .session )
259
+ else :
260
+ return None
261
+ # raise NotImplementedError(f"PageType {category_type} not implemented")
262
+
263
+ return category .parse (json_obj )
264
+
265
+
235
266
class SimpleList (PageCategory ):
236
267
"""A simple list of different items for the home page V2"""
237
268
@@ -252,21 +283,22 @@ def parse(self, json_obj: JsonObj) -> "SimpleList":
252
283
253
284
def get_item (self , json_obj ):
254
285
item_type = json_obj ["type" ]
255
- item_data = json_obj ["data" ]
286
+ # item_data = json_obj["data"]
256
287
257
288
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
289
+ return self .session .parse_playlist (json_obj )
290
+ # elif item_type == "VIDEO":
291
+ # return self.session.parse_video(item_data)
292
+ # elif item_type == "TRACK":
293
+ # return self.session.parse_track(item_data)
294
+ # elif item_type == "ARTIST":
295
+ # return self.session.parse_artist(item_data)
296
+ # elif item_type == "ALBUM":
297
+ # return self.session.parse_album(item_data)
298
+ # elif item_type == "MIX":
299
+ # return self.session.parse_v2_mix(json_obj)
300
+ # raise NotImplementedError
301
+ return None
270
302
271
303
272
304
class HorizontalList (SimpleList ):
@@ -355,6 +387,33 @@ def parse(self, json_obj: JsonObj) -> "ItemList":
355
387
return copy .copy (self )
356
388
357
389
390
+ class ItemListV2 (PageCategory ):
391
+ """A list of items from TIDAL, can be a list of mixes, for example, or a list of
392
+ playlists and mixes in some cases."""
393
+
394
+ items : Optional [List [Any ]] = None
395
+
396
+ def parse (self , json_obj : JsonObj ) -> "ItemListV2" :
397
+ """Parse a list of items on TIDAL from the pages endpoints.
398
+
399
+ :param json_obj: The json from TIDAL to be parsed
400
+ :return: A copy of the ItemListV2 with a list of items
401
+ """
402
+ self .title = json_obj ["title" ]
403
+ item_type = json_obj ["type" ]
404
+ session : Optional ["Session" ] = None
405
+ parse : Optional [Callable [..., Any ]] = None
406
+
407
+ if item_type in self .item_types .keys ():
408
+ parse = self .item_types [item_type ]
409
+ else :
410
+ raise NotImplementedError ("PageType {} not implemented" .format (item_type ))
411
+
412
+ self .items = self .request .map_json (json_obj ["items" ], parse , session )
413
+
414
+ return copy .copy (self )
415
+
416
+
358
417
class PageLink :
359
418
"""A Link to another :class:`.Page` on TIDAL, Call get() to retrieve the Page."""
360
419
0 commit comments