diff --git a/api.php b/api.php
index 5c82709..3062638 100644
--- a/api.php
+++ b/api.php
@@ -517,7 +517,7 @@ function fetchFromBlurayCom($ean) {
}
// ── FONCTION POUR RÉCUPÉRER LES DONNÉES DEPUIS MOVIECOVERS.COM ──
-function fetchFromMovieCovers($title, $year = '') {
+function fetchFromMovieCovers($title) {
$empty = [
'title' => '', 'year' => '', 'director' => '', 'actors' => '',
'poster' => '', 'description' => '', 'length' => '',
@@ -527,106 +527,55 @@ function fetchFromMovieCovers($title, $year = '') {
if (empty($title)) return $empty;
- // Nettoyer le titre pour la recherche
- $searchTitle = trim($title);
- $searchTitle = preg_replace('/\s*[\[\(].*?[\]\)]\s*/', '', $searchTitle); // Enlever [Blu-ray], (2015), etc.
- $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));
+ // Nettoyer le titre pour l'URL
+ $urlTitle = strtoupper(str_replace(' ', '+', $title));
+ $url = "https://moviecovers.com/film/titre_{$urlTitle}.html";
- if (empty($searchTitle)) return $empty;
+ $html = httpGet($url, 10);
+ if (!$html) return $empty;
- error_log("MovieCovers: 🔍 Recherche de '$searchTitle'");
-
- // É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 : SAW
- 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('/([^<]+)<\/TITLE>/i', $html, $m)) {
$empty['title'] = trim($m[1]);
- } else {
- $empty['title'] = $searchTitle;
}
- // IDMC (via og:image ou PRE)
- $idmc = null;
- if (preg_match('/([^<]+)<\/PRE>/is', $filmHtml, $m)) {
- $idmc = trim($m[1]);
+ // Extraire l'affiche
+ if (preg_match('/
]*src="(https:\/\/moviecovers\.com\/DATA\/thumbs\/[^"]+)"[^>]*title="Recto/i', $html, $m)) {
+ $empty['poster'] = $m[1];
+ } elseif (preg_match('/]*property="og:image"[^>]*content="([^"]+)"/i', $html, $m)) {
+ $empty['poster'] = $m[1];
}
- if (!$idmc) {
- error_log("MovieCovers: ❌ IDMC non trouvé");
- 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('/
]*>Ann[^<]*e<\/TH>\s* | ]*>.*?(\d{4})/is', $filmHtml, $m)) {
- $empty['year'] = $m[1];
- }
-
- // Durée
- if (preg_match('/ | ]*>Dur[^<]*e<\/TH>\s* | ]*>([^<]+)/is', $filmHtml, $m)) {
- $empty['length'] = trim(strip_tags($m[1]));
- }
-
- // Réalisateur
- if (preg_match('/ | ]*>R[^<]*alisateur<\/TH>\s* | ]*>.*?]*>([^<]+)<\/a>/is', $filmHtml, $m)) {
+ // Extraire le réalisateur
+ if (preg_match('/Réalisateur<\/TH>\s* | ]*>.*?]*>([^<]+)<\/a>/is', $html, $m)) {
$empty['director'] = trim($m[1]);
}
- // Acteurs (extraire tous les liens dans la section acteurs)
- if (preg_match('/ | ]*>Acteurs[^<]*<\/TH>\s* | ]*>(.*?)<\/TD>/is', $filmHtml, $m)) {
- $actorsHtml = $m[1];
- preg_match_all('/]*>([^<]+)<\/a>/i', $actorsHtml, $actorMatches);
- if (!empty($actorMatches[1])) {
- $empty['actors'] = implode(', ', array_map('trim', array_slice($actorMatches[1], 0, 5)));
- }
+ // Extraire l'année
+ if (preg_match('/Année<\/TH>\s* | ]*>.*?]*>(\d{4})<\/a>/is', $html, $m)) {
+ $empty['year'] = $m[1];
}
- // Synopsis (via og:description)
- if (preg_match('/\s* | ]*>([\dH]+[\dmin]*)/is', $html, $m)) {
+ $empty['length'] = trim($m[1]);
}
- // Distribution (éditeur)
- if (preg_match('/ | ]*>Distribution<\/TH>\s* | ]*>.*?]*>([^<]+)<\/a>/is', $filmHtml, $m)) {
- $empty['publisher'] = trim($m[1]);
+ // Extraire les acteurs
+ if (preg_match_all('/([^<]+)<\/a>/i', $html, $matches)) {
+ $empty['actors'] = implode(', ', array_slice($matches[1], 0, 5));
+ }
+
+ // Extraire le synopsis
+ if (preg_match('/]*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;
}
@@ -774,64 +723,53 @@ case 'import_batch':
$imported = 0; $skipped = 0;
try {
- 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)
- VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE
- title=VALUES(title), year=VALUES(year), format=VALUES(format),
- poster=IF(VALUES(poster)!='assets/img/default_physical_media.jpg', VALUES(poster), poster),
- ean_isbn13=IF(VALUES(ean_isbn13)!='', VALUES(ean_isbn13), ean_isbn13),
- description=IF(VALUES(description)!='', VALUES(description), description),
- length=IF(VALUES(length)!='', VALUES(length), length),
- number_of_discs=IF(VALUES(number_of_discs)!=1, VALUES(number_of_discs), number_of_discs),
- aspect_ratio=IF(VALUES(aspect_ratio)!='', VALUES(aspect_ratio), aspect_ratio),
- actors=IF(VALUES(actors)!='', VALUES(actors), actors),
- publisher=IF(VALUES(publisher)!='', VALUES(publisher), publisher),
+ 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)
+ VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE
+ title=VALUES(title), year=VALUES(year), format=VALUES(format),
+ poster=IF(VALUES(poster)!='assets/img/default_physical_media.jpg', VALUES(poster), poster),
+ ean_isbn13=IF(VALUES(ean_isbn13)!='', VALUES(ean_isbn13), ean_isbn13),
+ description=IF(VALUES(description)!='', VALUES(description), description),
+ length=IF(VALUES(length)!='', VALUES(length), length),
+ number_of_discs=IF(VALUES(number_of_discs)!=1, VALUES(number_of_discs), number_of_discs),
+ aspect_ratio=IF(VALUES(aspect_ratio)!='', VALUES(aspect_ratio), aspect_ratio),
+ actors=IF(VALUES(actors)!='', VALUES(actors), actors),
+ publisher=IF(VALUES(publisher)!='', VALUES(publisher), publisher),
director=IF(VALUES(director)!='', VALUES(director), director)");
foreach ($items as $item) {
$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)) {
- $skipped++;
- continue;
+ if (strlen($ean) < 8 && empty($csvTitle)) {
+ $skipped++;
+ continue;
}
- error_log("Import: 🎬 Traitement de '$csvTitle' (EAN: $ean)");
-
- // 1. Essayer Blu-ray.com (prioritaire pour les données physiques)
+ // 1. Essayer Blu-ray.com (peut échouer sans bloquer)
$blurayData = !empty($ean) ? fetchFromBlurayCom($ean) : [];
- // 2. Si Blu-ray.com échoue, essayer MovieCovers avec le titre CSV
- $movieCoversData = [];
- if ((empty($blurayData['title']) || empty($blurayData['poster'])) && !empty($csvTitle)) {
- error_log("Import: 🔄 Blu-ray.com incomplet, essai MovieCovers pour '$csvTitle'");
- $movieCoversData = fetchFromMovieCovers($csvTitle);
+ // ✅ Si Blu-ray.com trouve le film, utiliser son titre. Sinon, utiliser celui du CSV.
+ $title = !empty($blurayData['title']) ? $blurayData['title'] : $csvTitle;
+
+ if (empty($title)) {
+ $skipped++;
+ continue;
}
- // 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);
+ $year = $blurayData['year'] ?? '';
+ $format = $blurayData['format'] ?: detectFormat($title);
+ $publisher = $blurayData['publisher'] ?? '';
+ $discs = $blurayData['number_of_discs'] ?: 1;
+ $aspect = $blurayData['aspect_ratio'] ?? '';
+ $length = $blurayData['length'] ?? '';
+ $poster = $blurayData['poster'] ?? '';
+ $desc = $blurayData['description'] ?? '';
+ $director = $blurayData['director'] ?? '';
+ $actors = $blurayData['actors'] ?? '';
- if (empty($title)) {
- error_log("Import: ❌ Pas de titre pour EAN $ean - ignoré");
- $skipped++;
- continue;
- }
-
- $year = !empty($blurayData['year']) ? $blurayData['year'] : (!empty($movieCoversData['year']) ? $movieCoversData['year'] : '');
- $format = !empty($blurayData['format']) ? $blurayData['format'] : detectFormat($title);
- $publisher = !empty($blurayData['publisher']) ? $blurayData['publisher'] : (!empty($movieCoversData['publisher']) ? $movieCoversData['publisher'] : '');
- $discs = !empty($blurayData['number_of_discs']) ? $blurayData['number_of_discs'] : 1;
- $aspect = !empty($blurayData['aspect_ratio']) ? $blurayData['aspect_ratio'] : '';
- $length = !empty($blurayData['length']) ? $blurayData['length'] : (!empty($movieCoversData['length']) ? $movieCoversData['length'] : '');
- $poster = !empty($blurayData['poster']) ? $blurayData['poster'] : (!empty($movieCoversData['poster']) ? $movieCoversData['poster'] : '');
- $desc = !empty($blurayData['description']) ? $blurayData['description'] : (!empty($movieCoversData['description']) ? $movieCoversData['description'] : '');
- $director = !empty($blurayData['director']) ? $blurayData['director'] : (!empty($movieCoversData['director']) ? $movieCoversData['director'] : '');
- $actors = !empty($blurayData['actors']) ? $blurayData['actors'] : (!empty($movieCoversData['actors']) ? $movieCoversData['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)) {
- error_log("Import: 🔄 Fallback TMDB pour '$title'");
$tmdb = fetchTmdbPosterAndSynopsis($title, $year, $pdo);
if (empty($poster) || $poster === 'assets/img/default_physical_media.jpg') {
@@ -847,8 +785,6 @@ case 'import_batch':
$id = makeStableId('videotheque', $title, $year);
$stmt->execute([$id, $title, $year, $format, $poster, $ean, $desc, $length, $discs, $aspect, $actors, $publisher, $director]);
$imported++;
-
- error_log("Import: ✅ Importé '$title' ($ean) - Poster: " . ($poster ? 'OK' : 'MANQUANT'));
}
} else {
// Import critiques (inchangé)
|