From b37578a7905bfc1e5ef0fc2c484979340bd532ea Mon Sep 17 00:00:00 2001 From: Cedric Date: Mon, 22 Jun 2026 09:22:05 +0200 Subject: [PATCH] Actualiser api.php --- api.php | 60 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/api.php b/api.php index d754eba..68ba4e1 100644 --- a/api.php +++ b/api.php @@ -81,41 +81,67 @@ function fetchPosterByEAN($ean, $pdo) { $cached = getCache($pdo, $cacheKey); if ($cached && !empty($cached['poster'])) return $cached['poster']; - // 1. UPCitemDB (Pas de clé nécessaire, version trial) + // 1. UPCitemDB (Toujours présent comme base gratuite, sans clé) $upcData = fetchUPCitemdb($ean, $pdo); if ($upcData && !empty($upcData['poster'])) { setCache($pdo, $cacheKey, ['poster' => $upcData['poster']], 'upc'); return $upcData['poster']; } - // 2. EAN-Search API - $eanSearchKey = getConfigValue($pdo, 'ean_search_key'); - if ($eanSearchKey) { - $url = "https://api.ean-search.org/api?token={$eanSearchKey}&op=barcode-lookup&ean={$ean}&format=json"; + // 2. eBay Developers Program (Finding API) + $ebayKey = getConfigValue($pdo, 'ebay_api_key'); + if ($ebayKey) { + $url = "https://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&SECURITY-APPNAME={$ebayKey}&RESPONSE-DATA-FORMAT=JSON&REST-PAYLOAD&keywords={$ean}"; $res = httpGet($url, 5); if ($res) { $data = json_decode($res, true); - if (!empty($data[0]['imageUrl'])) { - setCache($pdo, $cacheKey, ['poster' => $data[0]['imageUrl']], 'ean_search'); - return $data[0]['imageUrl']; + // On récupère l'image du premier résultat trouvé correspondant au code barre + if (!empty($data['findItemsByKeywordsResponse'][0]['searchResult'][0]['item'][0]['galleryURL'][0])) { + $img = $data['findItemsByKeywordsResponse'][0]['searchResult'][0]['item'][0]['galleryURL'][0]; + // eBay retourne parfois une image par défaut si non trouvée + if (strpos($img, 'default') === false) { + setCache($pdo, $cacheKey, ['poster' => $img], 'ebay'); + return $img; + } } } } - // 3. Barcode Lookup API - $blKey = getConfigValue($pdo, 'barcode_lookup_key'); - if ($blKey) { - $url = "https://api.barcodelookup.com/v3/products?barcode={$ean}&key={$blKey}&formatted=y"; + // 3. WorldCat APIs (xID / Search API) + $worldcatKey = getConfigValue($pdo, 'worldcat_api_key'); + if ($worldcatKey) { + // WorldCat est principalement pour les livres (ISBN), utile pour les Digibooks ou éditions spéciales + $url = "https://worldcat.org/webservices/catalog/content/isbn/{$ean}?wskey={$worldcatKey}"; $res = httpGet($url, 5); if ($res) { - $data = json_decode($res, true); - if (!empty($data['products'][0]['images'][0])) { - setCache($pdo, $cacheKey, ['poster' => $data['products'][0]['images'][0]], 'barcode_lookup'); - return $data['products'][0]['images'][0]; - } + // Logique de parsing XML à implémenter selon la structure de réponse WorldCat + // Si une couverture est trouvée : + // setCache($pdo, $cacheKey, ['poster' => $img], 'worldcat'); + // return $img; } } + // 4. Amazon Product Advertising API (PA-API 5.0) + $amazonKey = getConfigValue($pdo, 'amazon_api_key'); + if ($amazonKey) { + // Note: L'API Amazon requiert une signature AWS V4 (clé d'accès + clé secrète). + // Voici la structure cible de l'appel pour rechercher par EAN (Keywords) + $url = "https://webservices.amazon.fr/paapi5/searchitems"; + + // Pseudo-requête de démonstration + // Il faudrait utiliser un SDK AWS ou une fonction de signature HMAC-SHA256 ici + $payload = json_encode([ + "Keywords" => $ean, + "Resources" => ["Images.Primary.Large"], + "PartnerTag" => "moncinema-21", + "PartnerType" => "Associates", + "Marketplace" => "www.amazon.fr" + ]); + + // Simulation d'une réponse valide + // if ($response && !empty($data['SearchResult']['Items'][0]['Images']['Primary']['Large']['URL'])) { ... } + } + return null; }