mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 17:59:43 +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
|
import requests
|
||||||
from core.utils.state import state
|
from core.utils.data.state import state
|
||||||
|
|
||||||
|
|
||||||
def scrape_rutracker(search_text):
|
def scrape_rutracker(search_text):
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import requests
|
|||||||
import asyncio
|
import asyncio
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from core.utils.state import state
|
from core.utils.data.state import state
|
||||||
|
|
||||||
|
|
||||||
global url_uztracker
|
global url_uztracker
|
||||||
|
|||||||
+19
-26
@@ -22,21 +22,12 @@ import threading
|
|||||||
import asyncio
|
import asyncio
|
||||||
from core.data.scrapers.uztracker import scrape_uztracker
|
from core.data.scrapers.uztracker import scrape_uztracker
|
||||||
from core.data.scrapers.rutracker import scrape_rutracker
|
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.settings import save_settings
|
||||||
from core.utils.state import state
|
from core.utils.data.state import state
|
||||||
from core.network.aria2_integration import dlprogress
|
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):
|
def create_tab(title, searchbar, software_list, tabs):
|
||||||
tab = QWidget()
|
tab = QWidget()
|
||||||
layout = QVBoxLayout()
|
layout = QVBoxLayout()
|
||||||
@@ -48,7 +39,6 @@ def create_tab(title, searchbar, software_list, tabs):
|
|||||||
|
|
||||||
class MainWindow(QtWidgets.QMainWindow, QWidget):
|
class MainWindow(QtWidgets.QMainWindow, QWidget):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
global settings_action
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
searchresults = []
|
searchresults = []
|
||||||
|
|
||||||
@@ -63,7 +53,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
self.searchbar.setPlaceholderText("Search for software...")
|
self.searchbar.setPlaceholderText("Search for software...")
|
||||||
self.searchbar.setClearButtonEnabled(True)
|
self.searchbar.setClearButtonEnabled(True)
|
||||||
self.searchbar.setMinimumHeight(30)
|
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.dlbutton = QtWidgets.QPushButton("Download")
|
||||||
self.softwareList = QListWidget()
|
self.softwareList = QListWidget()
|
||||||
@@ -81,7 +71,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
self.softwareList.addItems(searchresults)
|
self.softwareList.addItems(searchresults)
|
||||||
|
|
||||||
# download button triggers
|
# 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)
|
container.setLayout(containerLayout)
|
||||||
self.setCentralWidget(container)
|
self.setCentralWidget(container)
|
||||||
@@ -209,16 +199,17 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
|
|
||||||
dialog.exec()
|
dialog.exec()
|
||||||
|
|
||||||
def download_selected(self):
|
# def download_selected(self):
|
||||||
item = self.softwareList.currentItem()
|
# item = self.softwareList.currentItem()
|
||||||
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=(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.")
|
||||||
# add gui notification for no item selected
|
# # add gui notification for no item selected
|
||||||
|
|
||||||
|
|
||||||
# this needs a cleanup
|
# this needs a cleanup
|
||||||
def return_pressed(self):
|
def return_pressed(self):
|
||||||
@@ -234,10 +225,13 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
if state.tracker == "rutracker":
|
if state.tracker == "rutracker":
|
||||||
response = asyncio.run(scrape_rutracker(search_text))
|
response = asyncio.run(scrape_rutracker(search_text))
|
||||||
if response:
|
if response:
|
||||||
|
if state.tracker == "uztracker":
|
||||||
self.postnames, self.postlinks = response
|
self.postnames, self.postlinks = response
|
||||||
self.softwareList.clear()
|
self.softwareList.clear()
|
||||||
if self.postnames:
|
if self.postnames:
|
||||||
self.softwareList.addItems(self.postnames)
|
self.softwareList.addItems(self.postnames)
|
||||||
|
if state.tracker == "rutracker":
|
||||||
|
pass
|
||||||
if not response:
|
if not response:
|
||||||
print(f"No Results found for \"{search_text}\"")
|
print(f"No Results found for \"{search_text}\"")
|
||||||
self.softwareList.clear()
|
self.softwareList.clear()
|
||||||
@@ -248,5 +242,4 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
progress = dlprogress()
|
progress = dlprogress()
|
||||||
self.progressbar.setValue(progress)
|
self.progressbar.setValue(progress)
|
||||||
|
|
||||||
def run_thread(self, thread):
|
|
||||||
thread.start()
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import aria2p
|
import aria2p
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
from core.utils.state import state
|
from core.utils.data.state import state
|
||||||
|
|
||||||
def run_aria2p():
|
def run_aria2p():
|
||||||
global aria2
|
global aria2
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ 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
|
from core.utils.data.state import state
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -40,3 +40,4 @@ def get_magnet_link(post_url, debug):
|
|||||||
if debug:
|
if debug:
|
||||||
print(f"Failed to fetch {post_url}: {e}")
|
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():
|
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 MainWindow
|
||||||
from core.interface.gui import state_debug
|
from core.utils.data.state import state
|
||||||
from core.utils.state import state
|
|
||||||
from core.network.aria2_integration import aria2server
|
from core.network.aria2_integration import aria2server
|
||||||
from PySide6 import QtWidgets
|
from PySide6 import QtWidgets
|
||||||
import qdarktheme
|
import qdarktheme
|
||||||
@@ -9,10 +8,10 @@ import signal
|
|||||||
import atexit
|
import atexit
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
debug = True
|
# Debug Output
|
||||||
|
state.debug = True
|
||||||
|
|
||||||
def run_gui():
|
def run_gui():
|
||||||
state_debug(debug)
|
|
||||||
app = QtWidgets.QApplication([])
|
app = QtWidgets.QApplication([])
|
||||||
if darkdetect.isDark:
|
if darkdetect.isDark:
|
||||||
app.setStyleSheet(qdarktheme.load_stylesheet("dark"))
|
app.setStyleSheet(qdarktheme.load_stylesheet("dark"))
|
||||||
@@ -31,7 +30,7 @@ def run_aria2server():
|
|||||||
def kill_aria2server():
|
def kill_aria2server():
|
||||||
if state.aria2process:
|
if state.aria2process:
|
||||||
state.aria2process.kill()
|
state.aria2process.kill()
|
||||||
if debug:
|
if state.debug:
|
||||||
print("\nKilled Aria2")
|
print("\nKilled Aria2")
|
||||||
|
|
||||||
|
|
||||||
@@ -41,12 +40,12 @@ def keyboardinterrupthandler(signum, frame):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if debug:
|
if state.debug:
|
||||||
print("Starting Aria2 Server")
|
print("Starting Aria2 Server")
|
||||||
state.aria2process = run_aria2server()
|
state.aria2process = run_aria2server()
|
||||||
signal.signal(signal.SIGINT, keyboardinterrupthandler)
|
signal.signal(signal.SIGINT, keyboardinterrupthandler)
|
||||||
atexit.register(kill_aria2server)
|
atexit.register(kill_aria2server)
|
||||||
if debug:
|
if state.debug:
|
||||||
print("Launching GUI")
|
print("Launching GUI")
|
||||||
run_gui()
|
run_gui()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user