Actualiser api.php
This commit is contained in:
@@ -115,17 +115,17 @@ function extractYear($dateStr) {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── DVDcover.com (version française) ──
|
// ── DVDcover.com (version corrigée) ──
|
||||||
function fetchDVDCover($title, $year = '', $format = 'bluray') {
|
function fetchDVDCover($title, $year = '', $format = 'bluray') {
|
||||||
if (empty($title)) return null;
|
if (empty($title)) return null;
|
||||||
|
|
||||||
$ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
|
$ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
|
||||||
$cleanTitle = cleanTitle($title);
|
$cleanTitle = cleanTitle($title);
|
||||||
|
|
||||||
// Mapping des formats pour DVDcover
|
// Mapping des formats
|
||||||
$formatMap = [
|
$formatMap = [
|
||||||
'4k ultra hd' => '4k-ultra-hd',
|
'4k ultra hd' => '4k',
|
||||||
'4k' => '4k-ultra-hd',
|
'4k' => '4k',
|
||||||
'blu-ray' => 'blu-ray',
|
'blu-ray' => 'blu-ray',
|
||||||
'bluray' => 'blu-ray',
|
'bluray' => 'blu-ray',
|
||||||
'dvd' => 'dvd',
|
'dvd' => 'dvd',
|
||||||
@@ -133,26 +133,16 @@ function fetchDVDCover($title, $year = '', $format = 'bluray') {
|
|||||||
|
|
||||||
$dcFormat = $formatMap[strtolower($format)] ?? 'blu-ray';
|
$dcFormat = $formatMap[strtolower($format)] ?? 'blu-ray';
|
||||||
|
|
||||||
// Construction de l'URL de recherche
|
// Construction URL de recherche
|
||||||
// DVDcover utilise des URLs comme : https://www.dvdcover.com/search/TITLE/year/FORMAT
|
|
||||||
$searchPath = str_replace(' ', '-', strtolower($cleanTitle));
|
$searchPath = str_replace(' ', '-', strtolower($cleanTitle));
|
||||||
$searchPath = preg_replace('/[^a-z0-9-]/', '', $searchPath);
|
$searchPath = preg_replace('/[^a-z0-9-]/', '', $searchPath);
|
||||||
|
|
||||||
$searchUrl = "https://www.dvdcover.com/{$dcFormat}/search/{$searchPath}";
|
$searchUrl = "https://www.dvdcover.com/{$dcFormat}/search/{$searchPath}";
|
||||||
if (!empty($year)) {
|
|
||||||
$searchUrl .= "/{$year}";
|
|
||||||
}
|
|
||||||
|
|
||||||
$html = httpGet($searchUrl, 8, $ua);
|
$html = httpGet($searchUrl, 8, $ua);
|
||||||
|
|
||||||
// Fallback : essayer sans l'année
|
|
||||||
if (!$html) {
|
if (!$html) {
|
||||||
$searchUrl = "https://www.dvdcover.com/{$dcFormat}/search/{$searchPath}";
|
error_log("DVDCover: Échec recherche pour '$title'");
|
||||||
$html = httpGet($searchUrl, 8, $ua);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$html) {
|
|
||||||
error_log("DVDCover: Échec recherche pour '$title' sur $searchUrl");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,44 +152,59 @@ function fetchDVDCover($title, $year = '', $format = 'bluray') {
|
|||||||
'format' => $format,
|
'format' => $format,
|
||||||
];
|
];
|
||||||
|
|
||||||
// DVDcover structure les covers dans des divs spécifiques
|
// Chercher les liens vers les pages de covers individuelles
|
||||||
// Chercher les liens vers les pages de covers
|
// DVDcover utilise des URLs comme /covers/title-year-format/
|
||||||
preg_match_all('/href=["\']([^"\']*\/covers?\/[^"\']+)["\']/i', $html, $coverLinks);
|
if (preg_match_all('/href=["\']([^"\']*\/covers?\/[^"\']+\/[^"\']+)["\']/i', $html, $coverLinks)) {
|
||||||
|
foreach ($coverLinks[1] as $coverPage) {
|
||||||
if (!empty($coverLinks[1])) {
|
|
||||||
// Prendre le premier résultat
|
|
||||||
$coverPage = $coverLinks[1][0];
|
|
||||||
if (strpos($coverPage, 'http') !== 0) {
|
if (strpos($coverPage, 'http') !== 0) {
|
||||||
$coverPage = 'https://www.dvdcover.com' . $coverPage;
|
$coverPage = 'https://www.dvdcover.com' . $coverPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Récupérer la page du cover
|
|
||||||
$coverHtml = httpGet($coverPage, 8, $ua);
|
$coverHtml = httpGet($coverPage, 8, $ua);
|
||||||
if ($coverHtml) {
|
if ($coverHtml) {
|
||||||
// Chercher l'image principale (cover front)
|
// Chercher les images dans /wp-content/uploads/ (vraies jaquettes)
|
||||||
// DVDcover utilise des classes comme "cover-front", "cover-image"
|
// Ignorer les images de thème (/wp-content/themes/)
|
||||||
if (preg_match('/<img[^>]+src=["\']([^"\']+\.jpg)["\'][^>]*class=["\'][^"\']*cover[^"\']*["\']/i', $coverHtml, $m)) {
|
if (preg_match_all('/<img[^>]+src=["\']([^"\']*\/wp-content\/uploads\/[^"\']+\.jpg)["\'][^>]*>/i', $coverHtml, $imgMatches)) {
|
||||||
$result['poster'] = $m[1];
|
foreach ($imgMatches[1] as $img) {
|
||||||
} elseif (preg_match('/<meta[^>]+property=["\']og:image["\'][^>]+content=["\']([^"\']+)["\']/i', $coverHtml, $m)) {
|
// Filtrer pour ne garder que les images de covers (pas les logos, etc.)
|
||||||
$result['poster'] = $m[1];
|
if (strpos($img, '/covers/') !== false ||
|
||||||
} elseif (preg_match('/href=["\']([^"\']*\/images\/covers?\/[^"\']+\.jpg)["\']/i', $coverHtml, $m)) {
|
strpos($img, '/bluray/') !== false ||
|
||||||
$result['poster'] = $m[1];
|
strpos($img, '/dvd/') !== false ||
|
||||||
|
strpos($img, '/4k/') !== false) {
|
||||||
|
$result['poster'] = $img;
|
||||||
|
break 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback : chercher dans les balises meta og:image
|
||||||
|
if (empty($result['poster']) && preg_match('/<meta[^>]+property=["\']og:image["\'][^>]+content=["\']([^"\']+)["\']/i', $coverHtml, $m)) {
|
||||||
|
$ogImage = $m[1];
|
||||||
|
// Vérifier que ce n'est pas une image de thème
|
||||||
|
if (strpos($ogImage, '/wp-content/uploads/') !== false) {
|
||||||
|
$result['poster'] = $ogImage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extraire le titre
|
// Extraire le titre
|
||||||
if (preg_match('/<title[^>]*>([^<]+) - DVDCover/i', $coverHtml, $titleMatch)) {
|
if (empty($result['title']) && preg_match('/<title[^>]*>([^<]+) - DVDCover/i', $coverHtml, $titleMatch)) {
|
||||||
$result['title'] = trim($titleMatch[1]);
|
$result['title'] = trim($titleMatch[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($result['poster'])) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback : chercher directement dans la page de résultats
|
// Fallback ultime : chercher directement les images uploads dans la page de recherche
|
||||||
if (empty($result['poster'])) {
|
if (empty($result['poster'])) {
|
||||||
// Chercher les images de covers dans les résultats de recherche
|
if (preg_match_all('/<img[^>]+src=["\']([^"\']*\/wp-content\/uploads\/[^"\']+\.jpg)["\'][^>]*>/i', $html, $imgMatches)) {
|
||||||
preg_match_all('/<img[^>]+src=["\']([^"\']+\.jpg)["\'][^>]*>/i', $html, $imgMatches);
|
|
||||||
if (!empty($imgMatches[1])) {
|
|
||||||
foreach ($imgMatches[1] as $img) {
|
foreach ($imgMatches[1] as $img) {
|
||||||
if (strpos($img, 'dvdcover') !== false || strpos($img, '/covers/') !== false) {
|
if (strpos($img, '/covers/') !== false ||
|
||||||
|
strpos($img, '/bluray/') !== false ||
|
||||||
|
strpos($img, '/dvd/') !== false) {
|
||||||
$result['poster'] = $img;
|
$result['poster'] = $img;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user