Refactor GUI to utilize get_item_index for improved item selection and download handling

This commit is contained in:
Vxrtrauter
2025-09-06 01:00:12 +02:00
parent 87380f57af
commit 01303234d6
2 changed files with 20 additions and 15 deletions
+16 -1
View File
@@ -1,12 +1,15 @@
import requests
import asyncio
from bs4 import BeautifulSoup
from ..downloading.download import start_client
from ..downloading.download import add_magnet
global url_uztracker
global up
url_uztracker = "https://uztracker.net/tracker.php?nm=" # placeholder url for now
async def init_uztracker():
global up
global soup
try:
response = requests.get(url_uztracker) # get da content from da url
soup = BeautifulSoup(response.content, 'html.parser') # create bs object
@@ -103,3 +106,15 @@ def get_magnet_link(post_url, debug):
# and - if x exists, THEN check the next part
# x.startswith('magnet:') - does x start with "magnet:"?
def get_item_index(item, list, listlinks, debug):
position = list.index(item)
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
if debug:
print("Selected URL: ", selected)
selected_magnet = get_magnet_link(selected, debug)
start_client()
add_magnet(selected_magnet)
+4 -14
View File
@@ -4,9 +4,8 @@ from PySide6.QtWidgets import QLineEdit, QPushButton, QWidget, QVBoxLayout, QLis
from PySide6.QtGui import QIcon, QAction
import darkdetect
from core.scraping.uztracker_scraper import scrape_uztracker
from core.scraping.uztracker_scraper import get_magnet_link
from core.downloading.download import start_client
from core.downloading.download import add_magnet
from core.scraping.uztracker_scraper import get_item_index
def state_debug(setting):
@@ -106,7 +105,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
if item is not None:
if debug:
print(f"Downloading {self.softwareList.currentItem().text()}")
self.get_item_index(self.softwareList.currentItem().text(), self.postnames, self.postlinks)
get_item_index(self.softwareList.currentItem().text(), self.postnames, self.postlinks, debug)
else:
if debug:
print("No item selected for download.")
@@ -131,13 +130,4 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
print("User searched for:", search_text)
def get_item_index(self, item, list, listlinks):
position = list.index(item)
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
if debug:
print("Selected URL: ", selected)
selected_magnet = get_magnet_link(selected, debug)
start_client()
add_magnet(selected_magnet)