forked from Mirrors/itch-dl
New Flag to force re-downloading cover/screenshots
This commit is contained in:
@@ -47,6 +47,8 @@ def parse_args() -> argparse.Namespace:
|
|||||||
help="directory to save results into (default: current working dir)")
|
help="directory to save results into (default: current working dir)")
|
||||||
parser.add_argument("--mirror-web", action="store_true",
|
parser.add_argument("--mirror-web", action="store_true",
|
||||||
help="try to fetch assets on game sites")
|
help="try to fetch assets on game sites")
|
||||||
|
parser.add_argument("--refresh-media", action="store_true",
|
||||||
|
help="force re-download cover images and screenshots (skips game files if already downloaded)")
|
||||||
parser.add_argument("--urls-only", action="store_true",
|
parser.add_argument("--urls-only", action="store_true",
|
||||||
help="print scraped game URLs without downloading them")
|
help="print scraped game URLs without downloading them")
|
||||||
parser.add_argument("--parallel", metavar="parallel", type=int, default=None,
|
parser.add_argument("--parallel", metavar="parallel", type=int, default=None,
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class Settings:
|
|||||||
|
|
||||||
download_to: str | None = None
|
download_to: str | None = None
|
||||||
mirror_web: bool = False
|
mirror_web: bool = False
|
||||||
|
refresh_media: bool = False
|
||||||
urls_only: bool = False
|
urls_only: bool = False
|
||||||
parallel: int = 1
|
parallel: int = 1
|
||||||
|
|
||||||
|
|||||||
@@ -259,12 +259,19 @@ class GameDownloader:
|
|||||||
|
|
||||||
paths: dict[str, str] = {k: os.path.join(download_path, v) for k, v in TARGET_PATHS.items()}
|
paths: dict[str, str] = {k: os.path.join(download_path, v) for k, v in TARGET_PATHS.items()}
|
||||||
|
|
||||||
if os.path.exists(paths["metadata"]) and skip_downloaded:
|
# Check if we should skip or only refresh media
|
||||||
|
game_already_downloaded = os.path.exists(paths["metadata"])
|
||||||
|
media_only_mode = game_already_downloaded and self.settings.refresh_media
|
||||||
|
|
||||||
|
if game_already_downloaded and skip_downloaded and not self.settings.refresh_media:
|
||||||
# As metadata is the final file we write, all the files
|
# As metadata is the final file we write, all the files
|
||||||
# should already be downloaded at this point.
|
# should already be downloaded at this point.
|
||||||
logging.info("Skipping already-downloaded game for URL: %s", url)
|
logging.info("Skipping already-downloaded game for URL: %s", url)
|
||||||
return DownloadResult(url, True, ["Game already downloaded."], [])
|
return DownloadResult(url, True, ["Game already downloaded."], [])
|
||||||
|
|
||||||
|
if media_only_mode:
|
||||||
|
logging.info("Refreshing media for already-downloaded game: %s", url)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logging.info("Downloading %s", url)
|
logging.info("Downloading %s", url)
|
||||||
r = self.client.get(url, append_api_key=False)
|
r = self.client.get(url, append_api_key=False)
|
||||||
@@ -293,6 +300,7 @@ class GameDownloader:
|
|||||||
external_urls = []
|
external_urls = []
|
||||||
errors = []
|
errors = []
|
||||||
|
|
||||||
|
if not media_only_mode:
|
||||||
try:
|
try:
|
||||||
os.makedirs(paths["files"], exist_ok=True)
|
os.makedirs(paths["files"], exist_ok=True)
|
||||||
for upload in game_uploads:
|
for upload in game_uploads:
|
||||||
@@ -384,17 +392,34 @@ class GameDownloader:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
file_name = os.path.basename(screenshot)
|
file_name = os.path.basename(screenshot)
|
||||||
|
screenshot_path = os.path.join(paths["screenshots"], file_name)
|
||||||
|
|
||||||
|
# Check if screenshot already exists and if we should skip or force re-download
|
||||||
|
screenshot_exists = os.path.exists(screenshot_path)
|
||||||
|
should_download_screenshot = not screenshot_exists or self.settings.refresh_media
|
||||||
|
|
||||||
|
if should_download_screenshot:
|
||||||
try:
|
try:
|
||||||
self.download_file(screenshot, os.path.join(paths["screenshots"], file_name), credentials={})
|
self.download_file(screenshot, screenshot_path, credentials={})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
errors.append(f"Screenshot download failed (this is not fatal): {e}")
|
errors.append(f"Screenshot download failed (this is not fatal): {e}")
|
||||||
|
else:
|
||||||
|
logging.debug("Screenshot '%s' already exists, skipping download", file_name)
|
||||||
|
|
||||||
cover_url = metadata.get("cover_url")
|
cover_url = metadata.get("cover_url")
|
||||||
if cover_url:
|
if cover_url:
|
||||||
|
cover_path = paths["cover"] + os.path.splitext(cover_url)[-1]
|
||||||
|
# Check if cover already exists and if we should skip or force re-download
|
||||||
|
cover_exists = os.path.exists(cover_path)
|
||||||
|
should_download_cover = not cover_exists or self.settings.refresh_media
|
||||||
|
|
||||||
|
if should_download_cover:
|
||||||
try:
|
try:
|
||||||
self.download_file(cover_url, paths["cover"] + os.path.splitext(cover_url)[-1], credentials={})
|
self.download_file(cover_url, cover_path, credentials={})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
errors.append(f"Cover art download failed (this is not fatal): {e}")
|
errors.append(f"Cover art download failed (this is not fatal): {e}")
|
||||||
|
else:
|
||||||
|
logging.debug("Cover already exists, skipping download")
|
||||||
|
|
||||||
with open(paths["site"], "wb") as f:
|
with open(paths["site"], "wb") as f:
|
||||||
f.write(site.prettify(encoding="utf-8"))
|
f.write(site.prettify(encoding="utf-8"))
|
||||||
|
|||||||
Reference in New Issue
Block a user