mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 02:24:16 +02:00
[improvement][settings] only displaying available multi-threaded download clients
This commit is contained in:
@@ -5,7 +5,7 @@ import time
|
||||
import traceback
|
||||
from math import floor
|
||||
from threading import Thread
|
||||
from typing import Iterable
|
||||
from typing import Iterable, List
|
||||
|
||||
from bauh.api.abstract.download import FileDownloader
|
||||
from bauh.api.abstract.handler import ProcessWatcher
|
||||
@@ -24,7 +24,7 @@ class AdaptableFileDownloader(FileDownloader):
|
||||
self.multithread_enabled = multithread_enabled
|
||||
self.i18n = i18n
|
||||
self.http_client = http_client
|
||||
self.supported_multithread_clients = {'aria2', 'axel'}
|
||||
self.supported_multithread_clients = ['aria2', 'axel']
|
||||
self.multithread_client = multithread_client
|
||||
|
||||
@staticmethod
|
||||
@@ -184,22 +184,39 @@ class AdaptableFileDownloader(FileDownloader):
|
||||
return success
|
||||
|
||||
def is_multithreaded(self) -> bool:
|
||||
return self.multithread_enabled and (self.is_aria2c_available() or self.is_axel_available())
|
||||
return bool(self.get_available_multithreaded_tool())
|
||||
|
||||
def get_available_multithreaded_tool(self) -> str:
|
||||
if self.multithread_enabled:
|
||||
if self.multithread_client is None:
|
||||
if self.is_aria2c_available():
|
||||
return 'aria2'
|
||||
elif self.is_axel_available():
|
||||
return 'axel'
|
||||
elif (self.multithread_client == 'aria2' or self.multithread_client not in self.get_supported_multithreaded_clients()) and self.is_aria2c_available():
|
||||
return 'aria2'
|
||||
elif self.is_axel_available():
|
||||
return 'axel'
|
||||
if self.multithread_client is None or self.multithread_client not in self.supported_multithread_clients:
|
||||
for client in self.supported_multithread_clients:
|
||||
if self.is_multithreaded_client_available(client):
|
||||
return client
|
||||
else:
|
||||
possible_clients = {*self.supported_multithread_clients}
|
||||
|
||||
if self.is_multithreaded_client_available(self.multithread_client):
|
||||
return self.multithread_client
|
||||
else:
|
||||
possible_clients.remove(self.multithread_client)
|
||||
|
||||
for client in possible_clients:
|
||||
if self.is_multithreaded_client_available(client):
|
||||
return client
|
||||
|
||||
def can_work(self) -> bool:
|
||||
return self.is_wget_available() or self.is_multithreaded()
|
||||
|
||||
def get_supported_multithreaded_clients(self) -> Iterable[str]:
|
||||
return self.supported_multithread_clients
|
||||
|
||||
def is_multithreaded_client_available(self, name: str) -> bool:
|
||||
if name == 'aria2':
|
||||
return self.is_aria2c_available()
|
||||
elif name == 'axel':
|
||||
return self.is_axel_available()
|
||||
else:
|
||||
return False
|
||||
|
||||
def list_available_multithreaded_clients(self) -> List[str]:
|
||||
return [c for c in self.supported_multithread_clients if self.is_multithreaded_client_available(c)]
|
||||
|
||||
@@ -121,24 +121,33 @@ class GenericSettingsManager:
|
||||
max_width=default_width,
|
||||
value=core_config['download']['multithreaded'])
|
||||
|
||||
supported_mthread_clients = self.file_downloader.get_supported_multithreaded_clients()
|
||||
mthread_client_opts = [(self.i18n['default'].capitalize(), None, None)]
|
||||
mthread_client_opts.extend(((d, d, None) for d in supported_mthread_clients))
|
||||
current_mthread_client = core_config['download']['multithreaded_client']
|
||||
|
||||
if current_mthread_client not in supported_mthread_clients:
|
||||
current_mthread_client = None
|
||||
|
||||
select_mthread_client = self._gen_select(label=self.i18n['core.config.download.multithreaded_client'],
|
||||
tip=self.i18n['core.config.download.multithreaded_client.tip'],
|
||||
id_="mthread_client",
|
||||
max_width=default_width,
|
||||
opts=mthread_client_opts,
|
||||
value=current_mthread_client)
|
||||
select_mthread_client = self._gen_multithread_client_select(core_config, default_width)
|
||||
|
||||
sub_comps = [FormComponent([select_dmthread, select_mthread_client, select_trim_up, select_dep_check, input_data_exp, input_icon_exp], spaces=False)]
|
||||
return TabComponent(self.i18n['core.config.tab.advanced'].capitalize(), PanelComponent(sub_comps), None, 'core.adv')
|
||||
|
||||
def _gen_multithread_client_select(self, core_config: dict, default_width: int) -> SingleSelectComponent:
|
||||
available_mthread_clients = self.file_downloader.list_available_multithreaded_clients()
|
||||
available_mthread_clients.sort()
|
||||
|
||||
default_i18n_key = 'default' if available_mthread_clients else 'core.config.download.multithreaded_client.none'
|
||||
mthread_client_opts = [(self.i18n[default_i18n_key].capitalize(), None, None)]
|
||||
|
||||
for client in available_mthread_clients:
|
||||
mthread_client_opts.append((client, client, None))
|
||||
|
||||
current_mthread_client = core_config['download']['multithreaded_client']
|
||||
|
||||
if current_mthread_client not in available_mthread_clients:
|
||||
current_mthread_client = None
|
||||
|
||||
return self._gen_select(label=self.i18n['core.config.download.multithreaded_client'],
|
||||
tip=self.i18n['core.config.download.multithreaded_client.tip'],
|
||||
id_="mthread_client",
|
||||
max_width=default_width,
|
||||
opts=mthread_client_opts,
|
||||
value=current_mthread_client)
|
||||
|
||||
def _gen_tray_settings(self, core_config: dict, screen_width: int, screen_height: int) -> TabComponent:
|
||||
default_width = floor(0.22 * screen_width)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user