Skip to content

Commit 01d7688

Browse files
authored
Merge pull request #155 from PretzelVector/pv
Circular Imports and Typing
2 parents 53e7081 + df05d60 commit 01d7688

7 files changed

Lines changed: 101 additions & 74 deletions

File tree

README.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ tidalapi
99

1010
Unofficial Python API for TIDAL music streaming service.
1111

12+
Requires Python 3.7 or higher.
1213

1314
0.7.0 Rewrite
1415
-------------
@@ -48,3 +49,14 @@ Documentation
4849
-------------
4950

5051
Documentation is available at https://tidalapi.netlify.app/
52+
53+
Development
54+
-----------
55+
56+
This project uses poetry for dependency management and packaging. To install dependencies and setup the project for development, run:
57+
58+
.. code-block:: bash
59+
60+
$ pip install pipx
61+
$ pipx install poetry
62+
$ poetry install --no-root

tidalapi/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from .album import Album # noqa: F401
22
from .artist import Artist, Role # noqa: F401
33
from .genre import Genre # noqa: F401
4-
from .media import Track, Video # noqa: F401
4+
from .media import Quality, Track, Video, VideoQuality # noqa: F401
55
from .mix import Mix # noqa: F401
66
from .page import Page # noqa: F401
77
from .playlist import Playlist, UserPlaylist # noqa: F401
88
from .request import Requests # noqa: F401
9-
from .session import Config, Quality, Session, VideoQuality # noqa: F401
9+
from .session import Config, Session # noqa: F401
1010
from .user import ( # noqa: F401
1111
Favorites,
1212
FetchedUser,

tidalapi/media.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,35 @@
2020
Classes: :class:`Media`, :class:`Track`, :class:`Video`
2121
"""
2222

23+
from __future__ import annotations
24+
2325
import copy
2426
from abc import abstractmethod
2527
from 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

2831
import dateutil.parser
2932

30-
import tidalapi
33+
if TYPE_CHECKING:
34+
import tidalapi
35+
3136
from 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+
3452
class 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

tidalapi/mix.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
# You should have received a copy of the GNU Lesser General Public License
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
"""A module containing functions relating to TIDAL mixes."""
18+
19+
from __future__ import annotations
20+
1821
import copy
1922
from enum import Enum
2023
from typing import TYPE_CHECKING, List, Optional, TypedDict, Union

tidalapi/playlist.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
"""A module containing things related to TIDAL playlists."""
1919

20+
from __future__ import annotations
21+
2022
import copy
21-
from typing import Optional
23+
from typing import TYPE_CHECKING, List, Optional
24+
25+
if TYPE_CHECKING:
26+
import tidalapi
2227

2328
import dateutil.parser
2429

@@ -118,7 +123,7 @@ def parse_factory(self, json_obj):
118123
self.parse(json_obj)
119124
return copy.copy(self.factory())
120125

121-
def tracks(self, limit=None, offset=0):
126+
def tracks(self, limit: Optional[int] = None, offset=0) -> List[tidalapi.Track]:
122127
"""Gets the playlists̈́' tracks from TIDAL.
123128
124129
:param limit: The amount of items you want returned.

0 commit comments

Comments
 (0)