@@ -176,16 +176,22 @@ class TextInfo:
176
176
class MixV2 :
177
177
"""A mix from TIDALs v2 api endpoint."""
178
178
179
+ mix_type : Optional [MixType ] = None
180
+ country_code : Optional [str ] = None
179
181
date_added : Optional [datetime ] = None
180
- title : Optional [str ] = None
181
182
id : Optional [str ] = None
182
- mix_type : Optional [MixType ] = None
183
+ artifact_id_type : Optional [str ] = None
184
+ content_behavior : Optional [str ] = None
183
185
images : Optional [ImageResponse ] = None
184
186
detail_images : Optional [ImageResponse ] = None
185
187
master = False
188
+ is_stable_id = False
189
+ title : Optional [str ] = None
190
+ sub_title : Optional [str ] = None
191
+ short_subtitle : Optional [str ] = None
186
192
title_text_info : Optional [TextInfo ] = None
187
193
sub_title_text_info : Optional [TextInfo ] = None
188
- sub_title : Optional [str ] = None
194
+ short_subtitle_text_info : Optional [TextInfo ] = None
189
195
updated : Optional [datetime ] = None
190
196
_retrieved = False
191
197
_items : Optional [List [Union ["Video" , "Track" ]]] = None
@@ -232,38 +238,84 @@ def parse(self, json_obj: JsonObj) -> "MixV2":
232
238
:param json_obj: The json of a mix to be parsed
233
239
:return: A copy of the parsed mix
234
240
"""
235
- date_added = json_obj .get ("dateAdded" )
236
- self .date_added = dateutil .parser .isoparse (date_added ) if date_added else None
237
- self .title = json_obj ["title" ]
241
+
238
242
self .id = json_obj ["id" ]
239
- self .title = json_obj ["title" ]
240
- self .mix_type = MixType (json_obj ["mixType" ])
241
- images = json_obj ["images" ]
242
- self .images = ImageResponse (
243
- small = images ["SMALL" ]["url" ],
244
- medium = images ["MEDIUM" ]["url" ],
245
- large = images ["LARGE" ]["url" ],
246
- )
247
- detail_images = json_obj ["detailImages" ]
248
- self .detail_images = ImageResponse (
249
- small = detail_images ["SMALL" ]["url" ],
250
- medium = detail_images ["MEDIUM" ]["url" ],
251
- large = detail_images ["LARGE" ]["url" ],
252
- )
253
- self .master = json_obj ["master" ]
254
- title_text_info = json_obj ["titleTextInfo" ]
255
- self .title_text_info = TextInfo (
256
- text = title_text_info ["text" ],
257
- color = title_text_info ["color" ],
258
- )
259
- sub_title_text_info = json_obj ["subTitleTextInfo" ]
260
- self .sub_title_text_info = TextInfo (
261
- text = sub_title_text_info ["text" ],
262
- color = sub_title_text_info ["color" ],
263
- )
264
- self .sub_title = json_obj ["subTitle" ]
265
- updated = json_obj .get ("updated" )
266
- self .date_added = dateutil .parser .isoparse (updated ) if date_added else None
243
+ if json_obj .get ("mixType" ):
244
+ date_added = json_obj .get ("dateAdded" )
245
+ self .date_added = (
246
+ dateutil .parser .isoparse (date_added ) if date_added else None
247
+ )
248
+ self .title = json_obj ["title" ]
249
+ self .sub_title = json_obj ["subTitle" ]
250
+ images = json_obj ["images" ]
251
+ self .images = ImageResponse (
252
+ small = images ["SMALL" ]["url" ],
253
+ medium = images ["MEDIUM" ]["url" ],
254
+ large = images ["LARGE" ]["url" ],
255
+ )
256
+ detail_images = json_obj ["detailImages" ]
257
+ self .detail_images = ImageResponse (
258
+ small = detail_images ["SMALL" ]["url" ],
259
+ medium = detail_images ["MEDIUM" ]["url" ],
260
+ large = detail_images ["LARGE" ]["url" ],
261
+ )
262
+ self .master = json_obj ["master" ]
263
+ title_text_info = json_obj ["titleTextInfo" ]
264
+ self .title_text_info = TextInfo (
265
+ text = title_text_info ["text" ],
266
+ color = title_text_info ["color" ],
267
+ )
268
+ sub_title_text_info = json_obj ["subTitleTextInfo" ]
269
+ self .sub_title_text_info = TextInfo (
270
+ text = sub_title_text_info ["text" ],
271
+ color = sub_title_text_info ["color" ],
272
+ )
273
+ updated = json_obj .get ("updated" )
274
+ self .updated = dateutil .parser .isoparse (updated ) if updated else None
275
+ elif json_obj .get ("type" ):
276
+ # Certain mix types (e.g. when returned from Page) must be parsed differently. Why, TIDAL?
277
+ self .country_code = json_obj .get ("countryCode" , None )
278
+ self .is_stable_id = json_obj .get ("isStableId" , False )
279
+ self .artifact_id_type = json_obj .get ("trackGroupId" , None )
280
+ self .content_behavior = json_obj .get ("contentBehavior" , None )
281
+
282
+ images = json_obj ["mixImages" ]
283
+ self .images = ImageResponse (
284
+ small = images [0 ]["url" ],
285
+ medium = images [1 ]["url" ],
286
+ large = images [0 ]["url" ],
287
+ )
288
+
289
+ detail_images = json_obj ["detailMixImages" ]
290
+ self .detail_images = ImageResponse (
291
+ small = detail_images [0 ]["url" ],
292
+ medium = detail_images [1 ]["url" ],
293
+ large = detail_images [2 ]["url" ],
294
+ )
295
+
296
+ title_text_info = json_obj ["titleTextInfo" ]
297
+ self .title_text_info = TextInfo (
298
+ text = title_text_info ["text" ],
299
+ color = title_text_info ["color" ],
300
+ )
301
+ self .title = title_text_info ["text" ]
302
+
303
+ sub_title_text_info = json_obj ["subtitleTextInfo" ]
304
+ self .sub_title_text_info = TextInfo (
305
+ text = sub_title_text_info ["text" ],
306
+ color = sub_title_text_info ["color" ],
307
+ )
308
+ self .sub_title = sub_title_text_info ["text" ]
309
+
310
+ short_subtitle_text_info = json_obj ["shortSubtitleTextInfo" ]
311
+ self .short_subtitle_text_info = TextInfo (
312
+ text = sub_title_text_info ["text" ],
313
+ color = sub_title_text_info ["color" ],
314
+ )
315
+ self .short_subtitle = short_subtitle_text_info ["text" ]
316
+
317
+ if json_obj .get ("updated" ):
318
+ self .updated = datetime .fromtimestamp (json_obj ["updated" ] / 1000 )
267
319
268
320
return copy .copy (self )
269
321
0 commit comments