diff --git a/api.php b/api.php index 1e7e1a8..a6f0ea8 100644 --- a/api.php +++ b/api.php @@ -133,68 +133,53 @@ function fetchNotreCinema($title, $year = '', $ean = '', $pdo = null) { // ÉTAPE 1 : Recherche sur notrecinema.com $searchUrl = "https://www.notrecinema.com/communaute/stubs.php?stub=" . urlencode($cleanTitle); - if (!empty($year)) { - $searchUrl .= "&annee=" . $year; - } $searchRes = httpGet($searchUrl, 10, $userAgent); if ($searchRes) { - // Extraire le lien vers la page du film - if (preg_match('/]*>/i', $searchRes, $matches)) { - $filmSlug = $matches[1]; - $filmUrl = "https://www.notrecinema.com/communaute/stubs.php?stub=" . $filmSlug; + // Extraire l'ID du film et le slug + if (preg_match('/v1_detail_film\.php3\?lefilm=(\d+)/', $searchRes, $matches)) { + $filmId = $matches[1]; - $filmRes = httpGet($filmUrl, 10, $userAgent); + // Récupérer la page des jaquettes + $jaquettesUrl = "https://www.notrecinema.com/communaute/pdf/complete.php3?lefilm=" . $filmId; + $jaquettesRes = httpGet($jaquettesUrl, 10, $userAgent); - if ($filmRes) { - // Extraire l'image d'affiche - $posterUrl = null; - - // Chercher l'image principale du film - if (preg_match('/]*class="[^"]*affiche[^"]*"[^>]*src="([^"]+)"/i', $filmRes, $imgMatches)) { - $posterUrl = $imgMatches[1]; - } elseif (preg_match('/]*class="[^"]*film_affiche[^"]*"[^>]*>.*?]*src="([^"]+)"/is', $filmRes, $imgMatches)) { - $posterUrl = $imgMatches[1]; - } elseif (preg_match('/]*src="(https:\/\/www\.notrecinema\.com\/images\/films\/[^"]+)"/i', $filmRes, $imgMatches)) { - $posterUrl = $imgMatches[1]; - } - - if (!empty($posterUrl)) { - // S'assurer que l'URL est absolue - if (strpos($posterUrl, 'http') !== 0) { - $posterUrl = 'https://www.notrecinema.com' . $posterUrl; + if ($jaquettesRes) { + // Extraire les images de jaquettes (data-src des img.poster) + if (preg_match_all('/]*class=[\'"]poster[\'"][^>]*data-src=[\'"]([^\'"]+)[\'"][^>]*>/i', $jaquettesRes, $imgMatches)) { + if (!empty($imgMatches[1])) { + // Prendre la première jaquette disponible + $posterUrl = $imgMatches[1][0]; + + // Convertir en URL absolue si nécessaire + if (strpos($posterUrl, 'http') !== 0) { + $posterUrl = 'https://www.notrecinema.com' . $posterUrl; + } + + return [ + 'poster' => $posterUrl, + 'title' => $cleanTitle, + 'format' => 'Blu-ray' + ]; + } + } + + // Fallback : chercher dans le noscript + if (preg_match_all('/