mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-03 17:39:42 +02:00
Merge branch 'fix/gofile' into main
This commit is contained in:
@@ -8,24 +8,33 @@ def scrape_gofile(url):
|
|||||||
filetoken = re.findall(r"(?<=https...gofile.io\/d\/).*", url)[0]
|
filetoken = re.findall(r"(?<=https...gofile.io\/d\/).*", url)[0]
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
|
|
||||||
acc = session.post("https://api.gofile.io/accounts")
|
|
||||||
token = acc.json()["data"]["token"]
|
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {token}",
|
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:148.0) Gecko/20100101 Firefox/148.0",
|
||||||
"X-Website-Token": "4fd6sg89d7s6", # Maybe make this dynamic in the future
|
"Accept": "*/*",
|
||||||
|
"Accept-Language": "en-US,en;q=0.9",
|
||||||
|
"Accept-Encoding": "gzip, deflate, br, zstd",
|
||||||
|
"Referer": "https://gofile.io/",
|
||||||
|
"Authorization": f"Bearer lUUtRAccOuRUoZhelNSslDFSlpOgKLDj",
|
||||||
|
"X-Website-Token": "ffd9ffa831c50b9e68ca5e65cbbbd1a50e9a32e63022e17c7c6748388a1ed73b",
|
||||||
|
"X-BL": "en-US",
|
||||||
|
"Origin": "https://gofile.io",
|
||||||
|
"Sec-GPC": "1",
|
||||||
|
"Connection": "keep-alive",
|
||||||
|
"TE": "trailers"
|
||||||
}
|
}
|
||||||
|
|
||||||
r = session.get(
|
r = session.get(
|
||||||
f"https://api.gofile.io/contents/{filetoken}",
|
f"https://api.gofile.io/contents/{filetoken}",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
temp: dict = r.json()["data"]["children"]
|
temp: dict = r.json()["data"]["children"]
|
||||||
child = [key for key in temp.keys()]
|
child = [key for key in temp.keys()]
|
||||||
|
|
||||||
return temp[child[0]]["link"]
|
link = temp[child[0]]["link"]
|
||||||
|
return link, headers
|
||||||
except:
|
except:
|
||||||
consoleLog("GoFile Authorisation failed, if the Issue persists, please open an Issue on GitHub")
|
consoleLog("GoFile Authorisation failed, if the Issue persists, please open an Issue on GitHub")
|
||||||
|
|
||||||
|
|||||||
@@ -69,10 +69,6 @@ def scrape_steamrip_game_downloads(gamelink):
|
|||||||
download_links[0] = "https:" + pure
|
download_links[0] = "https:" + pure
|
||||||
if pure[2] == "g":
|
if pure[2] == "g":
|
||||||
download_links[1] = "https:" + pure
|
download_links[1] = "https:" + pure
|
||||||
if pure[2] == "v":
|
|
||||||
download_links[2] = "https:" + pure
|
|
||||||
if pure[2] == "m":
|
|
||||||
download_links[3] = "https:" + pure
|
|
||||||
|
|
||||||
ret = []
|
ret = []
|
||||||
|
|
||||||
@@ -94,13 +90,15 @@ def get_download_link(post: Dict):
|
|||||||
break
|
break
|
||||||
|
|
||||||
if links.index(best) == 0:
|
if links.index(best) == 0:
|
||||||
return scrape_buzzheavier(best)
|
link = scrape_buzzheavier(best)
|
||||||
|
return link
|
||||||
elif links.index(best) == 1:
|
elif links.index(best) == 1:
|
||||||
return scrape_gofile(best)
|
link, headers = scrape_gofile(best)
|
||||||
|
return link, headers
|
||||||
else:
|
else:
|
||||||
consoleLog("Unable to retrieve download link due to captcha, launching browser...")
|
consoleLog("Unable to retrieve download link due to captcha, launching browser...")
|
||||||
webbrowser.open(best)
|
webbrowser.open(best)
|
||||||
return None
|
return None, None
|
||||||
|
|
||||||
def filter_steamrip(query: str):
|
def filter_steamrip(query: str):
|
||||||
games = scrape_steamrip_links()
|
games = scrape_steamrip_links()
|
||||||
@@ -121,4 +119,4 @@ Metadata = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def init_steamrip():
|
def init_steamrip():
|
||||||
state.trackers.update({Metadata["name"] : Metadata})
|
state.trackers.update({Metadata["name"] : Metadata})
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from .utils import (
|
|||||||
detect_filename_from_headers,
|
detect_filename_from_headers,
|
||||||
)
|
)
|
||||||
|
|
||||||
def add_direct_download(url: str, title: str, dl_path: Optional[str] = None):
|
def add_direct_download(url: str, title: str, dl_path: Optional[str] = None, headers: Optional[dict] = None, single_threaded: bool = False):
|
||||||
|
|
||||||
if dl_path is None:
|
if dl_path is None:
|
||||||
dl_path = state.download_path
|
dl_path = state.download_path
|
||||||
@@ -24,7 +24,7 @@ def add_direct_download(url: str, title: str, dl_path: Optional[str] = None):
|
|||||||
or sanitize_filename(title) + ".zip"
|
or sanitize_filename(title) + ".zip"
|
||||||
)
|
)
|
||||||
|
|
||||||
handle = DirectDownloadHandle(url, filename, dl_path)
|
handle = DirectDownloadHandle(url, filename, dl_path, headers, single_threaded)
|
||||||
state.active_downloads[url] = handle
|
state.active_downloads[url] = handle
|
||||||
add_download_log(title, url, "", False)
|
add_download_log(title, url, "", False)
|
||||||
handle.start()
|
handle.start()
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class DirectDownloadHandle:
|
|||||||
"Chrome/125.0.0.0 Safari/537.36"
|
"Chrome/125.0.0.0 Safari/537.36"
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, url: str, name: str, save_path: str):
|
def __init__(self, url: str, name: str, save_path: str, headers: Optional[dict] = None, single_threaded: bool = False):
|
||||||
self.url = url
|
self.url = url
|
||||||
self._name = name
|
self._name = name
|
||||||
self._save_path = save_path
|
self._save_path = save_path
|
||||||
@@ -69,6 +69,8 @@ class DirectDownloadHandle:
|
|||||||
self._thread: Optional[threading.Thread] = None
|
self._thread: Optional[threading.Thread] = None
|
||||||
self._session: Optional[requests.Session] = None
|
self._session: Optional[requests.Session] = None
|
||||||
self._supports_range = False
|
self._supports_range = False
|
||||||
|
self._custom_headers = headers
|
||||||
|
self._single_threaded = single_threaded
|
||||||
|
|
||||||
state_dir = os.path.join(state.settings_path, "direct_downloads")
|
state_dir = os.path.join(state.settings_path, "direct_downloads")
|
||||||
os.makedirs(state_dir, exist_ok=True)
|
os.makedirs(state_dir, exist_ok=True)
|
||||||
@@ -151,6 +153,8 @@ class DirectDownloadHandle:
|
|||||||
def _build_session(self) -> requests.Session:
|
def _build_session(self) -> requests.Session:
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
session.headers.update({"User-Agent": self.USER_AGENT})
|
session.headers.update({"User-Agent": self.USER_AGENT})
|
||||||
|
if self._custom_headers is not None:
|
||||||
|
session.headers.update(self._custom_headers)
|
||||||
adapter = requests.adapters.HTTPAdapter(
|
adapter = requests.adapters.HTTPAdapter(
|
||||||
max_retries=0,
|
max_retries=0,
|
||||||
pool_connections=self.NUM_THREADS,
|
pool_connections=self.NUM_THREADS,
|
||||||
@@ -194,6 +198,7 @@ class DirectDownloadHandle:
|
|||||||
use_multithreaded = (
|
use_multithreaded = (
|
||||||
self._supports_range
|
self._supports_range
|
||||||
and total_size > self.MIN_CHUNK_SIZE * 2
|
and total_size > self.MIN_CHUNK_SIZE * 2
|
||||||
|
and not self._single_threaded
|
||||||
)
|
)
|
||||||
|
|
||||||
if use_multithreaded:
|
if use_multithreaded:
|
||||||
@@ -204,7 +209,7 @@ class DirectDownloadHandle:
|
|||||||
self._preallocate_file(total_size)
|
self._preallocate_file(total_size)
|
||||||
self._multithreaded_download(total_size)
|
self._multithreaded_download(total_size)
|
||||||
else:
|
else:
|
||||||
reason = "no range support" if not self._supports_range else "file too small"
|
reason = "no range support" if not self._supports_range else "file too small or single-threaded mode"
|
||||||
consoleLog(f"Single-threaded download ({reason}): {self._name}")
|
consoleLog(f"Single-threaded download ({reason}): {self._name}")
|
||||||
self._single_threaded_download()
|
self._single_threaded_download()
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ from PySide6.QtWidgets import QTableWidgetItem
|
|||||||
from core.utils.logging.logs import consoleLog
|
from core.utils.logging.logs import consoleLog
|
||||||
from core.utils.data.state import state
|
from core.utils.data.state import state
|
||||||
from PySide6.QtCore import Qt
|
from PySide6.QtCore import Qt
|
||||||
|
from typing import Optional
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def download_selected(items: list[QTableWidgetItem]):
|
def download_selected(items: list[QTableWidgetItem]):
|
||||||
if not items:
|
if not items:
|
||||||
consoleLog("No item selected for download.")
|
consoleLog("No item selected for download.")
|
||||||
@@ -30,16 +30,19 @@ def download_selected(items: list[QTableWidgetItem]):
|
|||||||
consoleLog(f"Downloading {post.get('title', 'Unknown')}")
|
consoleLog(f"Downloading {post.get('title', 'Unknown')}")
|
||||||
run_thread(threading.Thread(target=run_download, args=(post,)))
|
run_thread(threading.Thread(target=run_download, args=(post,)))
|
||||||
|
|
||||||
def run_download(post):
|
def run_download(post, headers: Optional[dict] = None):
|
||||||
linkfunc = state.trackers[state.currenttracker]["linkFunc"]
|
linkfunc = state.trackers[state.currenttracker]["linkFunc"]
|
||||||
ismagnet = state.trackers[state.currenttracker]["isMagnet"]
|
ismagnet = state.trackers[state.currenttracker]["isMagnet"]
|
||||||
link = linkfunc(post)
|
result = linkfunc(post)
|
||||||
|
|
||||||
if ismagnet:
|
if ismagnet:
|
||||||
|
link = result
|
||||||
add_magnet(link)
|
add_magnet(link)
|
||||||
add_download_log(post.get("title", "Unknown"), "", link, False)
|
add_download_log(post.get("title", "Unknown"), "", link, False)
|
||||||
else:
|
else:
|
||||||
add_direct_download(link, post.get("title", "Unknown"))
|
link, link_headers = result if isinstance(result, tuple) else (result, None)
|
||||||
|
final_headers = headers or link_headers
|
||||||
|
add_direct_download(link, post.get("title", "Unknown"), headers=final_headers, single_threaded=final_headers is not None)
|
||||||
|
|
||||||
def run_download_direct(magnet_uri, title="Direct Download"):
|
def run_download_direct(magnet_uri, title="Direct Download"):
|
||||||
consoleLog(f"Magnet: {title}")
|
consoleLog(f"Magnet: {title}")
|
||||||
|
|||||||
Reference in New Issue
Block a user