diff --git a/src/main/java/com/dostalgia/IgdbService.java b/src/main/java/com/dostalgia/IgdbService.java index 17514af..d2d0632 100644 --- a/src/main/java/com/dostalgia/IgdbService.java +++ b/src/main/java/com/dostalgia/IgdbService.java @@ -97,9 +97,8 @@ public class IgdbService { String apql = "search \"" + sanitize(query) + "\";" + " fields name,first_release_date,genres.name," + " involved_companies.company.name,involved_companies.developer,involved_companies.publisher," - + " summary,cover,platforms;" - + " where category = 0;" - + " limit 10;"; + + " summary,cover.url,platforms;" + + " limit 20;"; HttpRequest req = igdbRequest("/games") .POST(HttpRequest.BodyPublishers.ofString(apql)) @@ -107,12 +106,15 @@ public class IgdbService { HttpResponse res = http.send(req, HttpResponse.BodyHandlers.ofString()); if (res.statusCode() != 200) { - LOG.warning("IGDB search failed: HTTP " + res.statusCode()); + LOG.warning("IGDB search failed: HTTP " + res.statusCode() + " " + res.body()); return List.of(); } JsonNode results = mapper.readTree(res.body()); - if (!results.isArray()) return List.of(); + if (!results.isArray() || results.isEmpty()) { + LOG.info("IGDB search: no results for '" + query + "'. Response: " + res.body()); + return List.of(); + } List> out = new ArrayList<>(); for (JsonNode game : results) { @@ -167,9 +169,16 @@ public class IgdbService { entry.put("is_dos", isDos); } - // Cover URL (fetch from covers endpoint if ID is present) - if (game.has("cover") && game.get("cover").has("id")) { - int coverId = game.get("cover").get("id").asInt(); + // Cover URL — IGDB now returns cover as object with url (since we use cover.url in fields) + if (game.has("cover") && game.get("cover").has("url")) { + String thumbUrl = game.get("cover").get("url").asText(); + // IGDB URL format: //images.igdb.com/igdb/image/upload/t_thumb/co1x8h.jpg + // Replace t_thumb with our desired size + String coverUrl = "https:" + thumbUrl.replace("t_thumb", COVER_SIZE); + entry.put("cover_url", coverUrl); + } else if (game.has("cover") && game.get("cover").isInt()) { + // Fallback: cover is just an integer ID, fetch URL separately + int coverId = game.get("cover").asInt(); String coverUrl = fetchCoverUrl(coverId); if (coverUrl != null) { entry.put("cover_url", coverUrl); @@ -245,7 +254,7 @@ public class IgdbService { // Fetch game details from IGDB by ID String apql = "fields name,first_release_date,genres.name," + " involved_companies.company.name,involved_companies.developer,involved_companies.publisher," - + " summary,cover;" + + " summary,cover.url;" + " where id = " + igdbId + ";"; HttpRequest req = igdbRequest("/games") @@ -379,11 +388,21 @@ public class IgdbService { map.put("summary", node.get("summary").asText()); } - // Fetch cover URL - if (node.has("cover") && node.get("cover").has("id")) { + // Fetch cover URL — handle cover.url object or raw ID + if (node.has("cover")) { + JsonNode cover = node.get("cover"); try { - String coverUrl = fetchCoverUrl(node.get("cover").get("id").asInt()); - if (coverUrl != null) map.put("cover_url", coverUrl); + if (cover.has("url")) { + String thumbUrl = cover.get("url").asText(); + String coverUrl = "https:" + thumbUrl.replace("t_thumb", COVER_SIZE); + map.put("cover_url", coverUrl); + } else if (cover.isInt() || cover.isLong()) { + String coverUrl = fetchCoverUrl(cover.asInt()); + if (coverUrl != null) map.put("cover_url", coverUrl); + } else if (cover.has("id")) { + String coverUrl = fetchCoverUrl(cover.get("id").asInt()); + if (coverUrl != null) map.put("cover_url", coverUrl); + } } catch (Exception ignored) {} }