Actualiser api.php
This commit is contained in:
@@ -517,7 +517,7 @@ function fetchFromBlurayCom($ean) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ── FONCTION POUR RÉCUPÉRER LES DONNÉES DEPUIS MOVIECOVERS.COM ──
|
// ── FONCTION POUR RÉCUPÉRER LES DONNÉES DEPUIS MOVIECOVERS.COM ──
|
||||||
function fetchFromMovieCovers($title, $year = '') {
|
function fetchFromMovieCovers($title) {
|
||||||
$empty = [
|
$empty = [
|
||||||
'title' => '', 'year' => '', 'director' => '', 'actors' => '',
|
'title' => '', 'year' => '', 'director' => '', 'actors' => '',
|
||||||
'poster' => '', 'description' => '', 'length' => '',
|
'poster' => '', 'description' => '', 'length' => '',
|
||||||
@@ -527,106 +527,55 @@ function fetchFromMovieCovers($title, $year = '') {
|
|||||||
|
|
||||||
if (empty($title)) return $empty;
|
if (empty($title)) return $empty;
|
||||||
|
|
||||||
// Nettoyer le titre pour la recherche
|
// Nettoyer le titre pour l'URL
|
||||||
$searchTitle = trim($title);
|
$urlTitle = strtoupper(str_replace(' ', '+', $title));
|
||||||
$searchTitle = preg_replace('/\s*[\[\(].*?[\]\)]\s*/', '', $searchTitle); // Enlever [Blu-ray], (2015), etc.
|
$url = "https://moviecovers.com/film/titre_{$urlTitle}.html";
|
||||||
$searchTitle = preg_replace('/\s*-\s*(Édition|Edition|Collector|Simple|Spéciale|Digibook|Ultimate|Intégrale|Combo|SteelBook|Boîtier).*$/i', '', $searchTitle);
|
|
||||||
$searchTitle = preg_replace('/(blu-ray|bluray|dvd|4k|ultra hd|combo|vhs|bdrip).*$/i', '', $searchTitle);
|
|
||||||
$searchTitle = trim(preg_replace('/\s{2,}/', ' ', $searchTitle));
|
|
||||||
|
|
||||||
if (empty($searchTitle)) return $empty;
|
$html = httpGet($url, 10);
|
||||||
|
if (!$html) return $empty;
|
||||||
|
|
||||||
error_log("MovieCovers: 🔍 Recherche de '$searchTitle'");
|
// Extraire le titre
|
||||||
|
if (preg_match('/<TITLE>([^<]+)<\/TITLE>/i', $html, $m)) {
|
||||||
// ÉTAPE 1 : Recherche du film via l'URL de recherche
|
|
||||||
$searchUrl = "https://moviecovers.com/multicrit.html?titre=" . urlencode($searchTitle) . "&slow=1&listes=1";
|
|
||||||
$html = httpGet($searchUrl, 10);
|
|
||||||
|
|
||||||
if (!$html) {
|
|
||||||
error_log("MovieCovers: ❌ Échec de la recherche");
|
|
||||||
return $empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extraire le lien vers la page du film
|
|
||||||
// Format : <a href="/film/titre_SAW.html">SAW</a>
|
|
||||||
if (!preg_match('/href=["\']?\/film\/titre_([^"\'\s]+)\.html["\']?/i', $html, $matches)) {
|
|
||||||
error_log("MovieCovers: ❌ Film non trouvé pour '$searchTitle'");
|
|
||||||
return $empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
$filmId = $matches[1];
|
|
||||||
$filmUrl = "https://moviecovers.com/film/titre_{$filmId}.html";
|
|
||||||
|
|
||||||
error_log("MovieCovers: ✅ Film trouvé → $filmUrl");
|
|
||||||
|
|
||||||
// ÉTAPE 2 : Récupérer la page du film
|
|
||||||
$filmHtml = httpGet($filmUrl, 10);
|
|
||||||
if (!$filmHtml) {
|
|
||||||
error_log("MovieCovers: ❌ Impossible de charger la page du film");
|
|
||||||
return $empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ÉTAPE 3 : Extraire les informations
|
|
||||||
|
|
||||||
// Titre (via og:title)
|
|
||||||
if (preg_match('/<meta property="og:title" content="([^"]+)"/i', $filmHtml, $m)) {
|
|
||||||
$empty['title'] = trim($m[1]);
|
$empty['title'] = trim($m[1]);
|
||||||
} else {
|
|
||||||
$empty['title'] = $searchTitle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IDMC (via og:image ou PRE)
|
// Extraire l'affiche
|
||||||
$idmc = null;
|
if (preg_match('/<img[^>]*src="(https:\/\/moviecovers\.com\/DATA\/thumbs\/[^"]+)"[^>]*title="Recto/i', $html, $m)) {
|
||||||
if (preg_match('/<meta property="og:image" content="[^"]*\/getjpg\.html\/([^"\'\/]+)\.jpg"/i', $filmHtml, $m)) {
|
$empty['poster'] = $m[1];
|
||||||
$idmc = urldecode($m[1]);
|
} elseif (preg_match('/<meta[^>]*property="og:image"[^>]*content="([^"]+)"/i', $html, $m)) {
|
||||||
} elseif (preg_match('/IDMC.*?<PRE>([^<]+)<\/PRE>/is', $filmHtml, $m)) {
|
$empty['poster'] = $m[1];
|
||||||
$idmc = trim($m[1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$idmc) {
|
// Extraire le réalisateur
|
||||||
error_log("MovieCovers: ❌ IDMC non trouvé");
|
if (preg_match('/Réalisateur<\/TH>\s*<TD[^>]*>.*?<a[^>]*>([^<]+)<\/a>/is', $html, $m)) {
|
||||||
return $empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
// URL de la cover (haute qualité)
|
|
||||||
$idmcEncoded = urlencode($idmc);
|
|
||||||
$empty['poster'] = "https://moviecovers.com/DATA/zipcache/{$idmcEncoded}.jpg";
|
|
||||||
|
|
||||||
// Année
|
|
||||||
if (preg_match('/<TH[^>]*>Ann[^<]*e<\/TH>\s*<TD[^>]*>.*?(\d{4})/is', $filmHtml, $m)) {
|
|
||||||
$empty['year'] = $m[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Durée
|
|
||||||
if (preg_match('/<TH[^>]*>Dur[^<]*e<\/TH>\s*<TD[^>]*>([^<]+)/is', $filmHtml, $m)) {
|
|
||||||
$empty['length'] = trim(strip_tags($m[1]));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Réalisateur
|
|
||||||
if (preg_match('/<TH[^>]*>R[^<]*alisateur<\/TH>\s*<TD[^>]*>.*?<a[^>]*>([^<]+)<\/a>/is', $filmHtml, $m)) {
|
|
||||||
$empty['director'] = trim($m[1]);
|
$empty['director'] = trim($m[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Acteurs (extraire tous les liens dans la section acteurs)
|
// Extraire l'année
|
||||||
if (preg_match('/<TH[^>]*>Acteurs[^<]*<\/TH>\s*<TD[^>]*>(.*?)<\/TD>/is', $filmHtml, $m)) {
|
if (preg_match('/Année<\/TH>\s*<TD[^>]*>.*?<a[^>]*>(\d{4})<\/a>/is', $html, $m)) {
|
||||||
$actorsHtml = $m[1];
|
$empty['year'] = $m[1];
|
||||||
preg_match_all('/<a[^>]*>([^<]+)<\/a>/i', $actorsHtml, $actorMatches);
|
|
||||||
if (!empty($actorMatches[1])) {
|
|
||||||
$empty['actors'] = implode(', ', array_map('trim', array_slice($actorMatches[1], 0, 5)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis (via og:description)
|
// Extraire la durée
|
||||||
if (preg_match('/<meta property="og:description" content="([^"]+)"/i', $filmHtml, $m)) {
|
if (preg_match('/Durée<\/TH>\s*<TD[^>]*>([\dH]+[\dmin]*)/is', $html, $m)) {
|
||||||
$empty['description'] = html_entity_decode($m[1], ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
$empty['length'] = trim($m[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Distribution (éditeur)
|
// Extraire les acteurs
|
||||||
if (preg_match('/<TH[^>]*>Distribution<\/TH>\s*<TD[^>]*>.*?<a[^>]*>([^<]+)<\/a>/is', $filmHtml, $m)) {
|
if (preg_match_all('/<a href="\/multicrit\.html\?acteur=[^"]*">([^<]+)<\/a>/i', $html, $matches)) {
|
||||||
$empty['publisher'] = trim($m[1]);
|
$empty['actors'] = implode(', ', array_slice($matches[1], 0, 5));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extraire le synopsis
|
||||||
|
if (preg_match('/<meta[^>]*property="og:description"[^>]*content="([^"]+)"/i', $html, $m)) {
|
||||||
|
$empty['description'] = html_entity_decode($m[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format haute qualité de l'affiche
|
||||||
|
if ($empty['poster']) {
|
||||||
|
$empty['poster'] = str_replace('/thumbs/', '/films-l/', $empty['poster']);
|
||||||
}
|
}
|
||||||
|
|
||||||
error_log("MovieCovers: ✅ Données récupérées → " . $empty['title'] . " (" . $empty['year'] . ")");
|
|
||||||
return $empty;
|
return $empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -774,7 +723,7 @@ case 'import_batch':
|
|||||||
$imported = 0; $skipped = 0;
|
$imported = 0; $skipped = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($type === 'videotheque') {
|
if ($type === 'videotheque') {
|
||||||
$stmt = $pdo->prepare("INSERT INTO videotheque (id, title, year, format, poster, ean_isbn13, description, length, number_of_discs, aspect_ratio, actors, publisher, director)
|
$stmt = $pdo->prepare("INSERT INTO videotheque (id, title, year, format, poster, ean_isbn13, description, length, number_of_discs, aspect_ratio, actors, publisher, director)
|
||||||
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE
|
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE
|
||||||
title=VALUES(title), year=VALUES(year), format=VALUES(format),
|
title=VALUES(title), year=VALUES(year), format=VALUES(format),
|
||||||
@@ -790,48 +739,37 @@ case 'import_batch':
|
|||||||
|
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
$ean = preg_replace('/[^0-9]/', '', (string)($item['ean'] ?? ''));
|
$ean = preg_replace('/[^0-9]/', '', (string)($item['ean'] ?? ''));
|
||||||
$csvTitle = trim($item['title'] ?? '');
|
$csvTitle = trim($item['title'] ?? ''); // ✅ Titre du CSV
|
||||||
|
|
||||||
if (strlen($ean) < 8 && empty($csvTitle)) {
|
if (strlen($ean) < 8 && empty($csvTitle)) {
|
||||||
$skipped++;
|
$skipped++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_log("Import: 🎬 Traitement de '$csvTitle' (EAN: $ean)");
|
// 1. Essayer Blu-ray.com (peut échouer sans bloquer)
|
||||||
|
|
||||||
// 1. Essayer Blu-ray.com (prioritaire pour les données physiques)
|
|
||||||
$blurayData = !empty($ean) ? fetchFromBlurayCom($ean) : [];
|
$blurayData = !empty($ean) ? fetchFromBlurayCom($ean) : [];
|
||||||
|
|
||||||
// 2. Si Blu-ray.com échoue, essayer MovieCovers avec le titre CSV
|
// ✅ Si Blu-ray.com trouve le film, utiliser son titre. Sinon, utiliser celui du CSV.
|
||||||
$movieCoversData = [];
|
$title = !empty($blurayData['title']) ? $blurayData['title'] : $csvTitle;
|
||||||
if ((empty($blurayData['title']) || empty($blurayData['poster'])) && !empty($csvTitle)) {
|
|
||||||
error_log("Import: 🔄 Blu-ray.com incomplet, essai MovieCovers pour '$csvTitle'");
|
|
||||||
$movieCoversData = fetchFromMovieCovers($csvTitle);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Fusionner les données (Blu-ray.com prioritaire, MovieCovers en complément)
|
|
||||||
$title = !empty($blurayData['title']) ? $blurayData['title'] : (!empty($movieCoversData['title']) ? $movieCoversData['title'] : $csvTitle);
|
|
||||||
|
|
||||||
if (empty($title)) {
|
if (empty($title)) {
|
||||||
error_log("Import: ❌ Pas de titre pour EAN $ean - ignoré");
|
|
||||||
$skipped++;
|
$skipped++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$year = !empty($blurayData['year']) ? $blurayData['year'] : (!empty($movieCoversData['year']) ? $movieCoversData['year'] : '');
|
$year = $blurayData['year'] ?? '';
|
||||||
$format = !empty($blurayData['format']) ? $blurayData['format'] : detectFormat($title);
|
$format = $blurayData['format'] ?: detectFormat($title);
|
||||||
$publisher = !empty($blurayData['publisher']) ? $blurayData['publisher'] : (!empty($movieCoversData['publisher']) ? $movieCoversData['publisher'] : '');
|
$publisher = $blurayData['publisher'] ?? '';
|
||||||
$discs = !empty($blurayData['number_of_discs']) ? $blurayData['number_of_discs'] : 1;
|
$discs = $blurayData['number_of_discs'] ?: 1;
|
||||||
$aspect = !empty($blurayData['aspect_ratio']) ? $blurayData['aspect_ratio'] : '';
|
$aspect = $blurayData['aspect_ratio'] ?? '';
|
||||||
$length = !empty($blurayData['length']) ? $blurayData['length'] : (!empty($movieCoversData['length']) ? $movieCoversData['length'] : '');
|
$length = $blurayData['length'] ?? '';
|
||||||
$poster = !empty($blurayData['poster']) ? $blurayData['poster'] : (!empty($movieCoversData['poster']) ? $movieCoversData['poster'] : '');
|
$poster = $blurayData['poster'] ?? '';
|
||||||
$desc = !empty($blurayData['description']) ? $blurayData['description'] : (!empty($movieCoversData['description']) ? $movieCoversData['description'] : '');
|
$desc = $blurayData['description'] ?? '';
|
||||||
$director = !empty($blurayData['director']) ? $blurayData['director'] : (!empty($movieCoversData['director']) ? $movieCoversData['director'] : '');
|
$director = $blurayData['director'] ?? '';
|
||||||
$actors = !empty($blurayData['actors']) ? $blurayData['actors'] : (!empty($movieCoversData['actors']) ? $movieCoversData['actors'] : '');
|
$actors = $blurayData['actors'] ?? '';
|
||||||
|
|
||||||
// 4. Fallback TMDB si données manquantes
|
// 2. ✅ FALLBACK TMDB si Blu-ray.com n'a pas trouvé certaines données
|
||||||
if (empty($poster) || empty($director) || empty($actors) || empty($desc) || empty($year)) {
|
if (empty($poster) || empty($director) || empty($actors) || empty($desc) || empty($year)) {
|
||||||
error_log("Import: 🔄 Fallback TMDB pour '$title'");
|
|
||||||
$tmdb = fetchTmdbPosterAndSynopsis($title, $year, $pdo);
|
$tmdb = fetchTmdbPosterAndSynopsis($title, $year, $pdo);
|
||||||
|
|
||||||
if (empty($poster) || $poster === 'assets/img/default_physical_media.jpg') {
|
if (empty($poster) || $poster === 'assets/img/default_physical_media.jpg') {
|
||||||
@@ -847,8 +785,6 @@ case 'import_batch':
|
|||||||
$id = makeStableId('videotheque', $title, $year);
|
$id = makeStableId('videotheque', $title, $year);
|
||||||
$stmt->execute([$id, $title, $year, $format, $poster, $ean, $desc, $length, $discs, $aspect, $actors, $publisher, $director]);
|
$stmt->execute([$id, $title, $year, $format, $poster, $ean, $desc, $length, $discs, $aspect, $actors, $publisher, $director]);
|
||||||
$imported++;
|
$imported++;
|
||||||
|
|
||||||
error_log("Import: ✅ Importé '$title' ($ean) - Poster: " . ($poster ? 'OK' : 'MANQUANT'));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Import critiques (inchangé)
|
// Import critiques (inchangé)
|
||||||
|
|||||||
Reference in New Issue
Block a user