From addd432229b1d320294944930a79588ffd57e3ae Mon Sep 17 00:00:00 2001 From: Vxrtrauter Date: Thu, 4 Sep 2025 20:36:59 +0200 Subject: [PATCH] Implement debug mode for scraping and GUI interactions --- core/scraping/uztracker_scraper.py | 25 ++++++++++++++++--------- core/ui/gui.py | 29 +++++++++++++++++++++-------- main.py | 4 ++++ 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/core/scraping/uztracker_scraper.py b/core/scraping/uztracker_scraper.py index 44018e6..030c7bf 100644 --- a/core/scraping/uztracker_scraper.py +++ b/core/scraping/uztracker_scraper.py @@ -6,9 +6,10 @@ url_uztracker = "https://uztracker.net/tracker.php?nm=" # placeholder url for no response = requests.get(url_uztracker) # get da content from da url soup = BeautifulSoup(response.content, 'html.parser') # create bs object -def scrape_uztracker(search): +def scrape_uztracker(search, debug): search_url = url_uztracker + search - print(search_url) + if debug: + print(search_url) result = False global results global resulttitles @@ -34,24 +35,28 @@ def scrape_uztracker(search): return resulttitles, results if not result: - print(f'No Results found for "{search}"') + if debug: + print(f'No Results found for "{search}"') + # add popup in gui for no result return except requests.RequestException as e: - print(f"Failed to fetch {search_url}: {e}") + if result: + print(f"Failed to fetch {search_url}: {e}") return None -def get_post_title(post_url): +def get_post_title(post_url, debug): response = requests.get(post_url) soup = BeautifulSoup(response.text, 'html.parser') maintitle = soup.find(class_='tt-text') if maintitle: return maintitle.text else: - print("Program not found") + if debug: + print("Program not found") -def get_magnet_link(post_url): +def get_magnet_link(post_url, debug): try: response = requests.get(post_url) response.raise_for_status() @@ -60,9 +65,11 @@ def get_magnet_link(post_url): if magnet_link: return magnet_link['href'] else: - print("Magnet Link not Found!") + if debug: + print("Magnet Link not Found!") except requests.RequestException as e: - print(f"Failed to fetch {post_url}: {e}") + if debug: + print(f"Failed to fetch {post_url}: {e}") # What x and x.startswith('magnet:') Does # x - check if x exists (not None/empty) diff --git a/core/ui/gui.py b/core/ui/gui.py index a9e4d04..ab7d1f7 100644 --- a/core/ui/gui.py +++ b/core/ui/gui.py @@ -9,6 +9,12 @@ from core.downloading.download import start_client from core.downloading.download import add_magnet +def state_debug(setting): + global debug + if setting is True: + debug = True + else: + debug = False class MainWindow(QtWidgets.QMainWindow, QWidget): def __init__(self): global settings_action @@ -62,15 +68,17 @@ class MainWindow(QtWidgets.QMainWindow, QWidget): toolbar.setMovable(False) def settings_dialog(self): - print("Settings dialog opened") + if debug: + print("Settings dialog opened") dialog = QDialog(self) - dialog.setWindowTitle("test") + dialog.setWindowTitle("Settings") dialog.setFixedSize(400, 300) dialog.setLayout(QVBoxLayout()) label = QLabel("This is a settings dialog.") QtWidgets.QPushButton("Close", clicked=dialog.close) + # close button dialog.layout().addWidget(label) dialog.layout().addWidget(QtWidgets.QPushButton("Close", clicked=dialog.close)) @@ -98,10 +106,13 @@ class MainWindow(QtWidgets.QMainWindow, QWidget): def download_selected(self): item = self.softwareList.currentItem() if item is not None: - print(f"Downloading {self.softwareList.currentItem().text()}") + if debug: + print(f"Downloading {self.softwareList.currentItem().text()}") self.get_item_index(self.softwareList.currentItem().text(), self.postnames, self.postlinks) else: - print("No item selected for download.") + if debug: + print("No item selected for download.") + # add gui notification for no item selected def get_selected_item(self): @@ -114,11 +125,12 @@ class MainWindow(QtWidgets.QMainWindow, QWidget): def return_pressed(self): search_text = self.searchbar.text() - self.postnames, self.postlinks = scrape_uztracker(search_text) + self.postnames, self.postlinks = scrape_uztracker(search_text, debug) self.softwareList.clear() if self.postnames: self.softwareList.addItems(self.postnames) - print("User searched for:", search_text) + if debug: + print("User searched for:", search_text) def get_item_index(self, item, list, listlinks): @@ -126,7 +138,8 @@ class MainWindow(QtWidgets.QMainWindow, QWidget): if 0 <= position < len(listlinks): # note for myself: py starts counting at 0; check if number is not negative, check if number is not more than list length. selected = "https://uztracker.net/" + listlinks[position].lstrip("./") post_url = selected - print(selected) - selected_magnet = get_magnet_link(selected) + if debug: + print("Selected URL: ", selected) + selected_magnet = get_magnet_link(selected, debug) start_client() add_magnet(selected_magnet) diff --git a/main.py b/main.py index 578be10..07de043 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,14 @@ from core.ui.gui import MainWindow +from core.ui.gui import state_debug from PySide6 import QtWidgets import qdarktheme import darkdetect import sys +debug = True + def run_gui(): + state_debug(debug) app = QtWidgets.QApplication([]) if darkdetect.isDark: app.setStyleSheet(qdarktheme.load_stylesheet("dark"))