summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Honz <exislow+github@gmail.com>2024-04-01 13:09:42 +0200
committerRobert Honz <exislow+github@gmail.com>2024-04-01 13:09:42 +0200
commit0e91d7cea276faa10675b2ea764bf54f22575b15 (patch)
tree74d692f1cb2a19983f49bcfa8a351f33c357f9f3
parent4478b66c2456cb0d67c3bc8f1f0939fc118f39b0 (diff)
downloadtidal-dl-ng-0e91d7cea276faa10675b2ea764bf54f22575b15.tar.gz
✨ Background worker will handle download of queued items.
-rw-r--r--tidal_dl_ng/gui.py38
1 files changed, 36 insertions, 2 deletions
diff --git a/tidal_dl_ng/gui.py b/tidal_dl_ng/gui.py
index cf568ca..4a7d1e6 100644
--- a/tidal_dl_ng/gui.py
+++ b/tidal_dl_ng/gui.py
@@ -1,5 +1,6 @@
import math
import sys
+import time
from collections.abc import Callable
from requests.exceptions import HTTPError
@@ -77,6 +78,9 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
s_pb_reload_status: QtCore.Signal = QtCore.Signal(bool)
s_update_check: QtCore.Signal = QtCore.Signal()
s_update_show: QtCore.Signal = QtCore.Signal(bool, bool, object)
+ s_queue_download_item_downloading: QtCore.Signal = QtCore.Signal(object)
+ s_queue_download_item_finished: QtCore.Signal = QtCore.Signal(object)
+ s_queue_download_item_failed: QtCore.Signal = QtCore.Signal(object)
def __init__(self, tidal: Tidal | None = None):
super().__init__()
@@ -89,8 +93,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
# XStream.stderr().messageWritten.connect(self._log_output)
self.settings = Settings()
- self.threadpool = QtCore.QThreadPool()
+ self._init_threads()
self._init_tree_results(self.tr_results)
self._init_tree_lists(self.tr_lists_user)
self._init_table_queue(self.tr_queue_download)
@@ -142,6 +146,10 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self._init_dl()
self.thread_it(self.tidal_user_lists)
+ def _init_threads(self):
+ self.threadpool = QtCore.QThreadPool()
+ self.thread_it(self.watcher_queue_download)
+
def _init_dl(self):
# Init `Download` object.
data_pb: ProgressBars = ProgressBars(
@@ -547,6 +555,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
# Download Queue
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)
def on_logout(self):
result: bool = self.tidal.logout()
@@ -693,7 +702,32 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
child.setText(4, "<quali>")
self.tr_queue_download.addTopLevelItem(child)
- def on_download_results1(self):
+ def watcher_queue_download(self) -> None:
+ while True:
+ items: [QtWidgets.QTreeWidgetItem | None] = self.tr_queue_download.findItems(
+ QueueDownloadStatus.Waiting.value, QtCore.Qt.MatchFlag.MatchExactly, column=0
+ )
+
+ for item in items:
+ self.s_queue_download_item_downloading.emit(item)
+
+ self.s_queue_download_item_finished.emit(item)
+
+ time.sleep(2)
+
+ def on_queue_download_item_downloading(self, item: QtWidgets.QTreeWidgetItem) -> None:
+ self.queue_download_item_status(item, QueueDownloadStatus.Downloading.value)
+
+ def on_queue_download_item_finished(self, item: QtWidgets.QTreeWidgetItem) -> None:
+ self.queue_download_item_status(item, QueueDownloadStatus.Finished.value)
+
+ def on_queue_download_item_failed(self, item: QtWidgets.QTreeWidgetItem) -> None:
+ self.queue_download_item_status(item, QueueDownloadStatus.Failed.value)
+
+ def queue_download_item_status(self, item: QtWidgets.QTreeWidgetItem, status: str) -> None:
+ item.setText(0, status)
+
+ def on_download_queue(self, media):
self.pb_download.setEnabled(False)
self.pb_download.setText("Downloading...")