mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-03 17:39:42 +02:00
INCOMPLETE, DONT PUSH:
refactor: reorganize state management and update import paths across modules and start changing json parsing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import requests
|
||||
from core.utils.state import state
|
||||
from core.utils.data.state import state
|
||||
|
||||
|
||||
def scrape_rutracker(search_text):
|
||||
|
||||
@@ -2,7 +2,7 @@ import requests
|
||||
import asyncio
|
||||
import aiohttp
|
||||
from bs4 import BeautifulSoup
|
||||
from core.utils.state import state
|
||||
from core.utils.data.state import state
|
||||
|
||||
|
||||
global url_uztracker
|
||||
|
||||
+23
-30
@@ -22,21 +22,12 @@ import threading
|
||||
import asyncio
|
||||
from core.data.scrapers.uztracker import scrape_uztracker
|
||||
from core.data.scrapers.rutracker import scrape_rutracker
|
||||
from core.utils.tracker import get_item_index
|
||||
from core.utils.wrappers import run_thread
|
||||
from core.utils.settings import save_settings
|
||||
from core.utils.state import state
|
||||
from core.utils.data.state import state
|
||||
from core.network.aria2_integration import dlprogress
|
||||
|
||||
|
||||
|
||||
|
||||
def state_debug(setting):
|
||||
if setting is True:
|
||||
state.debug = True
|
||||
else:
|
||||
state.debug = False
|
||||
|
||||
|
||||
def create_tab(title, searchbar, software_list, tabs):
|
||||
tab = QWidget()
|
||||
layout = QVBoxLayout()
|
||||
@@ -48,7 +39,6 @@ def create_tab(title, searchbar, software_list, tabs):
|
||||
|
||||
class MainWindow(QtWidgets.QMainWindow, QWidget):
|
||||
def __init__(self):
|
||||
global settings_action
|
||||
super().__init__()
|
||||
searchresults = []
|
||||
|
||||
@@ -63,7 +53,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
||||
self.searchbar.setPlaceholderText("Search for software...")
|
||||
self.searchbar.setClearButtonEnabled(True)
|
||||
self.searchbar.setMinimumHeight(30)
|
||||
self.searchbar.returnPressed.connect(lambda: self.run_thread(threading.Thread(target=self.return_pressed))) # Triggers data function thread on enter
|
||||
self.searchbar.returnPressed.connect(lambda: run_thread(threading.Thread(target=self.return_pressed))) # Triggers data function thread on enter
|
||||
|
||||
self.dlbutton = QtWidgets.QPushButton("Download")
|
||||
self.softwareList = QListWidget()
|
||||
@@ -81,7 +71,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
||||
self.softwareList.addItems(searchresults)
|
||||
|
||||
# download button triggers
|
||||
self.dlbutton.clicked.connect(lambda: self.run_thread(threading.Thread(target=self.download_selected)))
|
||||
self.dlbutton.clicked.connect(lambda: run_thread(threading.Thread(target=self.download_selected)))
|
||||
|
||||
container.setLayout(containerLayout)
|
||||
self.setCentralWidget(container)
|
||||
@@ -209,16 +199,17 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
||||
|
||||
dialog.exec()
|
||||
|
||||
def download_selected(self):
|
||||
item = self.softwareList.currentItem()
|
||||
if item is not None:
|
||||
if state.debug:
|
||||
print(f"network {self.softwareList.currentItem().text()}")
|
||||
self.run_thread(threading.Thread(target=get_item_index, args=(self.softwareList.currentItem().text(), self.postnames, self.postlinks, state.debug)))
|
||||
else:
|
||||
if state.debug:
|
||||
print("No item selected for download.")
|
||||
# add gui notification for no item selected
|
||||
# def download_selected(self):
|
||||
# item = self.softwareList.currentItem()
|
||||
# if item is not None:
|
||||
# if state.debug:
|
||||
# print(f"network {self.softwareList.currentItem().text()}")
|
||||
# self.run_thread(threading.Thread(target=get_item_index, args=(self.softwareList.currentItem().text(), self.postnames, self.postlinks, state.debug)))
|
||||
# else:
|
||||
# if state.debug:
|
||||
# print("No item selected for download.")
|
||||
# # add gui notification for no item selected
|
||||
|
||||
|
||||
# this needs a cleanup
|
||||
def return_pressed(self):
|
||||
@@ -234,10 +225,13 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
||||
if state.tracker == "rutracker":
|
||||
response = asyncio.run(scrape_rutracker(search_text))
|
||||
if response:
|
||||
self.postnames, self.postlinks = response
|
||||
self.softwareList.clear()
|
||||
if self.postnames:
|
||||
self.softwareList.addItems(self.postnames)
|
||||
if state.tracker == "uztracker":
|
||||
self.postnames, self.postlinks = response
|
||||
self.softwareList.clear()
|
||||
if self.postnames:
|
||||
self.softwareList.addItems(self.postnames)
|
||||
if state.tracker == "rutracker":
|
||||
pass
|
||||
if not response:
|
||||
print(f"No Results found for \"{search_text}\"")
|
||||
self.softwareList.clear()
|
||||
@@ -248,5 +242,4 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
||||
progress = dlprogress()
|
||||
self.progressbar.setValue(progress)
|
||||
|
||||
def run_thread(self, thread):
|
||||
thread.start()
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import aria2p
|
||||
import os
|
||||
import subprocess
|
||||
from core.utils.state import state
|
||||
from core.utils.data.state import state
|
||||
|
||||
def run_aria2p():
|
||||
global aria2
|
||||
|
||||
@@ -2,7 +2,7 @@ import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from core.network.aria2_wrapper import start_client
|
||||
from core.network.aria2_wrapper import add_magnet
|
||||
from core.utils.state import state
|
||||
from core.utils.data.state import state
|
||||
|
||||
|
||||
|
||||
@@ -39,4 +39,5 @@ def get_magnet_link(post_url, debug):
|
||||
except requests.RequestException as e:
|
||||
if debug:
|
||||
print(f"Failed to fetch {post_url}: {e}")
|
||||
return None
|
||||
return None
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
from core.utils.data.state import state
|
||||
from core.utils.data.tracker import get_item_index
|
||||
from core.utils.wrappers import run_thread
|
||||
import threading
|
||||
|
||||
|
||||
def download_selected(item, ):
|
||||
if item is not None:
|
||||
if state.debug:
|
||||
print(f"network {item.text()}")
|
||||
run_thread(threading.Thread(target=get_item_index, args=(item.text(), self.postnames, self.postlinks, state.debug)))
|
||||
else:
|
||||
if state.debug:
|
||||
print("No item selected for download.")
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
def split_data(data):
|
||||
json = json.loads(data)
|
||||
|
||||
count = json["count"]
|
||||
posts = json["data"]
|
||||
query = json["query"]
|
||||
success = json["success"]
|
||||
|
||||
return count, posts, query, success
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from core.utils.state import state
|
||||
from core.utils.data.state import state
|
||||
|
||||
|
||||
def restart_aria2c():
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
def run_thread(thread):
|
||||
thread.start()
|
||||
@@ -1,6 +1,5 @@
|
||||
from core.interface.gui import MainWindow
|
||||
from core.interface.gui import state_debug
|
||||
from core.utils.state import state
|
||||
from core.utils.data.state import state
|
||||
from core.network.aria2_integration import aria2server
|
||||
from PySide6 import QtWidgets
|
||||
import qdarktheme
|
||||
@@ -9,10 +8,10 @@ import signal
|
||||
import atexit
|
||||
import sys
|
||||
|
||||
debug = True
|
||||
# Debug Output
|
||||
state.debug = True
|
||||
|
||||
def run_gui():
|
||||
state_debug(debug)
|
||||
app = QtWidgets.QApplication([])
|
||||
if darkdetect.isDark:
|
||||
app.setStyleSheet(qdarktheme.load_stylesheet("dark"))
|
||||
@@ -31,7 +30,7 @@ def run_aria2server():
|
||||
def kill_aria2server():
|
||||
if state.aria2process:
|
||||
state.aria2process.kill()
|
||||
if debug:
|
||||
if state.debug:
|
||||
print("\nKilled Aria2")
|
||||
|
||||
|
||||
@@ -41,12 +40,12 @@ def keyboardinterrupthandler(signum, frame):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if debug:
|
||||
if state.debug:
|
||||
print("Starting Aria2 Server")
|
||||
state.aria2process = run_aria2server()
|
||||
signal.signal(signal.SIGINT, keyboardinterrupthandler)
|
||||
atexit.register(kill_aria2server)
|
||||
if debug:
|
||||
if state.debug:
|
||||
print("Launching GUI")
|
||||
run_gui()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user