From 64ca3c76a2ee8e0979d8967dfd8452b3379fbe7e Mon Sep 17 00:00:00 2001 From: Vxrtrauter <101264710+Vxrtrauter@users.noreply.github.com> Date: Mon, 4 May 2026 19:07:42 +0200 Subject: [PATCH] Fix: update buzzheavier link detection logic and improve filename extraction from headers --- src/data/sources/steamrip.py | 2 +- src/network/direct_download/__init__.py | 4 +++- src/network/direct_download/handle.py | 19 ++++++++++++++++++- src/network/direct_download/utils.py | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/data/sources/steamrip.py b/src/data/sources/steamrip.py index 7162f17..550ee22 100644 --- a/src/data/sources/steamrip.py +++ b/src/data/sources/steamrip.py @@ -113,7 +113,7 @@ class SteamripScraper: try: consoleLog(f"Found download link: {best}") - if "buzzheavier" in best: + if "buzzheavier" or "bzzhr" in best: link = scrape_buzzheavier(best) return link elif "gofile" in best: diff --git a/src/network/direct_download/__init__.py b/src/network/direct_download/__init__.py index f423484..01c6768 100644 --- a/src/network/direct_download/__init__.py +++ b/src/network/direct_download/__init__.py @@ -20,12 +20,14 @@ def add_direct_download(url: str, title: str, dl_path: Optional[str] = None, hea consoleLog(f"Download already active: {title}") return - filename = ( + raw_filename = ( detect_filename_from_headers(url, DirectDownloadHandle.USER_AGENT) or extract_filename_from_url(url) or sanitize_filename(title) + ".zip" ) + filename = sanitize_filename(raw_filename) + handle = DirectDownloadHandle(url, filename, dl_path, headers, single_threaded) with state.downloads_lock: state.active_downloads[url] = handle diff --git a/src/network/direct_download/handle.py b/src/network/direct_download/handle.py index 023191b..eca5858 100644 --- a/src/network/direct_download/handle.py +++ b/src/network/direct_download/handle.py @@ -10,6 +10,7 @@ import requests import hashlib import json import time +import sys import os @@ -231,8 +232,24 @@ class DirectDownloadHandle: def _preallocate_file(self, total_size: int): if os.path.exists(self._file_path) and os.path.getsize(self._file_path) == total_size: return + with open(self._file_path, "wb") as f: - f.truncate(total_size) + if sys.platform == "win32": + import msvcrt + import ctypes + from ctypes.wintypes import DWORD + + handle = msvcrt.get_osfhandle(f.fileno()) + kernel32 = ctypes.windll.kernel32 + + bytes_returned = DWORD() + kernel32.DeviceIoControl( + handle, 590020, None, 0, None, 0, ctypes.byref(bytes_returned), None + ) + kernel32.SetFilePointerEx(handle, ctypes.c_int64(total_size), None, 0) + kernel32.SetEndOfFile(handle) + else: + f.truncate(total_size) def _compute_chunks(self, total_size: int) -> list[ChunkSpec]: num_chunks = min(self.NUM_THREADS, max(1, total_size // self.MIN_CHUNK_SIZE)) diff --git a/src/network/direct_download/utils.py b/src/network/direct_download/utils.py index 2b70b58..3a6f470 100644 --- a/src/network/direct_download/utils.py +++ b/src/network/direct_download/utils.py @@ -34,7 +34,7 @@ def detect_filename_from_headers(url: str, user_agent: str) -> Optional[str]: if "filename=" in cd: parts = cd.split("filename=") if len(parts) > 1: - fname = parts[-1].strip().strip('"').strip("'") + fname = parts[1].split(";")[0].strip().strip('"').strip("'") if fname: return fname except Exception as e: