From 2598c0397bef67c8b4de1b5a7ea6b8aa83ba9fa8 Mon Sep 17 00:00:00 2001 From: Jose Falanga Date: Mon, 17 Aug 2026 13:12:53 -0300 Subject: [PATCH 1/4] Cloudflare detection, cache failed scrapes, cover art fallback logging --- core/boxart_itch.gd | 13 +++++++++---- plugin.json | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/boxart_itch.gd b/core/boxart_itch.gd index 18f2292..a2be6c3 100644 --- a/core/boxart_itch.gd +++ b/core/boxart_itch.gd @@ -62,11 +62,12 @@ func get_boxart(item: LibraryItem, kind: LAYOUT) -> Texture2D: if meta.is_empty() and game.has("url"): logger.info("Enriching metadata for: %s (url=%s)" % [title, game.get("url", "")]) meta = _fetch_game_page_metadata(game) + # Cache even empty results to avoid re-scraping on every request. if meta.is_empty(): - logger.warn("Page scrape returned no metadata for: %s" % title) - else: - _enriched[game_id] = meta - _save_enriched_meta(game_id, meta) + meta = {"screenshots": []} + logger.info("Page scrape returned no screenshots for: %s (cached as empty)" % title) + _enriched[game_id] = meta + _save_enriched_meta(game_id, meta) elif not meta.is_empty(): logger.info("Using cached metadata for: %s (%d screenshots)" % [title, meta.get("screenshots", []).size()]) else: @@ -267,6 +268,10 @@ func _fetch_game_page_metadata(game: Dictionary) -> Dictionary: logger.warn("Empty HTML response for: " + page_url) return {} + if html.find("challenge-platform") != -1 or html.find("cf-browser-verification") != -1: + logger.warn("Cloudflare challenge detected for: " + page_url) + return {} + var shot_re := RegEx.new() shot_re.compile("https://img\\.itch\\.zone/aW1hZ2Uv[^\"]*/original/[^\"]*") var screenshots: Array = [] diff --git a/plugin.json b/plugin.json index c0e577f..407892b 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "plugin.id": "itch-artprovider", "plugin.name": "itch.io Art Provider", - "plugin.version": "0.1.4", + "plugin.version": "0.1.5", "plugin.min-api-version": "1.1.0", "plugin.link": "https://forge.thergic.ar/jose/itchio-opengamepadui-artprovider-plugin", "plugin.source": "https://forge.thergic.ar/jose/itchio-opengamepadui-artprovider-plugin", From 75f0463bc61c45473efa451c4f02b9fb174924c2 Mon Sep 17 00:00:00 2001 From: Jose Falanga Date: Wed, 19 Aug 2026 16:20:21 -0300 Subject: [PATCH 2/4] readability: extract magic constants - HTTP_TIMEOUT_MS for HTTP connection/request timeout - SCREENSHOT_REGEX_PATTERN for itch.io screenshot URL regex --- core/boxart_itch.gd | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/boxart_itch.gd b/core/boxart_itch.gd index 18f2292..ed93c72 100644 --- a/core/boxart_itch.gd +++ b/core/boxart_itch.gd @@ -12,6 +12,8 @@ extends BoxArtProvider const _boxart_dir := "user://boxart/itch" const _meta_cache_file := "itch_art_meta.json" +const HTTP_TIMEOUT_MS := 15000 +const SCREENSHOT_REGEX_PATTERN := "https://img\\.itch\\.zone/aW1hZ2Uv[^\"]*/original/[^\"]*" @export var use_caching: bool = true var http_image := HTTPImageFetcher.new() @@ -225,7 +227,7 @@ func _fetch_game_page_metadata(game: Dictionary) -> Dictionary: if err != OK: logger.warn("HTTP connect failed for %s: %d" % [page_url, err]) return {} - var deadline := Time.get_ticks_msec() + 15000 + var deadline := Time.get_ticks_msec() + HTTP_TIMEOUT_MS while http.get_status() == HTTPClient.STATUS_CONNECTING or http.get_status() == HTTPClient.STATUS_RESOLVING: http.poll() if Time.get_ticks_msec() > deadline: @@ -239,7 +241,7 @@ func _fetch_game_page_metadata(game: Dictionary) -> Dictionary: return {} http.request(HTTPClient.METHOD_GET, "/" + "/".join(parts.slice(3)), PackedStringArray()) - deadline = Time.get_ticks_msec() + 15000 + deadline = Time.get_ticks_msec() + HTTP_TIMEOUT_MS while http.get_status() == HTTPClient.STATUS_REQUESTING: http.poll() if Time.get_ticks_msec() > deadline: @@ -268,7 +270,7 @@ func _fetch_game_page_metadata(game: Dictionary) -> Dictionary: return {} var shot_re := RegEx.new() - shot_re.compile("https://img\\.itch\\.zone/aW1hZ2Uv[^\"]*/original/[^\"]*") + shot_re.compile(SCREENSHOT_REGEX_PATTERN) var screenshots: Array = [] for m in shot_re.search_all(html): var url: String = m.get_string(0) From e3281f7587374af9e21fe18961b306beff78141a Mon Sep 17 00:00:00 2001 From: Jose Falanga Date: Wed, 19 Aug 2026 16:41:33 -0300 Subject: [PATCH 3/4] readability: rename constants, extract poll intervals, remove dead code - BOXART_DIR, META_CACHE_FILE, _meta_cache_dir, _enriched_meta - _find_game_dict, _combine_side_by_side(left, right) - CONNECT_POLL_DELAY_MS, READ_POLL_DELAY_MS, LOG_URL_MAX_LEN - Remove dead _cover_url function - Fix fall-through comment, boxart_provider variable name --- core/boxart_itch.gd | 62 ++++++++++++++++++++------------------------- plugin.gd | 4 +-- 2 files changed, 29 insertions(+), 37 deletions(-) diff --git a/core/boxart_itch.gd b/core/boxart_itch.gd index ed93c72..e77ecd8 100644 --- a/core/boxart_itch.gd +++ b/core/boxart_itch.gd @@ -10,15 +10,18 @@ extends BoxArtProvider ## (the itch.io API does not expose them), caches the result in ## itch_art_meta.json, and uses HTTPImageFetcher for async image downloads. -const _boxart_dir := "user://boxart/itch" -const _meta_cache_file := "itch_art_meta.json" +const BOXART_DIR := "user://boxart/itch" +const META_CACHE_FILE := "itch_art_meta.json" const HTTP_TIMEOUT_MS := 15000 const SCREENSHOT_REGEX_PATTERN := "https://img\\.itch\\.zone/aW1hZ2Uv[^\"]*/original/[^\"]*" +const CONNECT_POLL_DELAY_MS := 50 +const READ_POLL_DELAY_MS := 10 +const LOG_URL_MAX_LEN := 80 @export var use_caching: bool = true var http_image := HTTPImageFetcher.new() -var _cache_dir := "itch_art" -var _enriched: Dictionary = {} +var _meta_cache_dir := "itch_art" +var _enriched_meta: Dictionary = {} var layout_map: Dictionary = { LAYOUT.GRID_PORTRAIT: "-portrait", @@ -30,14 +33,14 @@ var layout_map: Dictionary = { func _init() -> void: super() - DirAccess.make_dir_recursive_absolute(ProjectSettings.globalize_path(_boxart_dir)) + DirAccess.make_dir_recursive_absolute(ProjectSettings.globalize_path(BOXART_DIR)) provider_id = "itch" logger_name = "BoxArtItch" func _ready() -> void: super() - _enriched = _load_enriched_meta() + _enriched_meta = _load_enriched_meta() logger.info("itch.io Art Provider loaded") add_child(http_image) @@ -47,7 +50,7 @@ func get_boxart(item: LibraryItem, kind: LAYOUT) -> Texture2D: logger.error("Unsupported boxart layout: {0}".format([kind])) return null - var game := _itch_game(item) + var game := _find_game_dict(item) if game.is_empty(): logger.warn("No itch.io game metadata found for: " + item.name) return null @@ -60,14 +63,14 @@ func get_boxart(item: LibraryItem, kind: LAYOUT) -> Texture2D: return null # Enrich on first access: scrape the itch.io page for screenshots. - var meta: Dictionary = _enriched.get(game_id, {}) + var meta: Dictionary = _enriched_meta.get(game_id, {}) if meta.is_empty() and game.has("url"): logger.info("Enriching metadata for: %s (url=%s)" % [title, game.get("url", "")]) meta = _fetch_game_page_metadata(game) if meta.is_empty(): logger.warn("Page scrape returned no metadata for: %s" % title) else: - _enriched[game_id] = meta + _enriched_meta[game_id] = meta _save_enriched_meta(game_id, meta) elif not meta.is_empty(): logger.info("Using cached metadata for: %s (%d screenshots)" % [title, meta.get("screenshots", []).size()]) @@ -86,7 +89,7 @@ func get_boxart(item: LibraryItem, kind: LAYOUT) -> Texture2D: if cover_url.is_empty(): logger.warn("No cover URL for: %s (id=%d)" % [title, game_id]) return null - logger.info("cover_url=%s" % cover_url.left(80)) + logger.info("cover_url=%s" % cover_url.left(LOG_URL_MAX_LEN)) var cache_flags := Cache.FLAGS.NONE if use_caching: @@ -99,7 +102,7 @@ func get_boxart(item: LibraryItem, kind: LAYOUT) -> Texture2D: var tex_b := await http_image.fetch(non_gif_screenshots[1], cache_flags) if tex_a != null and tex_b != null: return _combine_side_by_side(tex_a, tex_b) - # Fall through to single-image path if either failed. + # Banner combine failed — fall back to single-image path. logger.warn("Banner screenshot fetch failed: tex_a=%s tex_b=%s" % [str(tex_a != null), str(tex_b != null)]) if tex_a != null: return tex_a @@ -111,15 +114,15 @@ func get_boxart(item: LibraryItem, kind: LAYOUT) -> Texture2D: logger.warn("URL for layout %s is empty (cover=%s)" % [str(kind), cover_url]) return null - logger.info("Fetching itch.io box art for: %s layout=%s url=%s" % [item.name, str(kind), url.left(80)]) + logger.info("Fetching itch.io box art for: %s layout=%s url=%s" % [item.name, str(kind), url.left(LOG_URL_MAX_LEN)]) var texture: Texture2D = await http_image.fetch(url, cache_flags) if texture == null: - logger.warn("Image download returned null for: %s url=%s" % [item.name, url.left(80)]) + logger.warn("Image download returned null for: %s url=%s" % [item.name, url.left(LOG_URL_MAX_LEN)]) return texture ## Finds the itch.io game dict from the library item's launch items. -func _itch_game(item: LibraryItem) -> Dictionary: +func _find_game_dict(item: LibraryItem) -> Dictionary: if item.launch_items.is_empty(): logger.warn("Item has no launch items: " + item.name) return {} @@ -156,17 +159,6 @@ func _url_for_layout(kind: LAYOUT, cover_url: String, screenshots: Array) -> Str return "" -func _cover_url(game: Dictionary) -> String: - var still: String = game.get("stillCoverUrl", "") - if not still.is_empty() and not still.to_lower().ends_with(".gif"): - return still - # stillCoverUrl is empty or is a GIF — prefer it if non-GIF alternatives - # aren't available, but log a warning. - if not still.is_empty(): - logger.debug("stillCoverUrl is a GIF, will try alternatives: " + still) - return game.get("coverUrl", "") - - ## Returns a non-GIF URL suitable for portrait/logo from the game data. ## Falls back through: stillCoverUrl → coverUrl (non-GIF) → first non-GIF ## screenshot. @@ -189,11 +181,11 @@ func _best_portrait_url(game: Dictionary, screenshots: Array) -> String: ## Combines two textures side-by-side into a single banner image. ## Both images are scaled to the same height, then placed left and right. -func _combine_side_by_side(a: Texture2D, b: Texture2D) -> Texture2D: - var img_a := a.get_image() - var img_b := b.get_image() +func _combine_side_by_side(left: Texture2D, right: Texture2D) -> Texture2D: + var img_a := left.get_image() + var img_b := right.get_image() if img_a == null or img_b == null: - return a + return left # Scale both to the same height (use the taller one). var target_h: int = max(img_a.get_height(), img_b.get_height()) @@ -234,7 +226,7 @@ func _fetch_game_page_metadata(game: Dictionary) -> Dictionary: http.close() logger.warn("HTTP connect timed out for: " + page_url) return {} - OS.delay_msec(50) + OS.delay_msec(CONNECT_POLL_DELAY_MS) if http.get_status() != HTTPClient.STATUS_CONNECTED: logger.warn("HTTP not connected for %s: status=%d" % [page_url, http.get_status()]) http.close() @@ -248,7 +240,7 @@ func _fetch_game_page_metadata(game: Dictionary) -> Dictionary: http.close() logger.warn("HTTP request timed out for: " + page_url) return {} - OS.delay_msec(10) + OS.delay_msec(READ_POLL_DELAY_MS) var body := PackedByteArray() while http.get_status() == HTTPClient.STATUS_BODY: @@ -259,7 +251,7 @@ func _fetch_game_page_metadata(game: Dictionary) -> Dictionary: http.close() logger.warn("HTTP body read timed out for: " + page_url) return {} - OS.delay_msec(10) + OS.delay_msec(READ_POLL_DELAY_MS) continue body.append_array(chunk) http.close() @@ -284,7 +276,7 @@ func _fetch_game_page_metadata(game: Dictionary) -> Dictionary: func _load_enriched_meta() -> Dictionary: - var raw: Variant = Cache.get_json(_cache_dir, _meta_cache_file) + var raw: Variant = Cache.get_json(_meta_cache_dir, META_CACHE_FILE) if typeof(raw) != TYPE_DICTIONARY: return {} var out := {} @@ -294,8 +286,8 @@ func _load_enriched_meta() -> Dictionary: func _save_enriched_meta(game_id: int, meta: Dictionary) -> void: - var raw: Variant = Cache.get_json(_cache_dir, _meta_cache_file) + var raw: Variant = Cache.get_json(_meta_cache_dir, META_CACHE_FILE) if typeof(raw) != TYPE_DICTIONARY: raw = {} raw[str(game_id)] = meta - Cache.save_json(_cache_dir, _meta_cache_file, raw) + Cache.save_json(_meta_cache_dir, META_CACHE_FILE, raw) diff --git a/plugin.gd b/plugin.gd index 4f8056f..a5a3459 100644 --- a/plugin.gd +++ b/plugin.gd @@ -10,6 +10,6 @@ var icon := preload("res://plugins/itch-artprovider/assets/itch.svg") func _ready() -> void: logger = Log.get_logger("ItchArt", Log.LEVEL.INFO) - var boxart: BoxArtProvider = load("res://plugins/itch-artprovider/core/boxart_itch.tscn").instantiate() - add_child(boxart) + var boxart_provider: BoxArtProvider = load("res://plugins/itch-artprovider/core/boxart_itch.tscn").instantiate() + add_child(boxart_provider) logger.info("itch.io Art Provider loaded") From d8426050986687f3ee172435c6b8300e6b7e40a8 Mon Sep 17 00:00:00 2001 From: Jose Falanga Date: Wed, 19 Aug 2026 16:42:25 -0300 Subject: [PATCH 4/4] Bump version to v0.1.5 --- plugin.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.json b/plugin.json index c0e577f..407892b 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "plugin.id": "itch-artprovider", "plugin.name": "itch.io Art Provider", - "plugin.version": "0.1.4", + "plugin.version": "0.1.5", "plugin.min-api-version": "1.1.0", "plugin.link": "https://forge.thergic.ar/jose/itchio-opengamepadui-artprovider-plugin", "plugin.source": "https://forge.thergic.ar/jose/itchio-opengamepadui-artprovider-plugin",