mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 10:07:48 -06:00
fix: retry site image and redump requests
fetch_site_images goes through fetch_bytes and the redump datfile HEAD through open_retrying: one 429 or reset no longer stops either.
This commit is contained in:
1 parent
837cc73937
commit
79e5eae036
2 files changed
+11
-10
No files matched your search
@@ -32,6 +32,7 @@ from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import contextlib
|
||||
import http.client
|
||||
import io
|
||||
import json
|
||||
import re
|
||||
@@ -1130,8 +1131,9 @@ def redump_datfile_version(code: str) -> str:
|
||||
gives the download: a HEAD request, nothing downloaded."""
|
||||
url = game_dat_importer.REDUMP_DATFILE_URL.format(code=code)
|
||||
request = urllib.request.Request(url, method="HEAD", headers={"User-Agent": "retrobios/1.0"})
|
||||
with urllib.request.urlopen(request, timeout=60) as response:
|
||||
disposition = response.headers.get("Content-Disposition", "")
|
||||
disposition = upstream.open_retrying(
|
||||
request, lambda response: response.headers.get("Content-Disposition", ""), timeout=60
|
||||
)
|
||||
named = game_dat_importer.DISPOSITION.search(disposition)
|
||||
match = game_dat_importer.REDUMP_FILE.match(named["file"]) if named else None
|
||||
if not match:
|
||||
@@ -1152,7 +1154,7 @@ def _check_redump_games(offline: bool) -> Finding:
|
||||
for code, (_name, system, _floor) in sorted(game_dat_importer.REDUMP_DATS.items()):
|
||||
try:
|
||||
remote = redump_datfile_version(code)
|
||||
except (OSError, ValueError) as exc:
|
||||
except (OSError, http.client.HTTPException, upstream.UpstreamError, ValueError) as exc:
|
||||
return Finding("catalogs", subject, UNKNOWN, local=newest, detail=str(exc))
|
||||
remote_newest = max(remote_newest, remote)
|
||||
if local.get(system) != remote:
|
||||
|
||||
@@ -29,13 +29,12 @@ import json
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
from model.registry import load_platform_registry
|
||||
from core.paths import PLATFORMS_DIR, REPO_ROOT
|
||||
from scraper.base_scraper import FetchError, fetch_bytes
|
||||
|
||||
sys.path.insert(0, str(REPO_ROOT / "scripts"))
|
||||
|
||||
@@ -47,9 +46,9 @@ AVATAR_HOST = "avatars.githubusercontent.com"
|
||||
USER_AGENT = "retrobios-site-images"
|
||||
|
||||
def fetch(url: str) -> bytes:
|
||||
request = urllib.request.Request(url, headers={"User-Agent": USER_AGENT})
|
||||
with urllib.request.urlopen(request, timeout=60) as response:
|
||||
return response.read()
|
||||
"""A GET retried on a rate limit or a dropped connection: one 429
|
||||
midway left icons rewritten under a sources.json of the previous run."""
|
||||
return fetch_bytes(url, {"User-Agent": USER_AGENT}, timeout=60)
|
||||
|
||||
|
||||
def square_image(data: bytes, size: int, kind: str = "PNG", flip: bool = False,
|
||||
@@ -212,8 +211,8 @@ def fetch_icons() -> None:
|
||||
url = f"{SYSTEM_ICON_BASE}/{urllib.parse.quote(name)}.png"
|
||||
try:
|
||||
data = fetch(url)
|
||||
except urllib.error.HTTPError as exc:
|
||||
if exc.code == 404:
|
||||
except FetchError as exc:
|
||||
if exc.status == 404:
|
||||
continue
|
||||
raise
|
||||
file_name = f"{name}.png"
|
||||
|
||||
Reference in new issue
Block a user