99 lines
4.0 KiB
PHP
99 lines
4.0 KiB
PHP
// ── DVDcover.com (version corrigée) ──
|
|
function fetchDVDCover($title, $year = '', $format = 'bluray') {
|
|
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';
|
|
$cleanTitle = cleanTitle($title);
|
|
|
|
// Mapping des formats
|
|
$formatMap = [
|
|
'4k ultra hd' => '4k',
|
|
'4k' => '4k',
|
|
'blu-ray' => 'blu-ray',
|
|
'bluray' => 'blu-ray',
|
|
'dvd' => 'dvd',
|
|
];
|
|
|
|
$dcFormat = $formatMap[strtolower($format)] ?? 'blu-ray';
|
|
|
|
// Construction URL de recherche
|
|
$searchPath = str_replace(' ', '-', strtolower($cleanTitle));
|
|
$searchPath = preg_replace('/[^a-z0-9-]/', '', $searchPath);
|
|
|
|
$searchUrl = "https://www.dvdcover.com/{$dcFormat}/search/{$searchPath}";
|
|
|
|
$html = httpGet($searchUrl, 8, $ua);
|
|
|
|
if (!$html) {
|
|
error_log("DVDCover: Échec recherche pour '$title'");
|
|
return null;
|
|
}
|
|
|
|
$result = [
|
|
'poster' => '',
|
|
'title' => '',
|
|
'format' => $format,
|
|
];
|
|
|
|
// Chercher les liens vers les pages de covers individuelles
|
|
// DVDcover utilise des URLs comme /covers/title-year-format/
|
|
if (preg_match_all('/href=["\']([^"\']*\/covers?\/[^"\']+\/[^"\']+)["\']/i', $html, $coverLinks)) {
|
|
foreach ($coverLinks[1] as $coverPage) {
|
|
if (strpos($coverPage, 'http') !== 0) {
|
|
$coverPage = 'https://www.dvdcover.com' . $coverPage;
|
|
}
|
|
|
|
$coverHtml = httpGet($coverPage, 8, $ua);
|
|
if ($coverHtml) {
|
|
// Chercher les images dans /wp-content/uploads/ (vraies jaquettes)
|
|
// Ignorer les images de thème (/wp-content/themes/)
|
|
if (preg_match_all('/<img[^>]+src=["\']([^"\']*\/wp-content\/uploads\/[^"\']+\.jpg)["\'][^>]*>/i', $coverHtml, $imgMatches)) {
|
|
foreach ($imgMatches[1] as $img) {
|
|
// Filtrer pour ne garder que les images de covers (pas les logos, etc.)
|
|
if (strpos($img, '/covers/') !== false ||
|
|
strpos($img, '/bluray/') !== false ||
|
|
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
|
|
if (empty($result['title']) && preg_match('/<title[^>]*>([^<]+) - DVDCover/i', $coverHtml, $titleMatch)) {
|
|
$result['title'] = trim($titleMatch[1]);
|
|
}
|
|
|
|
if (!empty($result['poster'])) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fallback ultime : chercher directement les images uploads dans la page de recherche
|
|
if (empty($result['poster'])) {
|
|
if (preg_match_all('/<img[^>]+src=["\']([^"\']*\/wp-content\/uploads\/[^"\']+\.jpg)["\'][^>]*>/i', $html, $imgMatches)) {
|
|
foreach ($imgMatches[1] as $img) {
|
|
if (strpos($img, '/covers/') !== false ||
|
|
strpos($img, '/bluray/') !== false ||
|
|
strpos($img, '/dvd/') !== false) {
|
|
$result['poster'] = $img;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return (!empty($result['poster'])) ? $result : null;
|
|
} |