summaryrefslogtreecommitdiff
path: root/tidal_dl_ng/helper/tidal.py
diff options
context:
space:
mode:
authorRobert Honz <exislow+github@gmail.com>2024-02-26 07:27:53 +0100
committerRobert Honz <exislow+github@gmail.com>2024-02-26 07:27:53 +0100
commitd845f40e540f33ec719f1cc3d6b2448456b009ac (patch)
tree6ca10c5dbd2288099b9bd393a14068da2c7c510a /tidal_dl_ng/helper/tidal.py
parent43326ec93f2b8e06caaaf81acac8114dafa1bd61 (diff)
downloadtidal-dl-ng-d845f40e540f33ec719f1cc3d6b2448456b009ac.tar.gz
✨ Direct search for links in GUI is possible. ♻️ Instantiate media method was moved to helper.
Diffstat (limited to 'tidal_dl_ng/helper/tidal.py')
-rw-r--r--tidal_dl_ng/helper/tidal.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tidal_dl_ng/helper/tidal.py b/tidal_dl_ng/helper/tidal.py
index 9c4eeba..bdb2abf 100644
--- a/tidal_dl_ng/helper/tidal.py
+++ b/tidal_dl_ng/helper/tidal.py
@@ -2,6 +2,7 @@ from tidalapi import Album, Mix, Playlist, Session, Track, UserPlaylist, Video
from tidalapi.session import SearchTypes
from tidal_dl_ng.constants import MediaType
+from tidal_dl_ng.helper.exceptions import MediaUnknown
def name_builder_artist(media: Track) -> str:
@@ -104,3 +105,24 @@ def user_media_lists(session: Session) -> [Playlist | UserPlaylist | Mix]:
result: [Playlist | UserPlaylist | Mix] = user_playlists + user_mixes
return result
+
+
+def instantiate_media(
+ session: Session,
+ media_type: type[MediaType.TRACK, MediaType.VIDEO, MediaType.ALBUM, MediaType.PLAYLIST, MediaType.MIX],
+ id_media: str,
+) -> Track | Video:
+ if media_type == MediaType.TRACK:
+ media = Track(session, id_media)
+ elif media_type == MediaType.VIDEO:
+ media = Video(session, id_media)
+ elif media_type == MediaType.ALBUM:
+ media = Album(session, id_media)
+ elif media_type == MediaType.PLAYLIST:
+ media = Playlist(session, id_media)
+ elif media_type == MediaType.MIX:
+ media = Mix(session, id_media)
+ else:
+ raise MediaUnknown
+
+ return media