mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 09:59:41 +02:00
refactor: replace global tracker usage with state management in GUI and tracker utilities
This commit is contained in:
+6
-10
@@ -41,11 +41,8 @@ def pass_aria(aria):
|
|||||||
global aria2process
|
global aria2process
|
||||||
aria2process = aria
|
aria2process = aria
|
||||||
|
|
||||||
global tracker
|
|
||||||
tracker = "rutracker" # default tracker
|
|
||||||
|
|
||||||
global api_url
|
|
||||||
api_url = "https://api.michijackson.xyz"
|
|
||||||
|
|
||||||
def create_tab(title, searchbar, software_list, tabs):
|
def create_tab(title, searchbar, software_list, tabs):
|
||||||
tab = QWidget()
|
tab = QWidget()
|
||||||
@@ -143,8 +140,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
self.progress_timer.start(1000)
|
self.progress_timer.start(1000)
|
||||||
|
|
||||||
def set_tracker(self, _):
|
def set_tracker(self, _):
|
||||||
global tracker
|
state.tracker = self.tracker_list.currentText()
|
||||||
tracker = self.tracker_list.currentText()
|
|
||||||
|
|
||||||
def settings_dialog(self):
|
def settings_dialog(self):
|
||||||
|
|
||||||
@@ -197,7 +193,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
api_url_layout.addWidget(text_edit)
|
api_url_layout.addWidget(text_edit)
|
||||||
api_url_container.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
|
api_url_container.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
|
||||||
api_url_container.setLayout(api_url_layout)
|
api_url_container.setLayout(api_url_layout)
|
||||||
text_edit.setText(api_url)
|
text_edit.setText(state.api_url)
|
||||||
dialog.layout().addWidget(api_url_container)
|
dialog.layout().addWidget(api_url_container)
|
||||||
|
|
||||||
# dialog.layout().addWidget(QtWidgets.QPushButton("Close", clicked=dialog.close))
|
# dialog.layout().addWidget(QtWidgets.QPushButton("Close", clicked=dialog.close))
|
||||||
@@ -225,7 +221,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
if item is not None:
|
if item is not None:
|
||||||
if state.debug:
|
if state.debug:
|
||||||
print(f"network {self.softwareList.currentItem().text()}")
|
print(f"network {self.softwareList.currentItem().text()}")
|
||||||
self.run_thread(threading.Thread(target=get_item_index, args=(tracker, self.softwareList.currentItem().text(), self.postnames, self.postlinks, state.debug)))
|
self.run_thread(threading.Thread(target=get_item_index, args=(self.softwareList.currentItem().text(), self.postnames, self.postlinks, state.debug)))
|
||||||
else:
|
else:
|
||||||
if state.debug:
|
if state.debug:
|
||||||
print("No item selected for download.")
|
print("No item selected for download.")
|
||||||
@@ -240,9 +236,9 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
return
|
return
|
||||||
if state.debug:
|
if state.debug:
|
||||||
print("User searched for:", search_text)
|
print("User searched for:", search_text)
|
||||||
if tracker == "uztracker":
|
if state.tracker == "uztracker":
|
||||||
response = asyncio.run(scrape_uztracker(search_text))
|
response = asyncio.run(scrape_uztracker(search_text))
|
||||||
if tracker == "rutracker":
|
if state.tracker == "rutracker":
|
||||||
response = asyncio.run(scrape_rutracker(search_text))
|
response = asyncio.run(scrape_rutracker(search_text))
|
||||||
if response:
|
if response:
|
||||||
self.postnames, self.postlinks = response
|
self.postnames, self.postlinks = response
|
||||||
|
|||||||
@@ -2,14 +2,16 @@ import requests
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from core.network.aria2_wrapper import start_client
|
from core.network.aria2_wrapper import start_client
|
||||||
from core.network.aria2_wrapper import add_magnet
|
from core.network.aria2_wrapper import add_magnet
|
||||||
|
from core.utils.state import state
|
||||||
|
|
||||||
|
|
||||||
def get_item_index(tracker, item, list, listlinks, debug):
|
|
||||||
|
def get_item_index(item, list, listlinks, debug):
|
||||||
position = list.index(item)
|
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.
|
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.
|
||||||
if tracker == "uztracker":
|
if state.tracker == "uztracker":
|
||||||
selected = "https://uztracker.net/" + listlinks[position].lstrip("./")
|
selected = "https://uztracker.net/" + listlinks[position].lstrip("./")
|
||||||
if tracker == "rutracker":
|
if state.tracker == "rutracker":
|
||||||
selected = listlinks[position]
|
selected = listlinks[position]
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
|
|||||||
Reference in New Issue
Block a user