✨ Download items will now be taken from the queue.
This commit is contained in:
+26
-44
@@ -556,6 +556,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
# Download Queue
|
# Download Queue
|
||||||
self.tr_queue_download.itemClicked.connect(self.on_queue_download_item_clicked)
|
self.tr_queue_download.itemClicked.connect(self.on_queue_download_item_clicked)
|
||||||
self.s_queue_download_item_downloading.connect(self.on_queue_download_item_downloading)
|
self.s_queue_download_item_downloading.connect(self.on_queue_download_item_downloading)
|
||||||
|
self.s_queue_download_item_finished.connect(self.on_queue_download_item_finished)
|
||||||
|
self.s_queue_download_item_failed.connect(self.on_queue_download_item_failed)
|
||||||
|
|
||||||
def on_logout(self):
|
def on_logout(self):
|
||||||
result: bool = self.tidal.logout()
|
result: bool = self.tidal.logout()
|
||||||
@@ -708,11 +710,15 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
QueueDownloadStatus.Waiting.value, QtCore.Qt.MatchFlag.MatchExactly, column=0
|
QueueDownloadStatus.Waiting.value, QtCore.Qt.MatchFlag.MatchExactly, column=0
|
||||||
)
|
)
|
||||||
|
|
||||||
for item in items:
|
if len(items) > 0:
|
||||||
|
item: QtWidgets.QTreeWidgetItem = items[0]
|
||||||
|
media: Track | Album | Playlist | Video | Mix | Artist = get_queue_download_media(item)
|
||||||
|
|
||||||
|
# TODO: Try catch and set FAILED status
|
||||||
self.s_queue_download_item_downloading.emit(item)
|
self.s_queue_download_item_downloading.emit(item)
|
||||||
|
self.on_queue_download(media)
|
||||||
self.s_queue_download_item_finished.emit(item)
|
self.s_queue_download_item_finished.emit(item)
|
||||||
|
else:
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
def on_queue_download_item_downloading(self, item: QtWidgets.QTreeWidgetItem) -> None:
|
def on_queue_download_item_downloading(self, item: QtWidgets.QTreeWidgetItem) -> None:
|
||||||
@@ -727,51 +733,27 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
def queue_download_item_status(self, item: QtWidgets.QTreeWidgetItem, status: str) -> None:
|
def queue_download_item_status(self, item: QtWidgets.QTreeWidgetItem, status: str) -> None:
|
||||||
item.setText(0, status)
|
item.setText(0, status)
|
||||||
|
|
||||||
def on_download_queue(self, media):
|
def on_queue_download(self, media: Track | Album | Playlist | Video | Mix | Artist) -> None:
|
||||||
self.pb_download.setEnabled(False)
|
# if isinstance(media, Artist):
|
||||||
self.pb_download.setText("Downloading...")
|
# tmp_children: [QtWidgets.QTreeWidgetItem] = []
|
||||||
|
# is_dummy_child = not bool(get_results_media_item(items[0].child(0)))
|
||||||
|
#
|
||||||
|
# # Use the expand function to retrieve all albums.
|
||||||
|
# if is_dummy_child:
|
||||||
|
# self.on_tr_results_expanded(items[0])
|
||||||
|
#
|
||||||
|
# count_children: int = items[0].childCount()
|
||||||
|
#
|
||||||
|
# # Get all children.
|
||||||
|
# for idx in range(count_children):
|
||||||
|
# tmp_children.append(items[0].child(idx))
|
||||||
|
#
|
||||||
|
# items: [Album] = tmp_children
|
||||||
|
|
||||||
items: [QtWidgets.QTreeWidgetItem] = self.tr_results.selectedItems()
|
download_delay: bool = bool(isinstance(media, Track | Video) and self.settings.data.download_delay)
|
||||||
|
|
||||||
if len(items) == 0:
|
|
||||||
logger_gui.error("Please select a row first.")
|
|
||||||
else:
|
|
||||||
# If it is an artist resolve it with all available albums of him
|
|
||||||
if len(items) == 1:
|
|
||||||
tmp_media: Track | Video | Album | Artist = get_results_media_item(items[0])
|
|
||||||
|
|
||||||
if isinstance(tmp_media, Artist):
|
|
||||||
tmp_children: [QtWidgets.QTreeWidgetItem] = []
|
|
||||||
is_dummy_child = not bool(get_results_media_item(items[0].child(0)))
|
|
||||||
|
|
||||||
# Use the expand function to retrieve all albums.
|
|
||||||
if is_dummy_child:
|
|
||||||
self.on_tr_results_expanded(items[0])
|
|
||||||
|
|
||||||
count_children: int = items[0].childCount()
|
|
||||||
|
|
||||||
# Get all children.
|
|
||||||
for idx in range(count_children):
|
|
||||||
tmp_children.append(items[0].child(idx))
|
|
||||||
|
|
||||||
items: [Album] = tmp_children
|
|
||||||
|
|
||||||
items_pos_last = len(items) - 1
|
|
||||||
|
|
||||||
for item in items:
|
|
||||||
media: Track | Album | Playlist | Video | Artist = get_results_media_item(item)
|
|
||||||
# Skip only if Track item, skip option set and the item is not the last in the list.
|
|
||||||
download_delay: bool = bool(
|
|
||||||
isinstance(media, Track | Video)
|
|
||||||
and self.settings.data.download_delay
|
|
||||||
and items.index(item) < items_pos_last
|
|
||||||
)
|
|
||||||
|
|
||||||
self.download(media, self.dl, delay_track=download_delay)
|
self.download(media, self.dl, delay_track=download_delay)
|
||||||
|
|
||||||
self.pb_download.setText("Download")
|
|
||||||
self.pb_download.setEnabled(True)
|
|
||||||
|
|
||||||
def download(
|
def download(
|
||||||
self, media: Track | Album | Playlist | Video | Mix | Artist, dl: Download, delay_track: bool = False
|
self, media: Track | Album | Playlist | Video | Mix | Artist, dl: Download, delay_track: bool = False
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user