Actualiser api.php
This commit is contained in:
@@ -669,43 +669,130 @@ switch ($action) {
|
||||
}
|
||||
break;
|
||||
|
||||
case 'debug_dvdfr':
|
||||
checkAuth($pdo);
|
||||
$ean = $_GET['ean'] ?? '';
|
||||
if (!$ean) { echo json_encode(['error' => 'EAN manquant']); exit; }
|
||||
|
||||
$ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/124.0.0.0 Safari/537.36';
|
||||
|
||||
// Étape 1 : page de recherche
|
||||
$ch = curl_init('https://www.dvdfr.com/search/?q=' . urlencode($ean));
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10,
|
||||
CURLOPT_SSL_VERIFYPEER => false, CURLOPT_USERAGENT => $ua,
|
||||
CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => '',
|
||||
CURLOPT_HTTPHEADER => ['Accept-Language: fr-FR,fr;q=0.9'],
|
||||
]);
|
||||
$searchHtml = curl_exec($ch);
|
||||
$searchCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$searchFinal = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
|
||||
curl_close($ch);
|
||||
|
||||
// Extraire tous les liens .html
|
||||
preg_match_all('@href=["\']([^"\']+\.html)["\']@i', $searchHtml, $links);
|
||||
$allLinks = array_unique($links[1]);
|
||||
|
||||
// Chercher og:image dans la page de recherche
|
||||
preg_match('/<meta[^>]+property=["\']og:image["\'][^>]+content=["\']([^"\']+)["\']/i', $searchHtml, $ogSearch);
|
||||
|
||||
// Chercher toutes les <img>
|
||||
preg_match_all('/<img[^>]+src=["\']([^"\']+)["\'][^>]*>/i', $searchHtml, $allImgs);
|
||||
|
||||
echo json_encode([
|
||||
'search_http_code' => $searchCode,
|
||||
'search_final_url' => $searchFinal,
|
||||
'search_og_image' => $ogSearch[1] ?? null,
|
||||
'search_links_html' => array_slice($allLinks, 0, 20),
|
||||
'search_imgs' => array_slice($allImgs[1], 0, 15),
|
||||
'search_html_sample' => substr($searchHtml, 0, 3000),
|
||||
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
break;
|
||||
case 'debug_dvdfr':
|
||||
// 🔥 DEBUG SANS AUTHENTIFICATION (à supprimer après test)
|
||||
$ean = $_GET['ean'] ?? '';
|
||||
if (!$ean) { echo json_encode(['error' => 'EAN manquant']); exit; }
|
||||
|
||||
$result = ['ean' => $ean, 'steps' => []];
|
||||
|
||||
// Étape 1 : Recherche
|
||||
$ua = 'MonCinema/1.0 (collection privée; contact@moncineapp.fr)';
|
||||
$searchUrl = "https://www.dvdfr.com/api/search.php?gencode=" . urlencode($ean);
|
||||
$result['steps']['search_url'] = $searchUrl;
|
||||
|
||||
$ch = curl_init($searchUrl);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_TIMEOUT => 8,
|
||||
CURLOPT_CONNECTTIMEOUT => 5,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_USERAGENT => $ua,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTPHEADER => ['Accept: application/xml, text/xml, */*'],
|
||||
]);
|
||||
$res = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$curlError = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
$result['steps']['search'] = [
|
||||
'http_code' => $httpCode,
|
||||
'curl_error' => $curlError,
|
||||
'response_length' => strlen($res ?: ''),
|
||||
'response_preview' => substr($res ?: '', 0, 500)
|
||||
];
|
||||
|
||||
if (!$res || $httpCode !== 200) {
|
||||
$result['error'] = "Échec recherche HTTP $httpCode";
|
||||
echo json_encode($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Parser XML
|
||||
libxml_use_internal_errors(true);
|
||||
$xml = simplexml_load_string($res);
|
||||
$xmlErrors = libxml_get_errors();
|
||||
libxml_clear_errors();
|
||||
|
||||
if (!$xml) {
|
||||
$result['error'] = "XML invalide";
|
||||
$result['xml_errors'] = $xmlErrors;
|
||||
echo json_encode($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result['steps']['xml_structure'] = json_decode(json_encode($xml), true);
|
||||
|
||||
if (!isset($xml->dvd[0]->id)) {
|
||||
$result['error'] = "Pas de DVD trouvé dans la réponse";
|
||||
echo json_encode($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
$dvdId = (string)$xml->dvd[0]->id;
|
||||
$result['steps']['dvd_id'] = $dvdId;
|
||||
|
||||
// Étape 2 : Fiche complète
|
||||
$ficheUrl = "https://www.dvdfr.com/api/dvd.php?id=" . urlencode($dvdId);
|
||||
$result['steps']['fiche_url'] = $ficheUrl;
|
||||
|
||||
$ch2 = curl_init($ficheUrl);
|
||||
curl_setopt_array($ch2, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_TIMEOUT => 8,
|
||||
CURLOPT_CONNECTTIMEOUT => 5,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_USERAGENT => $ua,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTPHEADER => ['Accept: application/xml, text/xml, */*'],
|
||||
]);
|
||||
$res2 = curl_exec($ch2);
|
||||
$httpCode2 = curl_getinfo($ch2, CURLINFO_HTTP_CODE);
|
||||
$curlError2 = curl_error($ch2);
|
||||
curl_close($ch2);
|
||||
|
||||
$result['steps']['fiche'] = [
|
||||
'http_code' => $httpCode2,
|
||||
'curl_error' => $curlError2,
|
||||
'response_length' => strlen($res2 ?: ''),
|
||||
'response_preview' => substr($res2 ?: '', 0, 1000)
|
||||
];
|
||||
|
||||
if (!$res2 || $httpCode2 !== 200) {
|
||||
$result['error'] = "Échec fiche HTTP $httpCode2";
|
||||
echo json_encode($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
libxml_use_internal_errors(true);
|
||||
$fiche = simplexml_load_string($res2);
|
||||
libxml_clear_errors();
|
||||
|
||||
if (!$fiche || !isset($fiche->dvd[0])) {
|
||||
$result['error'] = "Fiche XML invalide";
|
||||
echo json_encode($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
$dvd = $fiche->dvd[0];
|
||||
$result['steps']['fiche_structure'] = json_decode(json_encode($dvd), true);
|
||||
|
||||
// Extraction finale
|
||||
$poster = '';
|
||||
if (isset($dvd->cover)) $poster = (string)$dvd->cover;
|
||||
if (empty($poster) && isset($dvd->covers->cover[0])) $poster = (string)$dvd->covers->cover[0];
|
||||
|
||||
$result['final'] = [
|
||||
'poster' => $poster,
|
||||
'publisher' => isset($dvd->editeur) ? (string)$dvd->editeur : '',
|
||||
'format' => isset($dvd->type) ? (string)$dvd->type : '',
|
||||
'length' => isset($dvd->duree) ? (string)$dvd->duree : '',
|
||||
'aspect' => isset($dvd->formatimage) ? (string)$dvd->formatimage : '',
|
||||
'discs' => isset($dvd->nbdisques) ? (string)$dvd->nbdisques : '',
|
||||
];
|
||||
|
||||
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
break;
|
||||
}
|
||||
Reference in New Issue
Block a user