forked from Linux-Gaming/PortProtonQt
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
65bc286494
|
||
|
|
cb91b41b46
|
||
|
|
c24aec0e40
|
||
|
|
54271548ec
|
||
|
|
a9552a3c1b
|
||
|
|
88c30025de
|
||
|
|
1aac62b647
|
||
|
|
08131ea53f
|
||
|
|
2666159375
|
||
|
|
3515ad0ac5
|
||
|
|
0875896e45
|
||
|
|
4f406cc966
|
No files matched your search
@@ -30,6 +30,7 @@
|
||||
- В настройки добавлена загрузка Wine/Proton в Steam `compatibilitytools.d`
|
||||
|
||||
### Changed
|
||||
- Бейджи источников (Steam и PortProton) теперь отображаются при любом фильтре библиотеки
|
||||
- Обложки к играм из Steam теперь полностью локальные
|
||||
- Улучшен механизм кеширования данных
|
||||
- Тип геймпада `Xbox` `PS` теперь выбирается автоматически
|
||||
@@ -48,6 +49,7 @@
|
||||
- Автоустановки теперь можно остановить
|
||||
- Префиксы `DEFAULT`, `DOTNET` и `PROGRAMS` теперь всегда отображаются вверху списков префиксов
|
||||
- Из лога удалена версия скриптов, так как скрипты теперь внутри PortProtonQt
|
||||
- Из downloader удалена отдельная проверка сети через Yandex и Google
|
||||
|
||||
### Fixed
|
||||
- Исправлено определение `PW_USE_RUNTIME` в debug-логе
|
||||
@@ -65,6 +67,7 @@
|
||||
- Исправлено управление геймпадом в диалоге выбора файла для загрузки PPDB
|
||||
- Исправлен повторный вывод одинаковых Vulkan GPU в `vk_gpu_info`
|
||||
- Исправлена работа клавиатурного управления при раскладке, отличной от английской
|
||||
- Исправлена загрузка данных HowLongToBeat
|
||||
|
||||
### Contributors
|
||||
- @Dervart
|
||||
|
||||
@@ -88,7 +88,7 @@ EOM
|
||||
# Disable locale noextract
|
||||
sed -i -E 's@[[:space:]]*usr/share/locale/\*@@g; s@[[:space:]]+@ @g; s@[[:space:]]+$@@' /etc/pacman.conf
|
||||
|
||||
pacman -Syy
|
||||
pacman -Syyu --noconfirm --disable-download-timeout
|
||||
|
||||
echo "Building PortProtonQt from PKGBUILD..."
|
||||
echo "---------------------------------------------------------------"
|
||||
|
||||
@@ -11,6 +11,7 @@ export DESKTOP=/usr/share/applications/ru.linux_gaming.PortProtonQt.desktop
|
||||
export ICON=/usr/share/icons/hicolor/scalable/apps/ru.linux_gaming.PortProtonQt.svg
|
||||
export OUTNAME=PortProtonQt-"$VERSION"-anylinux-"$ARCH".AppImage
|
||||
export DEPLOY_OPENGL=1
|
||||
export DEPLOY_SDL=1
|
||||
export DEPLOY_SYS_PYTHON=1
|
||||
export OPTIMIZE_LAUNCH=1
|
||||
|
||||
@@ -40,7 +41,7 @@ fi
|
||||
/usr/lib/libQt6Core.so* \
|
||||
/usr/lib/libQt6Gui.so* \
|
||||
/usr/lib/libQt6Network.so* \
|
||||
/usr/lib/libudev.so*
|
||||
/usr/lib/qt6/plugins/imageformats/libqwebp.so
|
||||
|
||||
# Turn AppDir into AppImage
|
||||
./quick-sharun --make-appimage
|
||||
+1
-1
@@ -6,7 +6,7 @@ arch=('any')
|
||||
url="https://git.linux-gaming.ru/Linux-Gaming/PortProtonQt"
|
||||
license=('GPL-3.0')
|
||||
depends=('python-requests' 'python-babel' 'python-evdev' 'python-pygame' 'python-orjson'
|
||||
'python-psutil' 'python-tqdm' 'python-vdf' 'python-libarchive-c' 'pyside6' 'python-rapidfuzz' 'python-pefile' 'python-pillow' 'perl-image-exiftool' 'python-beautifulsoup4' 'python-websocket-client' 'cabextract' 'unzip' 'curl' 'jq' 'file' 'findutils' 'gawk' 'grep' 'tar' 'xz' 'zstd' 'gzip' 'unrar' 'qt6-svg' 'pciutils' 'mesa-utils' 'vulkan-icd-loader' 'procps-ng' 'psmisc' 'squashfs-tools' '7zip' 'python-dbus-fast')
|
||||
'python-psutil' 'python-tqdm' 'python-vdf' 'python-libarchive-c' 'pyside6' 'python-rapidfuzz' 'python-pefile' 'python-pillow' 'perl-image-exiftool' 'python-websocket-client' 'cabextract' 'unzip' 'curl' 'jq' 'file' 'findutils' 'gawk' 'grep' 'tar' 'xz' 'zstd' 'gzip' 'unrar' 'qt6-svg' 'qt6-imageformats' 'pciutils' 'mesa-utils' 'vulkan-icd-loader' 'procps-ng' 'psmisc' 'squashfs-tools' '7zip' 'python-dbus-fast')
|
||||
depends_aarch64=('muvm')
|
||||
makedepends=('meson' 'ninja' 'vulkan-headers' 'gettext')
|
||||
source=("git+https://git.linux-gaming.ru/Linux-Gaming/PortProtonQt#tag=v$pkgver")
|
||||
|
||||
@@ -6,7 +6,7 @@ arch=('any')
|
||||
url="https://git.linux-gaming.ru/Linux-Gaming/PortProtonQt"
|
||||
license=('GPL-3.0')
|
||||
depends=('python-requests' 'python-babel' 'python-evdev' 'python-pygame' 'python-orjson'
|
||||
'python-psutil' 'python-tqdm' 'python-vdf' 'python-libarchive-c' 'pyside6' 'python-rapidfuzz' 'python-pefile' 'python-pillow' 'perl-image-exiftool' 'python-beautifulsoup4' 'python-websocket-client' 'cabextract' 'unzip' 'curl' 'jq' 'file' 'findutils' 'gawk' 'grep' 'tar' 'xz' 'zstd' 'gzip' 'unrar' 'qt6-svg' 'pciutils' 'mesa-utils' 'vulkan-icd-loader' 'procps-ng' 'psmisc' 'squashfs-tools' '7zip' 'python-dbus-fast')
|
||||
'python-psutil' 'python-tqdm' 'python-vdf' 'python-libarchive-c' 'pyside6' 'python-rapidfuzz' 'python-pefile' 'python-pillow' 'perl-image-exiftool' 'python-websocket-client' 'cabextract' 'unzip' 'curl' 'jq' 'file' 'findutils' 'gawk' 'grep' 'tar' 'xz' 'zstd' 'gzip' 'unrar' 'qt6-svg' 'qt6-imageformats' 'pciutils' 'mesa-utils' 'vulkan-icd-loader' 'procps-ng' 'psmisc' 'squashfs-tools' '7zip' 'python-dbus-fast')
|
||||
depends_aarch64=('muvm')
|
||||
makedepends=('meson' 'ninja' 'vulkan-headers' 'gettext')
|
||||
source=("git+https://git.linux-gaming.ru/Linux-Gaming/PortProtonQt.git")
|
||||
|
||||
@@ -39,11 +39,11 @@ Requires: python3-tqdm
|
||||
Requires: python3-vdf
|
||||
Requires: python3-pefile
|
||||
Requires: python3-pillow
|
||||
Requires: python3-beautifulsoup4
|
||||
Requires: python3-rapidfuzz
|
||||
Requires: python3-libarchive-c
|
||||
Requires: perl-Image-ExifTool
|
||||
Requires: qt6-qtsvg
|
||||
Requires: qt6-qtimageformats
|
||||
Requires: cabextract
|
||||
Requires: gzip
|
||||
Requires: unzip
|
||||
|
||||
@@ -36,11 +36,11 @@ Requires: python3-tqdm
|
||||
Requires: python3-vdf
|
||||
Requires: python3-pefile
|
||||
Requires: python3-pillow
|
||||
Requires: python3-beautifulsoup4
|
||||
Requires: python3-rapidfuzz
|
||||
Requires: python3-libarchive-c
|
||||
Requires: perl-Image-ExifTool
|
||||
Requires: qt6-qtsvg
|
||||
Requires: qt6-qtimageformats
|
||||
Requires: cabextract
|
||||
Requires: gzip
|
||||
Requires: unzip
|
||||
|
||||
@@ -21,6 +21,7 @@ from portprotonqt.detail_pages.widgets import (
|
||||
create_back_button,
|
||||
create_content_frame,
|
||||
setup_adaptive_layout,
|
||||
apply_adaptive_layout,
|
||||
create_cover_frame,
|
||||
create_protondb_badge,
|
||||
create_steam_badge,
|
||||
@@ -195,19 +196,17 @@ class DetailPageManager:
|
||||
return size, size
|
||||
|
||||
def _create_game_badges(self, parent: QWidget, game_data: dict) -> list:
|
||||
from portprotonqt.config import game_config
|
||||
|
||||
if self._is_compact_detail_layout():
|
||||
return []
|
||||
|
||||
display_filter = game_config.get_display_filter()
|
||||
game_source = str(game_data.get("game_source", "")).lower()
|
||||
appid = game_data.get("appid", "")
|
||||
name = game_data.get("name", "")
|
||||
exec_line = game_data.get("exec_line", "")
|
||||
|
||||
steam_visible = game_source == "steam" and display_filter in ("all", "favorites")
|
||||
portproton_visible = game_source == "portproton" and display_filter in ("all", "favorites")
|
||||
steam_visible = game_source == "steam"
|
||||
portproton_visible = game_source == "portproton"
|
||||
|
||||
badges = []
|
||||
protondb_badge = self._create_protondb_badge(parent, game_data)
|
||||
@@ -323,6 +322,19 @@ class DetailPageManager:
|
||||
|
||||
if has_data:
|
||||
game_info_layout.addLayout(hltb_layout)
|
||||
QTimer.singleShot(0, self._refresh_current_detail_page_layout)
|
||||
|
||||
def _refresh_current_detail_page_layout(self) -> None:
|
||||
"""Refresh layout after asynchronous detail content changes."""
|
||||
if not self._detail_page_active or not self._current_detail_page:
|
||||
return
|
||||
|
||||
content_frame_layout = self._get_content_frame_layout(self._current_detail_page)
|
||||
if content_frame_layout:
|
||||
content_frame_layout.invalidate()
|
||||
apply_adaptive_layout(self._current_detail_page, content_frame_layout)
|
||||
|
||||
self._current_detail_page.updateGeometry()
|
||||
|
||||
def _add_hltb_times(
|
||||
self, game: GameEntry, hltb: HowLongToBeat, hltb_layout: QHBoxLayout
|
||||
|
||||
@@ -107,30 +107,33 @@ def setup_adaptive_layout(
|
||||
"""Setup adaptive layout switching on resize."""
|
||||
|
||||
def on_detail_page_resize(event) -> None:
|
||||
if detail_page.property("force_compact_detail_layout"):
|
||||
content_frame_layout.setDirection(QBoxLayout.Direction.TopToBottom)
|
||||
content_frame_layout.setAlignment(
|
||||
Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop
|
||||
)
|
||||
QWidget.resizeEvent(detail_page, event)
|
||||
return
|
||||
|
||||
required_width = _get_required_horizontal_width(content_frame_layout)
|
||||
if detail_page.width() < required_width:
|
||||
if content_frame_layout.direction() != QBoxLayout.Direction.TopToBottom:
|
||||
content_frame_layout.setDirection(QBoxLayout.Direction.TopToBottom)
|
||||
content_frame_layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
else:
|
||||
if content_frame_layout.direction() != QBoxLayout.Direction.LeftToRight:
|
||||
content_frame_layout.setDirection(QBoxLayout.Direction.LeftToRight)
|
||||
content_frame_layout.setAlignment(
|
||||
Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop
|
||||
)
|
||||
apply_adaptive_layout(detail_page, content_frame_layout)
|
||||
QWidget.resizeEvent(detail_page, event)
|
||||
|
||||
detail_page.resizeEvent = on_detail_page_resize
|
||||
|
||||
|
||||
def apply_adaptive_layout(detail_page: QWidget, content_frame_layout: QBoxLayout) -> None:
|
||||
"""Apply detail page adaptive layout for current size hints."""
|
||||
if detail_page.property("force_compact_detail_layout"):
|
||||
content_frame_layout.setDirection(QBoxLayout.Direction.TopToBottom)
|
||||
content_frame_layout.setAlignment(
|
||||
Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop
|
||||
)
|
||||
return
|
||||
|
||||
required_width = _get_required_horizontal_width(content_frame_layout)
|
||||
if detail_page.width() < required_width:
|
||||
if content_frame_layout.direction() != QBoxLayout.Direction.TopToBottom:
|
||||
content_frame_layout.setDirection(QBoxLayout.Direction.TopToBottom)
|
||||
content_frame_layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
elif content_frame_layout.direction() != QBoxLayout.Direction.LeftToRight:
|
||||
content_frame_layout.setDirection(QBoxLayout.Direction.LeftToRight)
|
||||
content_frame_layout.setAlignment(
|
||||
Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop
|
||||
)
|
||||
|
||||
|
||||
def _get_required_horizontal_width(content_frame_layout: QBoxLayout) -> int:
|
||||
"""Calculate minimal width for horizontal content layout."""
|
||||
item_count = content_frame_layout.count()
|
||||
|
||||
@@ -94,15 +94,15 @@ class WinetricksDialog(DraggableDialog):
|
||||
|
||||
def update_winetricks(self):
|
||||
"""Update the winetricks script."""
|
||||
if not self.downloader.has_internet():
|
||||
logger.warning("No internet connection, skipping winetricks update")
|
||||
return
|
||||
|
||||
url = "https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks"
|
||||
temp_path = os.path.join(self.tmp_path, "winetricks_temp")
|
||||
|
||||
try:
|
||||
self.downloader.download(url, temp_path)
|
||||
if not self.downloader.download(url, temp_path):
|
||||
logger.warning("Failed to download external winetricks version")
|
||||
if os.path.exists(temp_path):
|
||||
os.remove(temp_path)
|
||||
return
|
||||
with open(temp_path) as f:
|
||||
ext_content = f.read()
|
||||
ext_ver_match = re.search(r'WINETRICKS_VERSION\s*=\s*[\'"]?([^\'"\s]+)', ext_content)
|
||||
|
||||
@@ -2,7 +2,6 @@ from PySide6.QtCore import QObject, Signal, QThread
|
||||
import threading
|
||||
import os
|
||||
import requests
|
||||
import socket
|
||||
from pathlib import Path
|
||||
from tqdm import tqdm
|
||||
from collections.abc import Callable
|
||||
@@ -65,54 +64,12 @@ class Downloader(QObject):
|
||||
self._locks = {}
|
||||
self._active_threads: list[QThread] = []
|
||||
self._global_lock = threading.Lock()
|
||||
self._has_internet = None
|
||||
self.callback_requested.connect(self._run_callback)
|
||||
|
||||
def _run_callback(self, callback, result):
|
||||
if callback:
|
||||
callback(result)
|
||||
|
||||
def has_internet(self, timeout=3):
|
||||
if self._has_internet is None:
|
||||
errors = []
|
||||
# Primary: Yandex
|
||||
try:
|
||||
socket.create_connection(("77.88.8.8", 53), timeout=timeout)
|
||||
except Exception as e:
|
||||
errors.append(f"Yandex DNS (77.88.8.8): {e}")
|
||||
try:
|
||||
socket.create_connection(("77.88.8.1", 53), timeout=timeout)
|
||||
except Exception as e:
|
||||
errors.append(f"Yandex DNS (77.88.8.1): {e}")
|
||||
try:
|
||||
requests.get("https://ya.ru", timeout=timeout)
|
||||
except Exception as e:
|
||||
errors.append(f"ya.ru: {e}")
|
||||
|
||||
# Fallback: Google (if Yandex failed)
|
||||
if errors:
|
||||
logger.debug("Yandex check failed, trying Google fallback")
|
||||
try:
|
||||
socket.create_connection(("8.8.8.8", 53), timeout=timeout)
|
||||
except Exception as e:
|
||||
errors.append(f"Google DNS (8.8.8.8): {e}")
|
||||
try:
|
||||
socket.create_connection(("8.8.4.4", 53), timeout=timeout)
|
||||
except Exception as e:
|
||||
errors.append(f"Google DNS (8.8.4.4): {e}")
|
||||
try:
|
||||
requests.get("https://www.google.com", timeout=timeout)
|
||||
except Exception as e:
|
||||
errors.append(f"google.com: {e}")
|
||||
|
||||
if errors:
|
||||
logger.warning("Internet unavailable:\n" + "\n".join(errors))
|
||||
self._has_internet = False
|
||||
else:
|
||||
self._has_internet = True
|
||||
return self._has_internet
|
||||
|
||||
|
||||
def _get_url_lock(self, url):
|
||||
with self._global_lock:
|
||||
if url not in self._locks:
|
||||
@@ -219,9 +176,6 @@ class Downloader(QObject):
|
||||
return results
|
||||
|
||||
def download(self, url, local_path, timeout=5):
|
||||
if not self.has_internet():
|
||||
logger.warning(f"No internet, skipping download {url}")
|
||||
return None
|
||||
with self._global_lock:
|
||||
if url in self._last_error:
|
||||
logger.warning(f"Previous download error for {url}, skipping")
|
||||
@@ -259,14 +213,6 @@ class Downloader(QObject):
|
||||
max_workers=None,
|
||||
on_result: Callable[[str, str | None], None] | None = None,
|
||||
):
|
||||
if not self.has_internet():
|
||||
logger.warning("No internet, skipping parallel download")
|
||||
results = dict.fromkeys(urls)
|
||||
if on_result:
|
||||
for url, result in results.items():
|
||||
on_result(url, result)
|
||||
return results
|
||||
|
||||
filtered_urls = []
|
||||
filtered_paths = []
|
||||
emitted_urls = set()
|
||||
|
||||
@@ -89,8 +89,8 @@ class GameCard(QFrame):
|
||||
self.portproton_api = PortProtonAPI(self.downloader)
|
||||
self.missing_executable_path = self._get_missing_executable_path()
|
||||
|
||||
self.steam_visible = (str(game_source).lower() == "steam" and self.display_filter in ("all", "favorites") and not self.economy_mode)
|
||||
self.portproton_visible = (str(game_source).lower() == "portproton" and self.display_filter in ("all", "favorites") and not self.economy_mode)
|
||||
self.steam_visible = (str(game_source).lower() == "steam" and not self.economy_mode)
|
||||
self.portproton_visible = (str(game_source).lower() == "portproton" and not self.economy_mode)
|
||||
|
||||
self.base_extra_margin = 8 if self.list_layout else 20
|
||||
self.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
|
||||
@@ -486,8 +486,8 @@ class GameCard(QFrame):
|
||||
|
||||
self.display_filter = display_filter
|
||||
self.economy_mode = ui_config.get_economy_mode()
|
||||
self.steam_visible = (str(self.game_source).lower() == "steam" and self.display_filter in ("all", "favorites") and not self.economy_mode)
|
||||
self.portproton_visible = (str(self.game_source).lower() == "portproton" and self.display_filter in ("all", "favorites") and not self.economy_mode)
|
||||
self.steam_visible = (str(self.game_source).lower() == "steam" and not self.economy_mode)
|
||||
self.portproton_visible = (str(self.game_source).lower() == "portproton" and not self.economy_mode)
|
||||
protondb_visible = bool(self.getProtonDBText(self.protondb_tier)) and not self.economy_mode
|
||||
anticheat_visible = bool(self.getAntiCheatText(self.anticheat_status)) and not self.economy_mode
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import orjson
|
||||
import re
|
||||
from dataclasses import dataclass, field
|
||||
import time
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
from difflib import SequenceMatcher
|
||||
from threading import Thread
|
||||
import requests
|
||||
from bs4 import BeautifulSoup, Tag
|
||||
from portprotonqt.config import proxy_config
|
||||
from portprotonqt.time_utils import format_playtime
|
||||
from portprotonqt.logger import get_logger
|
||||
@@ -17,66 +15,22 @@ logger = get_logger(__name__)
|
||||
@dataclass
|
||||
class GameEntry:
|
||||
"""Game information from HowLongToBeat."""
|
||||
game_id: int = -1
|
||||
game_name: str | None = None
|
||||
main_story: float | None = None
|
||||
main_extra: float | None = None
|
||||
completionist: float | None = None
|
||||
similarity: float = -1.0
|
||||
raw_data: dict[str, Any] = field(default_factory=dict)
|
||||
|
||||
@dataclass
|
||||
class SearchConfig:
|
||||
"""Search configuration."""
|
||||
api_key: str | None = None
|
||||
search_url: str | None = None
|
||||
|
||||
class APIKeyExtractor:
|
||||
"""Extract API key and search URL from site scripts."""
|
||||
@staticmethod
|
||||
def extract_from_script(script_content: str) -> SearchConfig:
|
||||
config = SearchConfig()
|
||||
config.api_key = APIKeyExtractor._extract_api_key(script_content)
|
||||
config.search_url = APIKeyExtractor._extract_search_url(script_content, config.api_key)
|
||||
return config
|
||||
|
||||
@staticmethod
|
||||
def _extract_api_key(script_content: str) -> str | None:
|
||||
user_id_pattern = r'users\s*:\s*{\s*id\s*:\s*"([^"]+)"'
|
||||
matches = re.findall(user_id_pattern, script_content)
|
||||
if matches:
|
||||
return ''.join(matches)
|
||||
concat_pattern = r'\/api\/\w+\/"(?:\.concat\("[^"]*"\))+'
|
||||
matches = re.findall(concat_pattern, script_content)
|
||||
if matches:
|
||||
parts = str(matches).split('.concat')
|
||||
cleaned_parts = [re.sub(r'["\(\)\[\]\']', '', part) for part in parts[1:]]
|
||||
return ''.join(cleaned_parts)
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _extract_search_url(script_content: str, api_key: str | None) -> str | None:
|
||||
if not api_key:
|
||||
return None
|
||||
pattern = re.compile(
|
||||
r'fetch\(\s*["\'](\/api\/[^"\']*)["\']'
|
||||
r'((?:\s*\.concat\(\s*["\']([^"\']*)["\']\s*\))+)'
|
||||
r'\s*,',
|
||||
re.DOTALL
|
||||
)
|
||||
for match in pattern.finditer(script_content):
|
||||
endpoint = match.group(1)
|
||||
concat_calls = match.group(2)
|
||||
concat_strings = re.findall(r'\.concat\(\s*["\']([^"\']*)["\']\s*\)', concat_calls)
|
||||
concatenated_str = ''.join(concat_strings)
|
||||
if concatenated_str == api_key:
|
||||
return endpoint
|
||||
return None
|
||||
token: str
|
||||
hp_key: str
|
||||
hp_val: str
|
||||
|
||||
class HTTPClient:
|
||||
"""HTTP client for HowLongToBeat API."""
|
||||
BASE_URL = 'https://howlongtobeat.com/'
|
||||
SEARCH_URL = BASE_URL + "api/s/"
|
||||
AUTH_URL = BASE_URL + "api/bleed/init"
|
||||
SEARCH_URL = BASE_URL + "api/bleed"
|
||||
|
||||
def __init__(self, timeout: int = 60):
|
||||
self.timeout = timeout
|
||||
@@ -89,67 +43,55 @@ class HTTPClient:
|
||||
if proxy_settings:
|
||||
self.session.proxies.update(proxy_settings)
|
||||
|
||||
def get_search_config(self, parse_all_scripts: bool = False) -> SearchConfig | None:
|
||||
def get_search_config(self) -> SearchConfig | None:
|
||||
try:
|
||||
response = self.session.get(self.BASE_URL, timeout=self.timeout)
|
||||
response = self.session.get(
|
||||
self.AUTH_URL,
|
||||
params={"t": int(time.time() * 1000)},
|
||||
timeout=self.timeout
|
||||
)
|
||||
response.raise_for_status()
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
scripts = soup.find_all('script', src=True)
|
||||
script_urls = []
|
||||
for script in scripts:
|
||||
if isinstance(script, Tag):
|
||||
src = script.get('src')
|
||||
if src is not None and isinstance(src, str):
|
||||
if parse_all_scripts or '_app-' in src:
|
||||
script_urls.append(src)
|
||||
for script_url in script_urls:
|
||||
full_url = self.BASE_URL + script_url
|
||||
script_response = self.session.get(full_url, timeout=self.timeout)
|
||||
if script_response.status_code == 200:
|
||||
config = APIKeyExtractor.extract_from_script(script_response.text)
|
||||
if config.api_key:
|
||||
return config
|
||||
except requests.RequestException:
|
||||
pass
|
||||
return None
|
||||
data = response.json()
|
||||
except (requests.RequestException, ValueError):
|
||||
return None
|
||||
if not data.get("token") or not data.get("hpKey") or not data.get("hpVal"):
|
||||
return None
|
||||
return SearchConfig(
|
||||
token=data["token"],
|
||||
hp_key=data["hpKey"],
|
||||
hp_val=data["hpVal"]
|
||||
)
|
||||
|
||||
def search_games(self, game_name: str, page: int = 1, config: SearchConfig | None = None) -> str | None:
|
||||
if not config:
|
||||
config = self.get_search_config()
|
||||
if not config:
|
||||
config = self.get_search_config(parse_all_scripts=True)
|
||||
if not config or not config.api_key:
|
||||
if not config:
|
||||
return None
|
||||
search_url = self.SEARCH_URL
|
||||
if config.search_url:
|
||||
search_url = self.BASE_URL + config.search_url.lstrip('/')
|
||||
payload = self._build_search_payload(game_name, page, config)
|
||||
headers = {
|
||||
'content-type': 'application/json',
|
||||
'accept': '*/*'
|
||||
}
|
||||
try:
|
||||
response = self.session.post(
|
||||
search_url + config.api_key,
|
||||
headers=headers,
|
||||
data=orjson.dumps(payload),
|
||||
timeout=self.timeout
|
||||
)
|
||||
for retry in range(2):
|
||||
payload = self._build_search_payload(game_name, page, config)
|
||||
headers = {
|
||||
'content-type': 'application/json',
|
||||
'accept': '*/*',
|
||||
'x-auth-token': config.token,
|
||||
'x-hp-key': config.hp_key,
|
||||
'x-hp-val': config.hp_val
|
||||
}
|
||||
try:
|
||||
response = self.session.post(
|
||||
self.SEARCH_URL,
|
||||
headers=headers,
|
||||
data=orjson.dumps(payload),
|
||||
timeout=self.timeout
|
||||
)
|
||||
except requests.RequestException:
|
||||
return None
|
||||
if response.status_code == 200:
|
||||
return response.text
|
||||
except requests.RequestException:
|
||||
pass
|
||||
try:
|
||||
response = self.session.post(
|
||||
search_url,
|
||||
headers=headers,
|
||||
data=orjson.dumps(payload),
|
||||
timeout=self.timeout
|
||||
)
|
||||
if response.status_code == 200:
|
||||
return response.text
|
||||
except requests.RequestException:
|
||||
pass
|
||||
if response.status_code != 403 or retry:
|
||||
return None
|
||||
config = self.get_search_config()
|
||||
if not config:
|
||||
return None
|
||||
return None
|
||||
|
||||
def _build_search_payload(self, game_name: str, page: int, config: SearchConfig) -> dict[str, Any]:
|
||||
@@ -171,8 +113,7 @@ class HTTPClient:
|
||||
'genre': "",
|
||||
"difficulty": ""
|
||||
},
|
||||
'rangeYear': {'max': "", 'min': ""},
|
||||
'modifier': "" # Hardcoded to empty string for SearchModifiers.NONE
|
||||
'rangeYear': {'max': "", 'min': ""}
|
||||
},
|
||||
'users': {'sortCategory': "postcount"},
|
||||
'lists': {'sortCategory': "follows"},
|
||||
@@ -181,42 +122,26 @@ class HTTPClient:
|
||||
'randomizer': 0
|
||||
},
|
||||
'useCache': True,
|
||||
'fields': ["game_id", "game_name", "comp_main", "comp_plus", "comp_100"] # Request only needed fields
|
||||
'fields': ["comp_main", "comp_plus", "comp_100"]
|
||||
}
|
||||
if config.api_key:
|
||||
payload['searchOptions']['users']['id'] = config.api_key
|
||||
payload[config.hp_key] = config.hp_val
|
||||
return payload
|
||||
|
||||
class ResultParser:
|
||||
"""Search results parser."""
|
||||
def __init__(self, search_query: str, minimum_similarity: float = 0.4, case_sensitive: bool = True):
|
||||
self.search_query = search_query
|
||||
self.minimum_similarity = minimum_similarity
|
||||
self.case_sensitive = case_sensitive
|
||||
self.search_numbers = self._extract_numbers(search_query)
|
||||
|
||||
def parse_results(self, json_response: str, target_game_id: int | None = None) -> list[GameEntry]:
|
||||
def parse_results(self, json_response: str) -> list[GameEntry]:
|
||||
try:
|
||||
data = orjson.loads(json_response)
|
||||
games = []
|
||||
# Only process the first result
|
||||
if data.get("data"):
|
||||
game_data = data["data"][0]
|
||||
game = self._parse_game_entry(game_data)
|
||||
if target_game_id is not None:
|
||||
if game.game_id == target_game_id:
|
||||
games.append(game)
|
||||
elif self.minimum_similarity == 0.0 or game.similarity >= self.minimum_similarity:
|
||||
games.append(game)
|
||||
games.append(self._parse_game_entry(game_data))
|
||||
return games
|
||||
except (orjson.JSONDecodeError, KeyError, IndexError):
|
||||
return []
|
||||
|
||||
def _parse_game_entry(self, game_data: dict[str, Any]) -> GameEntry:
|
||||
game = GameEntry()
|
||||
game.game_id = game_data.get("game_id", -1)
|
||||
game.game_name = game_data.get("game_name")
|
||||
game.raw_data = game_data
|
||||
time_fields = [
|
||||
("comp_main", "main_story"),
|
||||
("comp_plus", "main_extra"),
|
||||
@@ -228,35 +153,8 @@ class ResultParser:
|
||||
time_seconds = game_data[json_field]
|
||||
time_hours = None if all_zero else round(time_seconds / 3600, 2)
|
||||
setattr(game, attr_name, time_hours)
|
||||
game.similarity = self._calculate_similarity(game)
|
||||
return game
|
||||
|
||||
def _calculate_similarity(self, game: GameEntry) -> float:
|
||||
return self._compare_strings(self.search_query, game.game_name)
|
||||
|
||||
def _compare_strings(self, a: str | None, b: str | None) -> float:
|
||||
if not a or not b:
|
||||
return 0.0
|
||||
if self.case_sensitive:
|
||||
similarity = SequenceMatcher(None, a, b).ratio()
|
||||
else:
|
||||
similarity = SequenceMatcher(None, a.lower(), b.lower()).ratio()
|
||||
if self.search_numbers and not self._contains_numbers(b, self.search_numbers):
|
||||
similarity -= 0.1
|
||||
return max(0.0, similarity)
|
||||
|
||||
@staticmethod
|
||||
def _extract_numbers(text: str) -> list[str]:
|
||||
return [word for word in text.split() if word.isdigit()]
|
||||
|
||||
@staticmethod
|
||||
def _contains_numbers(text: str, numbers: list[str]) -> bool:
|
||||
if not numbers:
|
||||
return True
|
||||
cleaned_text = re.sub(r'([^\s\w]|_)+', '', text)
|
||||
text_numbers = [word for word in cleaned_text.split() if word.isdigit()]
|
||||
return any(num in text_numbers for num in numbers)
|
||||
|
||||
|
||||
class HowLongToBeat(QObject):
|
||||
"""Main class for HowLongToBeat API."""
|
||||
@@ -273,15 +171,13 @@ class HowLongToBeat(QObject):
|
||||
return self.cache_manager.load_text(f"hltb_{game_name}")
|
||||
|
||||
def _save_to_cache(self, game_name: str, json_response: str):
|
||||
"""Save data to cache, storing only first game and required fields."""
|
||||
"""Save data to cache, storing only first game times."""
|
||||
try:
|
||||
data = orjson.loads(json_response)
|
||||
if data.get("data"):
|
||||
first_game = data["data"][0]
|
||||
simplified_data = {
|
||||
"data": [{
|
||||
"game_id": first_game.get("game_id", -1),
|
||||
"game_name": first_game.get("game_name"),
|
||||
"comp_main": first_game.get("comp_main", 0),
|
||||
"comp_plus": first_game.get("comp_plus", 0),
|
||||
"comp_100": first_game.get("comp_100", 0)
|
||||
@@ -298,25 +194,8 @@ class HowLongToBeat(QObject):
|
||||
cached_response = self._load_from_cache(game_name)
|
||||
if cached_response:
|
||||
try:
|
||||
cached_data = orjson.loads(cached_response)
|
||||
full_json = {
|
||||
"data": [
|
||||
{
|
||||
"game_id": game["game_id"],
|
||||
"game_name": game["game_name"],
|
||||
"comp_main": game["comp_main"],
|
||||
"comp_plus": game["comp_plus"],
|
||||
"comp_100": game["comp_100"]
|
||||
}
|
||||
for game in cached_data.get("data", [])
|
||||
]
|
||||
}
|
||||
parser = ResultParser(
|
||||
game_name,
|
||||
self.minimum_similarity,
|
||||
case_sensitive
|
||||
)
|
||||
return parser.parse_results(orjson.dumps(full_json).decode('utf-8'))
|
||||
parser = ResultParser()
|
||||
return parser.parse_results(cached_response)
|
||||
except orjson.JSONDecodeError:
|
||||
pass
|
||||
# If not in cache, make request
|
||||
@@ -325,11 +204,7 @@ class HowLongToBeat(QObject):
|
||||
return None
|
||||
# Save only first game to cache
|
||||
self._save_to_cache(game_name, json_response)
|
||||
parser = ResultParser(
|
||||
game_name,
|
||||
self.minimum_similarity,
|
||||
case_sensitive
|
||||
)
|
||||
parser = ResultParser()
|
||||
return parser.parse_results(json_response)
|
||||
|
||||
def format_game_time(self, game_entry: GameEntry, time_field: str = "main_story") -> str | None:
|
||||
|
||||
@@ -31,6 +31,8 @@ logger = get_logger(__name__)
|
||||
AUTOINSTALL_CACHE_DURATION = 3600 # 1 hour for autoinstall cache
|
||||
HEAD_FAILURE_RETRY_DELAY = 60 # 1 minute cooldown for failed HEAD checks
|
||||
HEAD_CACHE_DURATION = 24 * 60 * 60
|
||||
HEAD_CACHE_NAME = "head_cache"
|
||||
HEAD_CACHE_OLD_PATTERN = "head_*.json"
|
||||
|
||||
|
||||
def _create_bootstrap_file_explorer_parent() -> tuple[QObject | None, Any]:
|
||||
@@ -116,6 +118,7 @@ class PortProtonAPI:
|
||||
self._head_positive_cache: set[str] = set()
|
||||
self._head_negative_cache: set[str] = set()
|
||||
self._head_failure_cache: dict[str, float] = {}
|
||||
self._head_disk_cache_cleaned = False
|
||||
self._pending_asset_notifier: QObject | None = None
|
||||
self._pending_asset_batch_thread: QThread | None = None
|
||||
|
||||
@@ -124,6 +127,38 @@ class PortProtonAPI:
|
||||
os.makedirs(game_dir, exist_ok=True)
|
||||
return game_dir
|
||||
|
||||
def _load_head_cache_entry(self, cache_manager: CacheManager, cache_key: str) -> bool | None:
|
||||
cached = cache_manager.load_json(HEAD_CACHE_NAME)
|
||||
if not isinstance(cached, dict):
|
||||
return None
|
||||
entry = cached.get(cache_key)
|
||||
if not isinstance(entry, dict):
|
||||
return None
|
||||
timestamp = entry.get("timestamp")
|
||||
if not isinstance(timestamp, int | float):
|
||||
return None
|
||||
if time.time() - timestamp > HEAD_CACHE_DURATION:
|
||||
return None
|
||||
return entry.get("exists") is True
|
||||
|
||||
def _save_head_cache_entry(self, cache_manager: CacheManager, cache_key: str, exists: bool) -> None:
|
||||
cached = cache_manager.load_json(HEAD_CACHE_NAME)
|
||||
if not isinstance(cached, dict):
|
||||
cached = {}
|
||||
cached[cache_key] = {"exists": exists, "timestamp": time.time()}
|
||||
cache_manager.save_json(HEAD_CACHE_NAME, cached)
|
||||
self._remove_old_head_cache_files(cache_manager)
|
||||
|
||||
def _remove_old_head_cache_files(self, cache_manager: CacheManager) -> None:
|
||||
if self._head_disk_cache_cleaned:
|
||||
return
|
||||
for cache_file in cache_manager.cache_dir.glob(HEAD_CACHE_OLD_PATTERN):
|
||||
try:
|
||||
cache_file.unlink()
|
||||
except OSError as e:
|
||||
logger.debug("Failed to remove old HEAD cache %s: %s", cache_file, e)
|
||||
self._head_disk_cache_cleaned = True
|
||||
|
||||
def _check_file_exists(self, url: str, timeout: int = 5) -> bool:
|
||||
if url in self._head_negative_cache:
|
||||
return False
|
||||
@@ -134,11 +169,10 @@ class PortProtonAPI:
|
||||
return False
|
||||
|
||||
cache_manager = CacheManager()
|
||||
cache_key = f"head_{hashlib.sha256(url.encode('utf-8')).hexdigest()}"
|
||||
if cache_manager.is_fresh(cache_key, HEAD_CACHE_DURATION):
|
||||
cached = cache_manager.load_json(cache_key)
|
||||
if isinstance(cached, dict):
|
||||
return cached.get("exists") is True
|
||||
cache_key = hashlib.sha256(url.encode('utf-8')).hexdigest()
|
||||
cached_exists = self._load_head_cache_entry(cache_manager, cache_key)
|
||||
if cached_exists is not None:
|
||||
return cached_exists
|
||||
|
||||
try:
|
||||
session = get_requests_session()
|
||||
@@ -147,13 +181,13 @@ class PortProtonAPI:
|
||||
self._head_negative_cache.add(url)
|
||||
self._head_positive_cache.discard(url)
|
||||
self._head_failure_cache.pop(url, None)
|
||||
cache_manager.save_json(cache_key, {"exists": False})
|
||||
self._save_head_cache_entry(cache_manager, cache_key, False)
|
||||
return False
|
||||
response.raise_for_status()
|
||||
if response.status_code == 200:
|
||||
self._head_positive_cache.add(url)
|
||||
self._head_failure_cache.pop(url, None)
|
||||
cache_manager.save_json(cache_key, {"exists": True})
|
||||
self._save_head_cache_entry(cache_manager, cache_key, True)
|
||||
return True
|
||||
return False
|
||||
except requests.RequestException as e:
|
||||
|
||||
+1
-2
@@ -24,9 +24,7 @@ classifiers = [
|
||||
]
|
||||
dependencies = [
|
||||
"babel>=2.18.0",
|
||||
"beautifulsoup4>=4.14.3",
|
||||
"evdev>=1.9.3",
|
||||
"icoextract>=0.2.0",
|
||||
"libarchive-c>=5.3",
|
||||
"orjson>=3.11.8",
|
||||
"pillow>=12.2.0",
|
||||
@@ -40,6 +38,7 @@ dependencies = [
|
||||
"websocket-client>=1.9.0",
|
||||
"dbus-fast>=4.0.4",
|
||||
"pygame>=2.6.1",
|
||||
"pefile>=2024.8.26",
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
|
||||
@@ -15,19 +15,6 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/77/f5/21d2de20e8b8b0408f0681956ca2c69f1320a3848ac50e6e7f39c6159675/babel-2.18.0-py3-none-any.whl", hash = "sha256:e2b422b277c2b9a9630c1d7903c2a00d0830c409c59ac8cae9081c92f1aeba35", size = 10196845, upload-time = "2026-02-01T12:30:53.445Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "beautifulsoup4"
|
||||
version = "4.14.3"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "soupsieve" },
|
||||
{ name = "typing-extensions" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/c3/b0/1c6a16426d389813b48d95e26898aff79abbde42ad353958ad95cc8c9b21/beautifulsoup4-4.14.3.tar.gz", hash = "sha256:6292b1c5186d356bba669ef9f7f051757099565ad9ada5dd630bd9de5fa7fb86", size = 627737, upload-time = "2025-11-30T15:08:26.084Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/1a/39/47f9197bdd44df24d67ac8893641e16f386c984a0619ef2ee4c51fbbc019/beautifulsoup4-4.14.3-py3-none-any.whl", hash = "sha256:0918bfe44902e6ad8d57732ba310582e98da931428d231a5ecb9e7c703a735bb", size = 107721, upload-time = "2025-11-30T15:08:24.087Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "certifi"
|
||||
version = "2025.11.12"
|
||||
@@ -207,15 +194,6 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/e3/7f/a1a97644e39e7316d850784c642093c99df1290a460df4ede27659056834/filelock-3.20.1-py3-none-any.whl", hash = "sha256:15d9e9a67306188a44baa72f569d2bfd803076269365fdea0934385da4dc361a", size = 16666, upload-time = "2025-12-15T23:54:26.874Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "icoextract"
|
||||
version = "0.2.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "pefile" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/cc/a9/4653791ae2356f981ea3597a1ace0d04fef622071209a4613bf56abd0264/icoextract-0.2.0.tar.gz", hash = "sha256:e7b4770c9a927a48ecfccc4ecd35afe477c2565a71449f92a95bdc92a0d10043", size = 10949, upload-time = "2025-06-03T04:17:37.464Z" }
|
||||
|
||||
[[package]]
|
||||
name = "identify"
|
||||
version = "2.6.15"
|
||||
@@ -455,12 +433,11 @@ version = "0.1.12"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "babel" },
|
||||
{ name = "beautifulsoup4" },
|
||||
{ name = "dbus-fast" },
|
||||
{ name = "evdev" },
|
||||
{ name = "icoextract" },
|
||||
{ name = "libarchive-c" },
|
||||
{ name = "orjson" },
|
||||
{ name = "pefile" },
|
||||
{ name = "pillow" },
|
||||
{ name = "psutil" },
|
||||
{ name = "pygame" },
|
||||
@@ -483,12 +460,11 @@ dev = [
|
||||
[package.metadata]
|
||||
requires-dist = [
|
||||
{ name = "babel", specifier = ">=2.18.0" },
|
||||
{ name = "beautifulsoup4", specifier = ">=4.14.3" },
|
||||
{ name = "dbus-fast", specifier = ">=4.0.4" },
|
||||
{ name = "evdev", specifier = ">=1.9.3" },
|
||||
{ name = "icoextract", specifier = ">=0.2.0" },
|
||||
{ name = "libarchive-c", specifier = ">=5.3" },
|
||||
{ name = "orjson", specifier = ">=3.11.8" },
|
||||
{ name = "pefile", specifier = ">=2024.8.26" },
|
||||
{ name = "pillow", specifier = ">=12.2.0" },
|
||||
{ name = "psutil", specifier = ">=7.2.2" },
|
||||
{ name = "pygame", specifier = ">=2.6.1" },
|
||||
@@ -854,15 +830,6 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/fb/99/6e5ee21db2d6af84bbbd7d871d441dafeb069c6de5667b1aa49891a77c66/shiboken6-6.11.0-cp310-abi3-win_arm64.whl", hash = "sha256:3bd76cf56105ab2d62ecaff630366f11264f69b88d488f10f048da9a065781f4", size = 1783186, upload-time = "2026-03-23T12:47:11.832Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "soupsieve"
|
||||
version = "2.8.1"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/89/23/adf3796d740536d63a6fbda113d07e60c734b6ed5d3058d1e47fc0495e47/soupsieve-2.8.1.tar.gz", hash = "sha256:4cf733bc50fa805f5df4b8ef4740fc0e0fa6218cf3006269afd3f9d6d80fd350", size = 117856, upload-time = "2025-12-18T13:50:34.655Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/48/f3/b67d6ea49ca9154453b6d70b34ea22f3996b9fa55da105a79d8732227adc/soupsieve-2.8.1-py3-none-any.whl", hash = "sha256:a11fe2a6f3d76ab3cf2de04eb339c1be5b506a8a47f2ceb6d139803177f85434", size = 36710, upload-time = "2025-12-18T13:50:33.267Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tqdm"
|
||||
version = "4.67.3"
|
||||
|
||||
Reference in new issue
Block a user