✨ Direct search for links in GUI is possible. ♻️ Instantiate media method was moved to helper.
This commit is contained in:
+4
-25
@@ -28,9 +28,9 @@ from tidal_dl_ng.constants import (
|
||||
VideoExtensions,
|
||||
)
|
||||
from tidal_dl_ng.helper.decryption import decrypt_file, decrypt_security_token
|
||||
from tidal_dl_ng.helper.exceptions import MediaMissing, MediaUnknown, UnknownManifestFormat
|
||||
from tidal_dl_ng.helper.exceptions import MediaMissing, UnknownManifestFormat
|
||||
from tidal_dl_ng.helper.path import check_file_exists, format_path_media, path_file_sanitize
|
||||
from tidal_dl_ng.helper.tidal import items_results_all, name_builder_item
|
||||
from tidal_dl_ng.helper.tidal import instantiate_media, items_results_all, name_builder_item
|
||||
from tidal_dl_ng.metadata import Metadata
|
||||
from tidal_dl_ng.model.gui_data import ProgressBars
|
||||
from tidal_dl_ng.model.tidal import StreamManifest
|
||||
@@ -154,27 +154,6 @@ class Download:
|
||||
|
||||
return tmp_path_file_decrypted
|
||||
|
||||
def instantiate_media(
|
||||
self,
|
||||
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(self.session, id_media)
|
||||
elif media_type == MediaType.PLAYLIST:
|
||||
media = Playlist(self.session, id_media)
|
||||
elif media_type == MediaType.MIX:
|
||||
media = Mix(self.session, id_media)
|
||||
else:
|
||||
raise MediaUnknown
|
||||
|
||||
return media
|
||||
|
||||
def item(
|
||||
self,
|
||||
file_template: str,
|
||||
@@ -186,7 +165,7 @@ class Download:
|
||||
) -> (bool, str):
|
||||
# If no media instance is provided, we need to create the media instance.
|
||||
if media_id and media_type:
|
||||
media = self.instantiate_media(self.session, media_type, media_id)
|
||||
media = instantiate_media(self.session, media_type, media_id)
|
||||
elif not media:
|
||||
raise MediaMissing
|
||||
|
||||
@@ -350,7 +329,7 @@ class Download:
|
||||
):
|
||||
# If no media instance is provided, we need to create the media instance.
|
||||
if media_id and media_type:
|
||||
media = self.instantiate_media(self.session, media_type, media_id)
|
||||
media = instantiate_media(self.session, media_type, media_id)
|
||||
elif not media:
|
||||
raise MediaMissing
|
||||
|
||||
|
||||
+28
-1
@@ -7,7 +7,14 @@ from requests.exceptions import HTTPError
|
||||
from tidal_dl_ng import __version__
|
||||
from tidal_dl_ng.dialog import DialogLogin, DialogPreferences, DialogVersion
|
||||
from tidal_dl_ng.helper.path import get_format_template
|
||||
from tidal_dl_ng.helper.tidal import items_results_all, search_results_all, user_media_lists
|
||||
from tidal_dl_ng.helper.tidal import (
|
||||
get_tidal_media_id,
|
||||
get_tidal_media_type,
|
||||
instantiate_media,
|
||||
items_results_all,
|
||||
search_results_all,
|
||||
user_media_lists,
|
||||
)
|
||||
|
||||
try:
|
||||
import qdarktheme
|
||||
@@ -342,9 +349,17 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.apply_settings(self.settings)
|
||||
|
||||
def search(self, query: str, types_media: SearchTypes) -> [ResultItem]:
|
||||
# If a direct link was searched for, skip search and create the object from the link directly.
|
||||
if "http" in query:
|
||||
media_type = get_tidal_media_type(query)
|
||||
item_id = get_tidal_media_id(query)
|
||||
media = instantiate_media(self.tidal.session, media_type, item_id)
|
||||
result_search = {"direct": [media]}
|
||||
else:
|
||||
result_search: dict[str, [SearchTypes]] = search_results_all(
|
||||
session=self.tidal.session, needle=query, types_media=types_media
|
||||
)
|
||||
|
||||
result: [ResultItem] = []
|
||||
|
||||
for _media_type, l_media in result_search.items():
|
||||
@@ -404,6 +419,18 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
obj=item,
|
||||
)
|
||||
|
||||
result.append(result_item)
|
||||
elif isinstance(item, Mix):
|
||||
result_item: ResultItem = ResultItem(
|
||||
position=idx,
|
||||
artist=item.sub_title,
|
||||
title=item.title,
|
||||
album="",
|
||||
# TODO: Calculate total duration.
|
||||
duration_sec=-1,
|
||||
obj=item,
|
||||
)
|
||||
|
||||
result.append(result_item)
|
||||
|
||||
return result
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user