mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-03 17:39:42 +02:00
f5809c466a
Add network timeouts and more robust error handling across scrapers/hosts, improve logging concurrency, and refine download handling: - Hosts/sources: add request timeouts (15s) and exception handling to buzzheavier, gofile, steamrip, uztracker and rutracker; use urllib.parse.quote for search queries and better parse error checks. - GoFile: use Session with try/finally, create guest account with timeout, validate API responses and close session. - Context menu: import DirectDownloadHandle and handle stopping direct downloads separately from libtorrent; simplify file deletion with single try/catch; improve logging on exceptions. - GUI/search flow: move UI state changes (clear table, disable searchbar, hide empty results) into MainWindow._start_search and reduce duplicated UI changes in run_search. - Main: remove duplicate is_running assignment. - Libtorrent: snapshot seeded magnets in update loop to avoid concurrent access; minor indentation change in add_seed. - State/logging: add _log_lock to AppState; protect state.log_buffer with lock in consoleLog and flush_log_buffer and fix flush semantics. - Updater: replace busy-wait with QEventLoop/QTimer polling for DirectDownloadHandle progress, stop timer and quit loop on completion/error, and remove unnecessary sleeps. These changes aim to make network operations more reliable, prevent UI freezes, avoid race conditions when logging, and handle direct vs libtorrent downloads more cleanly.
66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
from utils.logging.logs import consoleLog
|
|
import requests
|
|
import hashlib
|
|
import time
|
|
import re
|
|
|
|
_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
|
|
_WT_SECRET = "5d4f7g8sd45fsd"
|
|
_API_BASE = "https://api.gofile.io"
|
|
|
|
|
|
def _generate_website_token(account_token):
|
|
time_bucket = str(int(time.time() / 14400))
|
|
raw = f"{_USER_AGENT}::en-US::{account_token}::{time_bucket}::{_WT_SECRET}"
|
|
return hashlib.sha256(raw.encode()).hexdigest()
|
|
|
|
|
|
def scrape_gofile(url):
|
|
match = re.search(r"gofile\.io/d/([a-zA-Z0-9]+)", url)
|
|
if not match:
|
|
consoleLog("GoFile: Invalid URL")
|
|
return None
|
|
|
|
content_id = match.group(1)
|
|
session = requests.Session()
|
|
try:
|
|
# Create a guest account
|
|
r = session.post(f"{_API_BASE}/accounts", headers={"User-Agent": _USER_AGENT}, timeout=15)
|
|
data = r.json()
|
|
if data.get("status") != "ok":
|
|
consoleLog("GoFile: Failed to create guest account")
|
|
return None
|
|
|
|
account_token = data["data"]["token"]
|
|
website_token = _generate_website_token(account_token)
|
|
|
|
headers = {
|
|
"User-Agent": _USER_AGENT,
|
|
"Authorization": f"Bearer {account_token}",
|
|
"X-Website-Token": website_token,
|
|
"X-BL": "en-US",
|
|
"Referer": "https://gofile.io/",
|
|
"Origin": "https://gofile.io",
|
|
}
|
|
|
|
# Fetch folder contents
|
|
r = session.get(f"{_API_BASE}/contents/{content_id}", headers=headers, timeout=15)
|
|
data = r.json()
|
|
if data.get("status") != "ok":
|
|
consoleLog(f"GoFile: API error - {data.get('status')}")
|
|
return None
|
|
|
|
children = data["data"].get("children", {})
|
|
if not children:
|
|
consoleLog("GoFile: No files found")
|
|
return None
|
|
|
|
first_child = next(iter(children.values()))
|
|
link = first_child.get("link")
|
|
if not link:
|
|
consoleLog("GoFile: No download link in response")
|
|
return None
|
|
|
|
return link, headers
|
|
finally:
|
|
session.close() |