Actualiser api.php
This commit is contained in:
@@ -25,8 +25,6 @@ try {
|
|||||||
$pdo->exec("CREATE TABLE IF NOT EXISTS videotheque (id BIGINT PRIMARY KEY, title VARCHAR(255) NOT NULL, year VARCHAR(10), director VARCHAR(255), poster TEXT, format VARCHAR(50), length VARCHAR(50), publisher VARCHAR(255), ean_isbn13 VARCHAR(50), number_of_discs INT DEFAULT 1, aspect_ratio VARCHAR(50), description TEXT, actors TEXT)");
|
$pdo->exec("CREATE TABLE IF NOT EXISTS videotheque (id BIGINT PRIMARY KEY, title VARCHAR(255) NOT NULL, year VARCHAR(10), director VARCHAR(255), poster TEXT, format VARCHAR(50), length VARCHAR(50), publisher VARCHAR(255), ean_isbn13 VARCHAR(50), number_of_discs INT DEFAULT 1, aspect_ratio VARCHAR(50), description TEXT, actors TEXT)");
|
||||||
try { $pdo->exec("ALTER TABLE videotheque ADD COLUMN actors TEXT AFTER description"); } catch (\Exception $e) {}
|
try { $pdo->exec("ALTER TABLE videotheque ADD COLUMN actors TEXT AFTER description"); } catch (\Exception $e) {}
|
||||||
|
|
||||||
try { $pdo->exec("DROP TABLE IF EXISTS cache_api"); } catch (\Exception $e) {}
|
|
||||||
|
|
||||||
} catch (\PDOException $e) { echo json_encode(["error" => "Erreur BDD : " . $e->getMessage()]); exit; }
|
} catch (\PDOException $e) { echo json_encode(["error" => "Erreur BDD : " . $e->getMessage()]); exit; }
|
||||||
|
|
||||||
// ── FONCTIONS UTILITAIRES ──
|
// ── FONCTIONS UTILITAIRES ──
|
||||||
@@ -117,33 +115,44 @@ function extractYear($dateStr) {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── CoverCentury.com (jaquettes HD pour vidéothèque) ──
|
// ── DVDcover.com (version française) ──
|
||||||
function fetchCoverCentury($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 CoverCentury
|
// Mapping des formats pour DVDcover
|
||||||
$formatMap = [
|
$formatMap = [
|
||||||
'4k ultra hd' => '4k',
|
'4k ultra hd' => '4k-ultra-hd',
|
||||||
'4k' => '4k',
|
'4k' => '4k-ultra-hd',
|
||||||
'blu-ray' => 'bluray',
|
'blu-ray' => 'blu-ray',
|
||||||
'bluray' => 'bluray',
|
'bluray' => 'blu-ray',
|
||||||
'dvd' => 'dvd',
|
'dvd' => 'dvd',
|
||||||
];
|
];
|
||||||
|
|
||||||
$ccFormat = $formatMap[strtolower($format)] ?? 'bluray';
|
$dcFormat = $formatMap[strtolower($format)] ?? 'blu-ray';
|
||||||
|
|
||||||
// URL de recherche CoverCentury
|
// Construction de l'URL de recherche
|
||||||
$searchUrl = "https://www.covercentury.com/search?q=" . urlencode($cleanTitle);
|
// DVDcover utilise des URLs comme : https://www.dvdcover.com/search/TITLE/year/FORMAT
|
||||||
|
$searchPath = str_replace(' ', '-', strtolower($cleanTitle));
|
||||||
|
$searchPath = preg_replace('/[^a-z0-9-]/', '', $searchPath);
|
||||||
|
|
||||||
|
$searchUrl = "https://www.dvdcover.com/{$dcFormat}/search/{$searchPath}";
|
||||||
if (!empty($year)) {
|
if (!empty($year)) {
|
||||||
$searchUrl .= "+(" . $year . ")";
|
$searchUrl .= "/{$year}";
|
||||||
}
|
}
|
||||||
|
|
||||||
$html = httpGet($searchUrl, 8, $ua);
|
$html = httpGet($searchUrl, 8, $ua);
|
||||||
|
|
||||||
|
// Fallback : essayer sans l'année
|
||||||
if (!$html) {
|
if (!$html) {
|
||||||
error_log("CoverCentury: Échec recherche pour '$title'");
|
$searchUrl = "https://www.dvdcover.com/{$dcFormat}/search/{$searchPath}";
|
||||||
|
$html = httpGet($searchUrl, 8, $ua);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$html) {
|
||||||
|
error_log("DVDCover: Échec recherche pour '$title' sur $searchUrl");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,42 +162,44 @@ function fetchCoverCentury($title, $year = '', $format = 'bluray') {
|
|||||||
'format' => $format,
|
'format' => $format,
|
||||||
];
|
];
|
||||||
|
|
||||||
// Extraction des liens d'images - CoverCentury utilise des structures spécifiques
|
// DVDcover structure les covers dans des divs spécifiques
|
||||||
// Chercher les liens vers les pages de covers
|
// Chercher les liens vers les pages de covers
|
||||||
preg_match_all('/href=["\']([^"\']*\/cover\/[^"\']+)["\']/i', $html, $coverLinks);
|
preg_match_all('/href=["\']([^"\']*\/covers?\/[^"\']+)["\']/i', $html, $coverLinks);
|
||||||
|
|
||||||
if (!empty($coverLinks[1])) {
|
if (!empty($coverLinks[1])) {
|
||||||
// Prendre le premier résultat pertinent
|
// Prendre le premier résultat
|
||||||
$coverPage = $coverLinks[1][0];
|
$coverPage = $coverLinks[1][0];
|
||||||
if (strpos($coverPage, 'http') !== 0) {
|
if (strpos($coverPage, 'http') !== 0) {
|
||||||
$coverPage = 'https://www.covercentury.com' . $coverPage;
|
$coverPage = 'https://www.dvdcover.com' . $coverPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Récupérer la page du cover pour avoir l'image en haute qualité
|
// 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 en haute résolution
|
// Chercher l'image principale (cover front)
|
||||||
if (preg_match('/<img[^>]+src=["\']([^"\']+\.jpg)["\'][^>]*class=["\'][^"\']*main[^"\']*["\']/i', $coverHtml, $m)) {
|
// DVDcover utilise des classes comme "cover-front", "cover-image"
|
||||||
|
if (preg_match('/<img[^>]+src=["\']([^"\']+\.jpg)["\'][^>]*class=["\'][^"\']*cover[^"\']*["\']/i', $coverHtml, $m)) {
|
||||||
$result['poster'] = $m[1];
|
$result['poster'] = $m[1];
|
||||||
} elseif (preg_match('/<meta[^>]+property=["\']og:image["\'][^>]+content=["\']([^"\']+)["\']/i', $coverHtml, $m)) {
|
} elseif (preg_match('/<meta[^>]+property=["\']og:image["\'][^>]+content=["\']([^"\']+)["\']/i', $coverHtml, $m)) {
|
||||||
$result['poster'] = $m[1];
|
$result['poster'] = $m[1];
|
||||||
} elseif (preg_match('/href=["\']([^"\']*\/images\/[^"\']+\.jpg)["\']/i', $coverHtml, $m)) {
|
} elseif (preg_match('/href=["\']([^"\']*\/images\/covers?\/[^"\']+\.jpg)["\']/i', $coverHtml, $m)) {
|
||||||
$result['poster'] = $m[1];
|
$result['poster'] = $m[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extraire le titre
|
// Extraire le titre
|
||||||
if (preg_match('/<title[^>]*>([^<]+) - CoverCentury/i', $coverHtml, $titleMatch)) {
|
if (preg_match('/<title[^>]*>([^<]+) - DVDCover/i', $coverHtml, $titleMatch)) {
|
||||||
$result['title'] = trim($titleMatch[1]);
|
$result['title'] = trim($titleMatch[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback : chercher directement les images dans la page de résultats
|
// Fallback : chercher directement dans la page de résultats
|
||||||
if (empty($result['poster'])) {
|
if (empty($result['poster'])) {
|
||||||
|
// Chercher les images de covers dans les résultats de recherche
|
||||||
preg_match_all('/<img[^>]+src=["\']([^"\']+\.jpg)["\'][^>]*>/i', $html, $imgMatches);
|
preg_match_all('/<img[^>]+src=["\']([^"\']+\.jpg)["\'][^>]*>/i', $html, $imgMatches);
|
||||||
if (!empty($imgMatches[1])) {
|
if (!empty($imgMatches[1])) {
|
||||||
foreach ($imgMatches[1] as $img) {
|
foreach ($imgMatches[1] as $img) {
|
||||||
if (strpos($img, 'covercentury') !== false || strpos($img, '/covers/') !== false) {
|
if (strpos($img, 'dvdcover') !== false || strpos($img, '/covers/') !== false) {
|
||||||
$result['poster'] = $img;
|
$result['poster'] = $img;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -346,7 +357,7 @@ switch ($action) {
|
|||||||
'length' => '', 'number_of_discs' => 1, 'aspect_ratio' => '', 'actors' => ''
|
'length' => '', 'number_of_discs' => 1, 'aspect_ratio' => '', 'actors' => ''
|
||||||
];
|
];
|
||||||
|
|
||||||
// Pour CoverCentury, on a besoin d'un titre
|
// Pour DVDcover, on a besoin d'un titre
|
||||||
$tmdbKey = getTmdbApiKey($pdo);
|
$tmdbKey = getTmdbApiKey($pdo);
|
||||||
$titleForSearch = '';
|
$titleForSearch = '';
|
||||||
|
|
||||||
@@ -372,12 +383,12 @@ switch ($action) {
|
|||||||
|
|
||||||
// Récupération jaquette
|
// Récupération jaquette
|
||||||
if ($type === 'videotheque') {
|
if ($type === 'videotheque') {
|
||||||
// CoverCentury pour vidéothèque
|
// DVDcover pour vidéothèque
|
||||||
$format = $result['format'] ?: 'Blu-ray';
|
$format = $result['format'] ?: 'Blu-ray';
|
||||||
$ccData = fetchCoverCentury($titleForSearch, $result['year'], $format);
|
$dcData = fetchDVDCover($titleForSearch, $result['year'], $format);
|
||||||
if (!empty($ccData)) {
|
if (!empty($dcData)) {
|
||||||
if (!empty($ccData['poster'])) $result['poster'] = $ccData['poster'];
|
if (!empty($dcData['poster'])) $result['poster'] = $dcData['poster'];
|
||||||
if (!empty($ccData['title'])) $result['title'] = $ccData['title'];
|
if (!empty($dcData['title'])) $result['title'] = $dcData['title'];
|
||||||
$result['format'] = $format;
|
$result['format'] = $format;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -420,12 +431,12 @@ switch ($action) {
|
|||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt->execute([$id, $data['title'] ?? '', $data['year'] ?? '', $data['director'] ?? '', $data['poster'] ?? '', $data['rating'] ?? 3.0, $data['review'] ?? '', $streaming]);
|
$stmt->execute([$id, $data['title'] ?? '', $data['year'] ?? '', $data['director'] ?? '', $data['poster'] ?? '', $data['rating'] ?? 3.0, $data['review'] ?? '', $streaming]);
|
||||||
} else {
|
} else {
|
||||||
// Vidéothèque : CoverCentury pour la jaquette
|
// Vidéothèque : DVDcover pour la jaquette
|
||||||
if (empty($data['poster']) && !empty($data['title'])) {
|
if (empty($data['poster']) && !empty($data['title'])) {
|
||||||
$format = $data['format'] ?: 'Blu-ray';
|
$format = $data['format'] ?: 'Blu-ray';
|
||||||
$ccData = fetchCoverCentury($data['title'], $data['year'] ?? '', $format);
|
$dcData = fetchDVDCover($data['title'], $data['year'] ?? '', $format);
|
||||||
if (!empty($ccData['poster'])) {
|
if (!empty($dcData['poster'])) {
|
||||||
$data['poster'] = $ccData['poster'];
|
$data['poster'] = $dcData['poster'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,7 +481,7 @@ switch ($action) {
|
|||||||
$id = makeStableId($type, $title, $year);
|
$id = makeStableId($type, $title, $year);
|
||||||
|
|
||||||
if ($type === 'videotheque') {
|
if ($type === 'videotheque') {
|
||||||
// ── VIDÉOTHÈQUE : CoverCentury pour jaquette HD ──
|
// ── VIDÉOTHÈQUE : DVDcover pour jaquette HD ──
|
||||||
$csvActors = $rowData['ensemble'] ?? $rowData['creators'] ?? '';
|
$csvActors = $rowData['ensemble'] ?? $rowData['creators'] ?? '';
|
||||||
$actors = '';
|
$actors = '';
|
||||||
if (!empty($csvActors)) {
|
if (!empty($csvActors)) {
|
||||||
@@ -502,16 +513,16 @@ switch ($action) {
|
|||||||
$poster = $rowData['poster'] ?? '';
|
$poster = $rowData['poster'] ?? '';
|
||||||
$director = '';
|
$director = '';
|
||||||
|
|
||||||
// Récupération jaquette via CoverCentury
|
// Récupération jaquette via DVDcover
|
||||||
$cleanTitleForCC = cleanTitle($title);
|
$cleanTitleForDC = cleanTitle($title);
|
||||||
if (!empty($cleanTitleForCC)) {
|
if (!empty($cleanTitleForDC)) {
|
||||||
$ccData = fetchCoverCentury($cleanTitleForCC, $year, $format);
|
$dcData = fetchDVDCover($cleanTitleForDC, $year, $format);
|
||||||
if (!empty($ccData)) {
|
if (!empty($dcData)) {
|
||||||
if (!empty($ccData['poster'])) {
|
if (!empty($dcData['poster'])) {
|
||||||
$poster = $ccData['poster'];
|
$poster = $dcData['poster'];
|
||||||
}
|
}
|
||||||
if (!empty($ccData['title']) && ($title === 'Sans titre' || empty($title))) {
|
if (!empty($dcData['title']) && ($title === 'Sans titre' || empty($title))) {
|
||||||
$title = $ccData['title'];
|
$title = $dcData['title'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -581,7 +592,7 @@ switch ($action) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'debug_covercentury':
|
case 'debug_dvdcover':
|
||||||
$title = $_GET['title'] ?? '';
|
$title = $_GET['title'] ?? '';
|
||||||
$year = $_GET['year'] ?? '';
|
$year = $_GET['year'] ?? '';
|
||||||
$format = $_GET['format'] ?? 'Blu-ray';
|
$format = $_GET['format'] ?? 'Blu-ray';
|
||||||
@@ -589,7 +600,7 @@ switch ($action) {
|
|||||||
if (!$title) { echo json_encode(['error' => 'Titre manquant']); exit; }
|
if (!$title) { echo json_encode(['error' => 'Titre manquant']); exit; }
|
||||||
|
|
||||||
$result = ['title' => $title, 'year' => $year, 'format' => $format];
|
$result = ['title' => $title, 'year' => $year, 'format' => $format];
|
||||||
$data = fetchCoverCentury($title, $year, $format);
|
$data = fetchDVDCover($title, $year, $format);
|
||||||
$result['data'] = $data;
|
$result['data'] = $data;
|
||||||
$result['status'] = $data ? 'OK' : 'AUCUN_RÉSULTAT';
|
$result['status'] = $data ? 'OK' : 'AUCUN_RÉSULTAT';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user