✨ Multithreaded downloads implemented (for Playlists, Albums etc.). Fixes #180
This commit is contained in:
@@ -162,7 +162,7 @@ class DialogPreferences(QtWidgets.QDialog):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def _init_spin_box(self):
|
def _init_spin_box(self):
|
||||||
self.parameters_spin_box = ["album_track_num_pad_min"]
|
self.parameters_spin_box = ["album_track_num_pad_min", "downloads_concurrent_max"]
|
||||||
|
|
||||||
def _init_comboboxes(self):
|
def _init_comboboxes(self):
|
||||||
self.parameters_combo = [
|
self.parameters_combo = [
|
||||||
|
|||||||
+11
-3
@@ -621,9 +621,11 @@ class Download:
|
|||||||
|
|
||||||
# Iterate through list items
|
# Iterate through list items
|
||||||
while not self.progress.finished:
|
while not self.progress.finished:
|
||||||
for item_media in items:
|
with futures.ThreadPoolExecutor(max_workers=self.settings.data.downloads_concurrent_max) as executor:
|
||||||
# Download the item.
|
# Dispatch all download tasks to worker threads
|
||||||
status, result_path_file = self.item(
|
l_futures: [any] = [
|
||||||
|
executor.submit(
|
||||||
|
self.item,
|
||||||
media=item_media,
|
media=item_media,
|
||||||
file_template=file_name_relative,
|
file_template=file_name_relative,
|
||||||
quality_audio=quality_audio,
|
quality_audio=quality_audio,
|
||||||
@@ -631,6 +633,12 @@ class Download:
|
|||||||
download_delay=download_delay,
|
download_delay=download_delay,
|
||||||
is_parent_album=is_album,
|
is_parent_album=is_album,
|
||||||
)
|
)
|
||||||
|
for item_media in items
|
||||||
|
]
|
||||||
|
# Report results as they become available
|
||||||
|
for future in futures.as_completed(l_futures):
|
||||||
|
# Retrieve result
|
||||||
|
status, result_path_file = future.result()
|
||||||
|
|
||||||
# Advance progress bar.
|
# Advance progress bar.
|
||||||
self.progress.advance(p_task1)
|
self.progress.advance(p_task1)
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ class Settings:
|
|||||||
downloads_simultaneous_per_track_max: int = 20
|
downloads_simultaneous_per_track_max: int = 20
|
||||||
download_delay_sec_min: float = 3.0
|
download_delay_sec_min: float = 3.0
|
||||||
download_delay_sec_max: float = 5.0
|
download_delay_sec_max: float = 5.0
|
||||||
album_track_num_pad_min: int = 0
|
album_track_num_pad_min: int = 1
|
||||||
|
downloads_concurrent_max: int = 3
|
||||||
|
|
||||||
|
|
||||||
@dataclass_json
|
@dataclass_json
|
||||||
@@ -86,8 +87,9 @@ class HelpSettings:
|
|||||||
download_delay_sec_min: str = "Lower boundary for the calculation of the download delay in seconds."
|
download_delay_sec_min: str = "Lower boundary for the calculation of the download delay in seconds."
|
||||||
download_delay_sec_max: str = "Upper boundary for the calculation of the download delay in seconds."
|
download_delay_sec_max: str = "Upper boundary for the calculation of the download delay in seconds."
|
||||||
album_track_num_pad_min: str = (
|
album_track_num_pad_min: str = (
|
||||||
"Minimum length of the album track count, will be padded with zeroes (0). To disable " "padding set this to 0."
|
"Minimum length of the album track count, will be padded with zeroes (0). To disable padding set this to 1."
|
||||||
)
|
)
|
||||||
|
downloads_concurrent_max: str = "Maximum concurrent number of downloads (threads)."
|
||||||
|
|
||||||
|
|
||||||
@dataclass_json
|
@dataclass_json
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class Ui_DialogSettings:
|
|||||||
def setupUi(self, DialogSettings):
|
def setupUi(self, DialogSettings):
|
||||||
if not DialogSettings.objectName():
|
if not DialogSettings.objectName():
|
||||||
DialogSettings.setObjectName("DialogSettings")
|
DialogSettings.setObjectName("DialogSettings")
|
||||||
DialogSettings.resize(640, 705)
|
DialogSettings.resize(640, 767)
|
||||||
sizePolicy = QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
sizePolicy = QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
||||||
sizePolicy.setHorizontalStretch(100)
|
sizePolicy.setHorizontalStretch(100)
|
||||||
sizePolicy.setVerticalStretch(100)
|
sizePolicy.setVerticalStretch(100)
|
||||||
@@ -293,6 +293,27 @@ class Ui_DialogSettings:
|
|||||||
|
|
||||||
self.verticalLayout_8.addLayout(self.horizontalLayout_9)
|
self.verticalLayout_8.addLayout(self.horizontalLayout_9)
|
||||||
|
|
||||||
|
self.horizontalLayout_11 = QHBoxLayout()
|
||||||
|
self.horizontalLayout_11.setObjectName("horizontalLayout_11")
|
||||||
|
self.l_downloads_concurrent_max = QLabel(self.gb_numbers)
|
||||||
|
self.l_downloads_concurrent_max.setObjectName("l_downloads_concurrent_max")
|
||||||
|
|
||||||
|
self.horizontalLayout_11.addWidget(self.l_downloads_concurrent_max)
|
||||||
|
|
||||||
|
self.l_icon_downloads_concurrent_max = QLabel(self.gb_numbers)
|
||||||
|
self.l_icon_downloads_concurrent_max.setObjectName("l_icon_downloads_concurrent_max")
|
||||||
|
|
||||||
|
self.horizontalLayout_11.addWidget(self.l_icon_downloads_concurrent_max)
|
||||||
|
|
||||||
|
self.sb_downloads_concurrent_max = QSpinBox(self.gb_numbers)
|
||||||
|
self.sb_downloads_concurrent_max.setObjectName("sb_downloads_concurrent_max")
|
||||||
|
self.sb_downloads_concurrent_max.setMinimum(1)
|
||||||
|
self.sb_downloads_concurrent_max.setMaximum(5)
|
||||||
|
|
||||||
|
self.horizontalLayout_11.addWidget(self.sb_downloads_concurrent_max)
|
||||||
|
|
||||||
|
self.verticalLayout_8.addLayout(self.horizontalLayout_11)
|
||||||
|
|
||||||
self.lv_main.addWidget(self.gb_numbers)
|
self.lv_main.addWidget(self.gb_numbers)
|
||||||
|
|
||||||
self.gb_path = QGroupBox(DialogSettings)
|
self.gb_path = QGroupBox(DialogSettings)
|
||||||
@@ -563,6 +584,8 @@ class Ui_DialogSettings:
|
|||||||
self.gb_numbers.setTitle(QCoreApplication.translate("DialogSettings", "Numbers", None))
|
self.gb_numbers.setTitle(QCoreApplication.translate("DialogSettings", "Numbers", None))
|
||||||
self.l_album_track_num_pad_min.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
self.l_album_track_num_pad_min.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
||||||
self.l_icon_album_track_num_pad_min.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
self.l_icon_album_track_num_pad_min.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
||||||
|
self.l_downloads_concurrent_max.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
||||||
|
self.l_icon_downloads_concurrent_max.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
||||||
self.gb_path.setTitle(QCoreApplication.translate("DialogSettings", "Path", None))
|
self.gb_path.setTitle(QCoreApplication.translate("DialogSettings", "Path", None))
|
||||||
self.l_icon_download_base_path.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
self.l_icon_download_base_path.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
||||||
self.l_download_base_path.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
self.l_download_base_path.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>640</width>
|
<width>640</width>
|
||||||
<height>705</height>
|
<height>767</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@@ -386,6 +386,34 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_11">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="l_downloads_concurrent_max">
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="l_icon_downloads_concurrent_max">
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="sb_downloads_concurrent_max">
|
||||||
|
<property name="minimum">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>5</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user