2020Classes: :class:`Media`, :class:`Track`, :class:`Video`
2121"""
2222
23+ from __future__ import annotations
24+
2325import copy
2426from abc import abstractmethod
2527from datetime import datetime
26- from typing import List , Optional , Union , cast
28+ from enum import Enum
29+ from typing import TYPE_CHECKING , List , Optional , Union , cast
2730
2831import dateutil .parser
2932
30- import tidalapi
33+ if TYPE_CHECKING :
34+ import tidalapi
35+
3136from tidalapi .types import JsonObj
3237
3338
39+ class Quality (Enum ):
40+ lossless = "LOSSLESS"
41+ high = "HIGH"
42+ low = "LOW"
43+ master = "HI_RES"
44+
45+
46+ class VideoQuality (Enum ):
47+ high = "HIGH"
48+ medium = "MEDIUM"
49+ low = "LOW"
50+
51+
3452class Media :
3553 """
3654 Base class for generic media, specifically :class:`Track` and :class:`Video`
@@ -52,16 +70,14 @@ class Media:
5270 volume_num : int = 1
5371 explicit : bool = False
5472 popularity : int = - 1
55- artist : Optional [tidalapi .artist . Artist ] = None
73+ artist : Optional [tidalapi .Artist ] = None
5674 #: For the artist credit page
5775 artist_roles = None
58- artists : Optional [List [tidalapi .artist . Artist ]] = None
76+ artists : Optional [List [tidalapi .Artist ]] = None
5977 album : Optional [tidalapi .album .Album ] = None
6078 type : Optional [str ] = None
6179
62- def __init__ (
63- self , session : tidalapi .session .Session , media_id : Optional [str ] = None
64- ):
80+ def __init__ (self , session : tidalapi .Session , media_id : Optional [str ] = None ):
6581 self .session = session
6682 self .requests = self .session .request
6783 self .album = session .album ()
@@ -70,7 +86,7 @@ def __init__(
7086 self ._get (self .id )
7187
7288 @abstractmethod
73- def _get (self , media_id : str ) -> " Media" :
89+ def _get (self , media_id : str ) -> Media :
7490 raise NotImplementedError (
7591 "You are not supposed to use the media class directly."
7692 )
@@ -140,20 +156,20 @@ class Track(Media):
140156 replay_gain = None
141157 peak = None
142158 isrc = None
143- audio_quality : Optional [tidalapi . session . Quality ] = None
159+ audio_quality : Optional [Quality ] = None
144160 version = None
145161 full_name : Optional [str ] = None
146162 copyright = None
147163
148- def parse_track (self , json_obj : JsonObj ) -> " Track" :
164+ def parse_track (self , json_obj : JsonObj ) -> Track :
149165 Media .parse (self , json_obj )
150166 self .replay_gain = json_obj ["replayGain" ]
151167 # Tracks from the pages endpoints might not actually exist
152168 if "peak" in json_obj and "isrc" in json_obj :
153169 self .peak = json_obj ["peak" ]
154170 self .isrc = json_obj ["isrc" ]
155171 self .copyright = json_obj ["copyright" ]
156- self .audio_quality = tidalapi . session . Quality (json_obj ["audioQuality" ])
172+ self .audio_quality = Quality (json_obj ["audioQuality" ])
157173 self .version = json_obj ["version" ]
158174
159175 if self .version is not None :
@@ -284,7 +300,7 @@ class Video(Media):
284300 video_quality : Optional [str ] = None
285301 cover : Optional [str ] = None
286302
287- def parse_video (self , json_obj : JsonObj ) -> " Video" :
303+ def parse_video (self , json_obj : JsonObj ) -> Video :
288304 Media .parse (self , json_obj )
289305 release_date = json_obj .get ("releaseDate" )
290306 self .release_date = (
@@ -296,7 +312,7 @@ def parse_video(self, json_obj: JsonObj) -> "Video":
296312
297313 return copy .copy (self )
298314
299- def _get (self , media_id : str ) -> " Video" :
315+ def _get (self , media_id : str ) -> Video :
300316 """Returns information about the video, and replaces the object used to call
301317 this function.
302318
0 commit comments