From 4e7e08c13696b0487fb4da40f71e4d104526e85e Mon Sep 17 00:00:00 2001 From: Vxrtrauter <101264710+Vxrtrauter@users.noreply.github.com> Date: Tue, 10 Mar 2026 22:21:59 +0100 Subject: [PATCH] fix: download path errors, improve print statements, add exception blocks to prevent errors from crashing the program, removed ability to add custom path on add_download as its not used, removed, fixed config format & parsing issues --- src/core/interface/gui.py | 5 ++++- src/core/network/direct_download/handle.py | 4 ++-- src/core/network/libtorrent_int.py | 5 +++-- src/core/network/libtorrent_wrapper.py | 7 ++----- src/core/utils/config/config.py | 21 +++++++++++---------- src/core/utils/config/settings.py | 1 - src/core/utils/data/state.py | 3 +-- src/core/utils/logging/loghandler.py | 1 - src/core/utils/logging/logs.py | 2 -- src/core/utils/network/download.py | 2 +- src/main.py | 2 +- 11 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/core/interface/gui.py b/src/core/interface/gui.py index 06b3c77..5c6df8f 100644 --- a/src/core/interface/gui.py +++ b/src/core/interface/gui.py @@ -1006,7 +1006,10 @@ class MainWindow(QtWidgets.QMainWindow, QWidget): pass del state.active_downloads[magnet_link] remove_download_log(magnet_link) - consoleLog(f"Cancelled download: {magnetdl.status().name}", True) + try: + consoleLog(f"Cancelled download: {magnetdl.status().name}", True) + except RuntimeError: + consoleLog(f"Cancelled download") def deleteFileAction(self): if not hasattr(self, '_context_menu_row'): diff --git a/src/core/network/direct_download/handle.py b/src/core/network/direct_download/handle.py index 22468f1..2d14e92 100644 --- a/src/core/network/direct_download/handle.py +++ b/src/core/network/direct_download/handle.py @@ -213,11 +213,11 @@ class DirectDownloadHandle: self._status.mark_completed() update_download_completed(self.url, True) self._clear_state() - consoleLog(f"✓ Finished downloading {self._name}") + consoleLog(f"Finished downloading {self._name}") except Exception as e: self._status.mark_error(str(e)) - consoleLog(f"✗ Download failed for {self._name}: {e}") + consoleLog(f"Download failed for {self._name}: {e}") finally: if self._session: self._session.close() diff --git a/src/core/network/libtorrent_int.py b/src/core/network/libtorrent_int.py index ba794ef..1af013e 100644 --- a/src/core/network/libtorrent_int.py +++ b/src/core/network/libtorrent_int.py @@ -44,7 +44,7 @@ def init_session(): consoleLog("Initialized Session") -def add_download(magnet_uri, dl_path=state.download_path): +def add_download(magnet_uri): if state.active_downloads is None: state.active_downloads = {} @@ -76,7 +76,8 @@ def add_download(magnet_uri, dl_path=state.download_path): try: magnetdl = lt.parse_magnet_uri(magnet_uri) - magnetdl.save_path = dl_path + magnetdl.save_path = state.download_path + consoleLog(magnetdl.save_path) download = state.dl_session.add_torrent(magnetdl) except Exception as e: consoleLog(f"Failed to add torrent: {e}") diff --git a/src/core/network/libtorrent_wrapper.py b/src/core/network/libtorrent_wrapper.py index c6465df..3720353 100644 --- a/src/core/network/libtorrent_wrapper.py +++ b/src/core/network/libtorrent_wrapper.py @@ -1,12 +1,9 @@ from core.utils.logging.logs import consoleLog from core.network.libtorrent_int import add_download -def add_magnet(uri, dl_path=None): +def add_magnet(uri): if uri is not None and uri.startswith("magnet:?"): - if dl_path: - add_download(uri, dl_path) - else: - add_download(uri) + add_download(uri) consoleLog("Magnet URI added to LibTorrent") else: consoleLog(f"Invalid Magnet Link: {uri}") \ No newline at end of file diff --git a/src/core/utils/config/config.py b/src/core/utils/config/config.py index 59826ec..651c125 100644 --- a/src/core/utils/config/config.py +++ b/src/core/utils/config/config.py @@ -1,7 +1,8 @@ -import os -import platform -import configparser from core.utils.data.state import state +import configparser +import platform +import os + def create_config(): config = configparser.ConfigParser() @@ -15,7 +16,7 @@ def create_config(): config["Network"] = { "api_url": f"{state.api_url}", - "download_path": f"{state.download_path}", + "bound_interface": f"{state.bound_interface}" if state.bound_interface is not None else "None", "download_speed_limit": f"{state.down_speed_limit}", "upload_speed_limit": f"{state.up_speed_limit}", "max_connections": f"{state.max_connections}", @@ -23,7 +24,7 @@ def create_config(): } config["Paths"] = { - "bound_interface": f"{state.bound_interface}" if state.bound_interface is not None else "None", + "download_path": f"{state.download_path}", "image_path": f"{state.image_path}" } @@ -64,16 +65,16 @@ def read_config(): # Network state.api_url = config.get("Network", "api_url", fallback=state.api_url) - state.download_path = config.get("Network", "download_path", fallback=state.download_path) + state.bound_interface = config.get("Network", "bound_interface", fallback=state.bound_interface) + if state.bound_interface == "None": + state.bound_interface = None state.down_speed_limit = config.getint("Network", "download_speed_limit", fallback=state.down_speed_limit) state.up_speed_limit = config.getint("Network", "upload_speed_limit", fallback=state.up_speed_limit) state.max_connections = config.getint("Network", "max_connections", fallback=state.max_connections) state.max_downloads = config.getint("Network", "max_downloads", fallback=state.max_downloads) # Paths - state.bound_interface = config.get("Paths", "bound_interface", fallback=state.bound_interface) - if state.bound_interface == "None": - state.bound_interface = None + state.download_path = config.get("Paths", "download_path", fallback=state.download_path) state.image_path = config.get("Paths", "image_path", fallback=state.image_path) - + create_config() diff --git a/src/core/utils/config/settings.py b/src/core/utils/config/settings.py index 289c25e..f7ab3e7 100644 --- a/src/core/utils/config/settings.py +++ b/src/core/utils/config/settings.py @@ -23,7 +23,6 @@ def save_settings(close=lambda: None, apiurl=None, download_path=None, down_spee state.max_downloads = max_downloads if bound_interface is not None: state.bound_interface = None if bound_interface == "None" else bound_interface - update_settings() consoleLog("Saved Settings") diff --git a/src/core/utils/data/state.py b/src/core/utils/data/state.py index 270a95f..15d98bd 100644 --- a/src/core/utils/data/state.py +++ b/src/core/utils/data/state.py @@ -18,7 +18,7 @@ class AppState(QObject): self.currenttracker: str = "rutracker" self.trackertable: QTableWidget - self.trackers: Dict[str,Dict[str,Any]] = {}# each tracker should add itself here + self.trackers: Dict[str,Dict[str,Any]] = {} # each tracker should add itself here ''' an example: "rutracker" : { @@ -41,7 +41,6 @@ class AppState(QObject): self.interfaces: List = [] self.active_interfaces: List = [] self.bound_interface: Any = None - self.log_buffer: List[str] = [] self.downloads_lock = threading.RLock() self.main_window: Any = None diff --git a/src/core/utils/logging/loghandler.py b/src/core/utils/logging/loghandler.py index a58305a..d1a1055 100644 --- a/src/core/utils/logging/loghandler.py +++ b/src/core/utils/logging/loghandler.py @@ -1,6 +1,5 @@ from core.utils.logging.logs import consoleLog, remove_download_log from core.utils.network.download import run_download_direct, seed_magnet - import os def split_data(data): diff --git a/src/core/utils/logging/logs.py b/src/core/utils/logging/logs.py index f176a1c..deec46a 100644 --- a/src/core/utils/logging/logs.py +++ b/src/core/utils/logging/logs.py @@ -135,9 +135,7 @@ def _update_download_completed_inner(magnet_uri, completed) -> DownloadList: try: stored_magnet = (getattr(download, 'magnet_uri', None) or "").strip() stored_url = (getattr(download, 'url', None) or "").strip() - consoleLog(f"Comparing with magnet: {stored_magnet[:50] if stored_magnet else 'None'}...") if identifier and (stored_magnet == identifier or stored_url == identifier): - consoleLog(f"Match found! Setting completed={completed}") download.completed = completed found = True except Exception as e: diff --git a/src/core/utils/network/download.py b/src/core/utils/network/download.py index 9ea6e96..a4dba30 100644 --- a/src/core/utils/network/download.py +++ b/src/core/utils/network/download.py @@ -43,7 +43,7 @@ def run_download(post): def run_download_direct(magnet_uri, dl_path=None, title="Direct Download"): consoleLog(f"Magnet: {title}") - add_magnet(magnet_uri, dl_path) + add_magnet(magnet_uri) add_download_log(title, "", magnet_uri, False) def seed_magnet(magnet_uri, file_path): diff --git a/src/main.py b/src/main.py index 08ca924..1ec8109 100644 --- a/src/main.py +++ b/src/main.py @@ -63,4 +63,4 @@ def main(): run_gui() if __name__ == "__main__": - main() + main() \ No newline at end of file