fix gofile downloads by adding custom headers to both direct dl and api request

still needs work: 1. fix restart causing the download to instantly jump to 100%
This commit is contained in:
2026-03-11 22:15:00 +01:00
parent c3efa39b09
commit 7df7d87928
5 changed files with 38 additions and 22 deletions
+16 -6
View File
@@ -8,24 +8,34 @@ def scrape_gofile(url):
filetoken = re.findall(r"(?<=https...gofile.io\/d\/).*", url)[0]
session = requests.Session()
acc = session.post("https://api.gofile.io/accounts")
token = acc.json()["data"]["token"]
headers = {
"Authorization": f"Bearer {token}",
"X-Website-Token": "4fd6sg89d7s6", # Maybe make this dynamic in the future
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:148.0) Gecko/20100101 Firefox/148.0",
"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(
f"https://api.gofile.io/contents/{filetoken}",
headers=headers,
)
try:
temp: dict = r.json()["data"]["children"]
child = [key for key in temp.keys()]
return temp[child[0]]["link"]
link = temp[child[0]]["link"]
return link, headers
except:
consoleLog("gofile didnt auth you, either the api has changed\n or you sent to many requests, please try again later.\n If it still doesnt work please open an issue on Github.")
return None, None
+5 -7
View File
@@ -68,10 +68,6 @@ def scrape_steamrip_game_downloads(gamelink):
download_links[0] = "https:" + pure
if pure[2] == "g":
download_links[1] = "https:" + pure
if pure[2] == "v":
download_links[2] = "https:" + pure
if pure[2] == "m":
download_links[3] = "https:" + pure
ret = []
@@ -93,13 +89,15 @@ def get_download_link(post: Dict):
break
if links.index(best) == 0:
return scrape_buzzheavier(best)
link = scrape_buzzheavier(best)
return link
elif links.index(best) == 1:
return scrape_gofile(best)
link, headers = scrape_gofile(best)
return link, headers
else:
consoleLog("Unable to retrieve download link due to captcha, launching browser...")
webbrowser.open(best)
return None
return None, None
def filter_steamrip(query: str):
games = scrape_steamrip_links()
+2 -2
View File
@@ -9,7 +9,7 @@ from .utils import (
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:
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"
)
handle = DirectDownloadHandle(url, filename, dl_path)
handle = DirectDownloadHandle(url, filename, dl_path, headers, single_threaded)
state.active_downloads[url] = handle
add_download_log(title, url, "", False)
handle.start()
+7 -2
View File
@@ -58,7 +58,7 @@ class DirectDownloadHandle:
"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._name = name
self._save_path = save_path
@@ -69,6 +69,8 @@ class DirectDownloadHandle:
self._thread: Optional[threading.Thread] = None
self._session: Optional[requests.Session] = None
self._supports_range = False
self._custom_headers = headers
self._single_threaded = single_threaded
state_dir = os.path.join(state.settings_path, "direct_downloads")
os.makedirs(state_dir, exist_ok=True)
@@ -151,6 +153,8 @@ class DirectDownloadHandle:
def _build_session(self) -> requests.Session:
session = requests.Session()
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(
max_retries=0,
pool_connections=self.NUM_THREADS,
@@ -194,6 +198,7 @@ class DirectDownloadHandle:
use_multithreaded = (
self._supports_range
and total_size > self.MIN_CHUNK_SIZE * 2
and not self._single_threaded
)
if use_multithreaded:
@@ -204,7 +209,7 @@ class DirectDownloadHandle:
self._preallocate_file(total_size)
self._multithreaded_download(total_size)
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}")
self._single_threaded_download()
+7 -4
View File
@@ -7,11 +7,11 @@ from core.utils.logging.logs import add_download_log
from core.network.libtorrent_int import add_seed
from core.utils.data.state import state
from core.network.direct_download import add_direct_download
from typing import Optional
import threading
def download_selected(items: list[QTableWidgetItem]):
if not items:
consoleLog("No item selected for download.")
@@ -30,16 +30,19 @@ def download_selected(items: list[QTableWidgetItem]):
consoleLog(f"Downloading {post.get('title', 'Unknown')}")
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"]
ismagnet = state.trackers[state.currenttracker]["isMagnet"]
link = linkfunc(post)
result = linkfunc(post)
if ismagnet:
link = result
add_magnet(link)
add_download_log(post.get("title", "Unknown"), "", link, False)
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, dl_path=None, title="Direct Download"):
consoleLog(f"Magnet: {title}")