✨ Result pagination implement for Downloader.
This commit is contained in:
@@ -30,7 +30,7 @@ from tidal_dl_ng.constants import (
|
|||||||
from tidal_dl_ng.helper.decryption import decrypt_file, decrypt_security_token
|
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, MediaUnknown, UnknownManifestFormat
|
||||||
from tidal_dl_ng.helper.path import check_file_exists, format_path_media, path_file_sanitize
|
from tidal_dl_ng.helper.path import check_file_exists, format_path_media, path_file_sanitize
|
||||||
from tidal_dl_ng.helper.tidal import name_builder_item
|
from tidal_dl_ng.helper.tidal import items_results_all, name_builder_item
|
||||||
from tidal_dl_ng.helper.wrapper import WrapperLogger
|
from tidal_dl_ng.helper.wrapper import WrapperLogger
|
||||||
from tidal_dl_ng.metadata import Metadata
|
from tidal_dl_ng.metadata import Metadata
|
||||||
from tidal_dl_ng.model.gui_data import ProgressBars
|
from tidal_dl_ng.model.gui_data import ProgressBars
|
||||||
@@ -306,18 +306,20 @@ class Download:
|
|||||||
# Create file name and path
|
# Create file name and path
|
||||||
file_name_relative = format_path_media(file_template, media)
|
file_name_relative = format_path_media(file_template, media)
|
||||||
|
|
||||||
# TODO: Extend with pagination support: Iterate through `items` and `tracks`until len(returned list) == 0
|
# Get the name of the list and check, if videos should be included.
|
||||||
# Get the items and name of the list.
|
videos_include: bool = True
|
||||||
|
|
||||||
if isinstance(media, Mix):
|
if isinstance(media, Mix):
|
||||||
items = media.items()
|
|
||||||
list_media_name = media.title[:30]
|
list_media_name = media.title[:30]
|
||||||
elif video_download:
|
elif video_download:
|
||||||
items = media.items(limit=100)
|
|
||||||
list_media_name = media.name[:30]
|
list_media_name = media.name[:30]
|
||||||
else:
|
else:
|
||||||
items = media.tracks(limit=999)
|
videos_include = False
|
||||||
list_media_name = media.name[:30]
|
list_media_name = media.name[:30]
|
||||||
|
|
||||||
|
# Get all items of the list.
|
||||||
|
items = items_results_all(media, videos_include=videos_include)
|
||||||
|
|
||||||
# Determine where to redirect the progress information.
|
# Determine where to redirect the progress information.
|
||||||
if progress_gui is None:
|
if progress_gui is None:
|
||||||
progress_stdout: bool = True
|
progress_stdout: bool = True
|
||||||
|
|||||||
+3
-3
@@ -2,7 +2,7 @@ import math
|
|||||||
import sys
|
import sys
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
|
|
||||||
from helper.tidal import items_all_results, search_all_results
|
from helper.tidal import items_results_all, search_results_all
|
||||||
|
|
||||||
from tidal_dl_ng.helper.path import get_format_template
|
from tidal_dl_ng.helper.path import get_format_template
|
||||||
|
|
||||||
@@ -272,7 +272,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
self.tr_results.addTopLevelItem(child)
|
self.tr_results.addTopLevelItem(child)
|
||||||
|
|
||||||
def search(self, query: str, types_media: SearchTypes) -> [ResultSearch]:
|
def search(self, query: str, types_media: SearchTypes) -> [ResultSearch]:
|
||||||
result_search: dict[str, [SearchTypes]] = search_all_results(
|
result_search: dict[str, [SearchTypes]] = search_results_all(
|
||||||
session=self.tidal.session, needle=query, types_media=types_media
|
session=self.tidal.session, needle=query, types_media=types_media
|
||||||
)
|
)
|
||||||
result: [ResultSearch] = []
|
result: [ResultSearch] = []
|
||||||
@@ -392,7 +392,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
media_list = item.data(3, QtCore.Qt.ItemDataRole.UserRole)
|
media_list = item.data(3, QtCore.Qt.ItemDataRole.UserRole)
|
||||||
|
|
||||||
# Get all results
|
# Get all results
|
||||||
media_items: [Track | Video] = items_all_results(media_list)
|
media_items: [Track | Video] = items_results_all(media_list)
|
||||||
result: [ResultSearch] = self.search_result_to_model(media_items)
|
result: [ResultSearch] = self.search_result_to_model(media_items)
|
||||||
|
|
||||||
self.populate_tree_results(result)
|
self.populate_tree_results(result)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ def get_tidal_media_type(url_media: str) -> MediaType | bool:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def search_all_results(session: Session, needle: str, types_media: SearchTypes = None) -> dict[str, [SearchTypes]]:
|
def search_results_all(session: Session, needle: str, types_media: SearchTypes = None) -> dict[str, [SearchTypes]]:
|
||||||
limit: int = 300
|
limit: int = 300
|
||||||
offset: int = 0
|
offset: int = 0
|
||||||
done: bool = False
|
done: bool = False
|
||||||
@@ -72,7 +72,7 @@ def search_all_results(session: Session, needle: str, types_media: SearchTypes =
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def items_all_results(media_list: [Mix | Playlist | Album]) -> [Track | Video]:
|
def items_results_all(media_list: [Mix | Playlist | Album], videos_include: bool = True) -> [Track | Video]:
|
||||||
limit: int = 100
|
limit: int = 100
|
||||||
offset: int = 0
|
offset: int = 0
|
||||||
done: bool = False
|
done: bool = False
|
||||||
@@ -82,7 +82,11 @@ def items_all_results(media_list: [Mix | Playlist | Album]) -> [Track | Video]:
|
|||||||
result = media_list.items()
|
result = media_list.items()
|
||||||
else:
|
else:
|
||||||
while not done:
|
while not done:
|
||||||
tmp_result: [Track | Video] = media_list.items(limit=limit, offset=offset)
|
tmp_result: [Track | Video] = (
|
||||||
|
media_list.items(limit=limit, offset=offset)
|
||||||
|
if videos_include
|
||||||
|
else media_list.tracks(limit=limit, offset=offset)
|
||||||
|
)
|
||||||
|
|
||||||
if bool(tmp_result):
|
if bool(tmp_result):
|
||||||
result += tmp_result
|
result += tmp_result
|
||||||
|
|||||||
Reference in New Issue
Block a user