mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 09:59:41 +02:00
Refactor GUI to utilize get_item_index for improved item selection and download handling
This commit is contained in:
@@ -1,12 +1,15 @@
|
|||||||
import requests
|
import requests
|
||||||
import asyncio
|
import asyncio
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
from ..downloading.download import start_client
|
||||||
|
from ..downloading.download import add_magnet
|
||||||
|
|
||||||
global url_uztracker
|
global url_uztracker
|
||||||
global up
|
|
||||||
url_uztracker = "https://uztracker.net/tracker.php?nm=" # placeholder url for now
|
url_uztracker = "https://uztracker.net/tracker.php?nm=" # placeholder url for now
|
||||||
|
|
||||||
async def init_uztracker():
|
async def init_uztracker():
|
||||||
|
global up
|
||||||
|
global soup
|
||||||
try:
|
try:
|
||||||
response = requests.get(url_uztracker) # get da content from da url
|
response = requests.get(url_uztracker) # get da content from da url
|
||||||
soup = BeautifulSoup(response.content, 'html.parser') # create bs object
|
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
|
# and - if x exists, THEN check the next part
|
||||||
# x.startswith('magnet:') - does x start with "magnet:"?
|
# 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
@@ -4,9 +4,8 @@ from PySide6.QtWidgets import QLineEdit, QPushButton, QWidget, QVBoxLayout, QLis
|
|||||||
from PySide6.QtGui import QIcon, QAction
|
from PySide6.QtGui import QIcon, QAction
|
||||||
import darkdetect
|
import darkdetect
|
||||||
from core.scraping.uztracker_scraper import scrape_uztracker
|
from core.scraping.uztracker_scraper import scrape_uztracker
|
||||||
from core.scraping.uztracker_scraper import get_magnet_link
|
from core.scraping.uztracker_scraper import get_item_index
|
||||||
from core.downloading.download import start_client
|
|
||||||
from core.downloading.download import add_magnet
|
|
||||||
|
|
||||||
|
|
||||||
def state_debug(setting):
|
def state_debug(setting):
|
||||||
@@ -106,7 +105,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
if item is not None:
|
if item is not None:
|
||||||
if debug:
|
if debug:
|
||||||
print(f"Downloading {self.softwareList.currentItem().text()}")
|
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:
|
else:
|
||||||
if debug:
|
if debug:
|
||||||
print("No item selected for download.")
|
print("No item selected for download.")
|
||||||
@@ -131,13 +130,4 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
print("User searched for:", search_text)
|
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)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user