mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 09:59:41 +02:00
refactor: update import paths and reorganize utility modules
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
from core.network.aria2_integration import set_threads
|
||||
|
||||
|
||||
def restart_aria2c(aria2process):
|
||||
import main # had to do this because of circle import :(
|
||||
import signal
|
||||
import atexit
|
||||
main.kill_aria2server(aria2process)
|
||||
aria2process.wait()
|
||||
aria2process = main.run_aria2server()
|
||||
signal.signal(signal.SIGINT, main.keyboardinterrupthandler)
|
||||
atexit.unregister(main.kill_aria2server)
|
||||
atexit.register(main.kill_aria2server, aria2process)
|
||||
|
||||
def save_settings(thread_count, close, apiurl, aria2process):
|
||||
global api_url
|
||||
set_threads(thread_count)
|
||||
api_url = apiurl
|
||||
restart_aria2c(aria2process)
|
||||
close()
|
||||
@@ -0,0 +1,11 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
class AppState:
|
||||
debug: bool = False
|
||||
tracker: str = "rutracker"
|
||||
api_url: str = "https://api.michijackson.xyz"
|
||||
|
||||
|
||||
state = AppState()
|
||||
@@ -0,0 +1,40 @@
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from core.network.aria2_wrapper import start_client
|
||||
from core.network.aria2_wrapper import add_magnet
|
||||
|
||||
|
||||
def get_item_index(tracker, 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.
|
||||
if tracker == "uztracker":
|
||||
selected = "https://uztracker.net/" + listlinks[position].lstrip("./")
|
||||
if tracker == "rutracker":
|
||||
selected = listlinks[position]
|
||||
|
||||
if debug:
|
||||
print("Selected URL: ", selected)
|
||||
selected_magnet = get_magnet_link(selected, debug)
|
||||
start_client()
|
||||
add_magnet(selected_magnet)
|
||||
|
||||
|
||||
|
||||
|
||||
def get_magnet_link(post_url, debug):
|
||||
try:
|
||||
response = requests.get(post_url)
|
||||
response.raise_for_status()
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
magnet_link = soup.find('a', href=lambda x: x and x.startswith('magnet:'))
|
||||
if magnet_link:
|
||||
if debug:
|
||||
print("Magnet Link Retrieved: ", magnet_link['href'])
|
||||
return magnet_link['href']
|
||||
else:
|
||||
if debug:
|
||||
print("Magnet Link not Found!")
|
||||
except requests.RequestException as e:
|
||||
if debug:
|
||||
print(f"Failed to fetch {post_url}: {e}")
|
||||
return None
|
||||
Reference in New Issue
Block a user