Actualiser api.php
This commit is contained in:
@@ -120,29 +120,6 @@ function extractYear($dateStr) {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 1. API UPCitemDB ──
|
|
||||||
function fetchUPCitemdb($ean, $pdo) {
|
|
||||||
if (empty($ean) || strlen($ean) < 8) return null;
|
|
||||||
$cacheKey = 'upc_full_' . md5($ean);
|
|
||||||
$cached = getCache($pdo, $cacheKey);
|
|
||||||
if ($cached) return $cached;
|
|
||||||
$url = "https://api.upcitemdb.com/prod/trial/lookup?upc=" . urlencode($ean);
|
|
||||||
$res = httpGet($url, 5);
|
|
||||||
if (!$res) return null;
|
|
||||||
$data = json_decode($res, true);
|
|
||||||
if (isset($data['code']) && $data['code'] === 'OK' && !empty($data['items'])) {
|
|
||||||
$item = $data['items'][0];
|
|
||||||
$result = [
|
|
||||||
'title' => $item['title'] ?? '',
|
|
||||||
'poster' => $item['images'][0] ?? '',
|
|
||||||
'publisher' => $item['brand'] ?? $item['publisher'] ?? '',
|
|
||||||
'format' => detectFormat($item['title'] ?? '', $item['description'] ?? '')
|
|
||||||
];
|
|
||||||
setCache($pdo, $cacheKey, $result, 'upc');
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetchDVDFr($ean, $pdo) {
|
function fetchDVDFr($ean, $pdo) {
|
||||||
if (empty($ean) || strlen($ean) < 8) return null;
|
if (empty($ean) || strlen($ean) < 8) return null;
|
||||||
@@ -366,22 +343,14 @@ switch ($action) {
|
|||||||
case 'search_ean_full':
|
case 'search_ean_full':
|
||||||
$ean = $_GET['ean'] ?? '';
|
$ean = $_GET['ean'] ?? '';
|
||||||
if (!$ean) { echo json_encode(['error' => 'EAN manquant']); exit; }
|
if (!$ean) { echo json_encode(['error' => 'EAN manquant']); exit; }
|
||||||
|
|
||||||
$result = [
|
$result = [
|
||||||
'ean' => $ean, 'title' => '', 'director' => '', 'year' => '',
|
'ean' => $ean, 'title' => '', 'director' => '', 'year' => '',
|
||||||
'poster' => '', 'publisher' => '', 'format' => '',
|
'poster' => '', 'publisher' => '', 'format' => '',
|
||||||
'length' => '', 'number_of_discs' => 1, 'aspect_ratio' => '', 'actors' => ''
|
'length' => '', 'number_of_discs' => 1, 'aspect_ratio' => '', 'actors' => ''
|
||||||
];
|
];
|
||||||
$upcData = fetchUPCitemdb($ean, $pdo);
|
|
||||||
$tmdbQueryTitle = "";
|
|
||||||
if ($upcData) {
|
|
||||||
$tmdbQueryTitle = $upcData['title'];
|
|
||||||
$result['title'] = $upcData['title'];
|
|
||||||
$result['poster'] = $upcData['poster'];
|
|
||||||
$result['publisher'] = $upcData['publisher'];
|
|
||||||
$result['format'] = $upcData['format'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// DVDFr : affiche FR + métadonnées techniques (format, éditeur, durée, aspect)
|
// 🔥 UNIQUEMENT DVDFr (plus de UPCitemDB)
|
||||||
$dvdfrData = fetchDVDFr($ean, $pdo);
|
$dvdfrData = fetchDVDFr($ean, $pdo);
|
||||||
if (!empty($dvdfrData)) {
|
if (!empty($dvdfrData)) {
|
||||||
if (!empty($dvdfrData['poster'])) $result['poster'] = $dvdfrData['poster'];
|
if (!empty($dvdfrData['poster'])) $result['poster'] = $dvdfrData['poster'];
|
||||||
@@ -391,26 +360,27 @@ switch ($action) {
|
|||||||
if (!empty($dvdfrData['aspect'])) $result['aspect_ratio'] = $dvdfrData['aspect'];
|
if (!empty($dvdfrData['aspect'])) $result['aspect_ratio'] = $dvdfrData['aspect'];
|
||||||
if (!empty($dvdfrData['discs'])) $result['number_of_discs'] = (int)$dvdfrData['discs'];
|
if (!empty($dvdfrData['discs'])) $result['number_of_discs'] = (int)$dvdfrData['discs'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TMDB pour le titre, réalisateur, année et acteurs
|
||||||
$tmdbKey = getTmdbApiKey($pdo);
|
$tmdbKey = getTmdbApiKey($pdo);
|
||||||
if ($tmdbKey && $tmdbQueryTitle) {
|
if ($tmdbKey && !empty($result['publisher'])) {
|
||||||
$tmdbData = fetchTMDBFull($tmdbQueryTitle, '', $tmdbKey, $pdo);
|
$tmdbData = fetchTMDBFull($result['publisher'], '', $tmdbKey, $pdo);
|
||||||
if ($tmdbData) {
|
if ($tmdbData) {
|
||||||
if (!empty($tmdbData['title'])) $result['title'] = $tmdbData['title'];
|
if (!empty($tmdbData['title'])) $result['title'] = $tmdbData['title'];
|
||||||
if (empty($result['poster']) && !empty($tmdbData['poster'])) $result['poster'] = $tmdbData['poster'];
|
|
||||||
if (!empty($tmdbData['year'])) $result['year'] = $tmdbData['year'];
|
if (!empty($tmdbData['year'])) $result['year'] = $tmdbData['year'];
|
||||||
if (!empty($tmdbData['length'])) $result['length'] = $tmdbData['length'];
|
|
||||||
if (!empty($tmdbData['director'])) $result['director'] = $tmdbData['director'];
|
if (!empty($tmdbData['director'])) $result['director'] = $tmdbData['director'];
|
||||||
if (!empty($tmdbData['cast'])) $result['actors'] = implode(', ', $tmdbData['cast']);
|
if (!empty($tmdbData['cast'])) $result['actors'] = implode(', ', $tmdbData['cast']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
echo json_encode(['success' => true, 'data' => $result]);
|
echo json_encode(['success' => true, 'data' => $result]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'save_film':
|
case 'save_film':
|
||||||
checkAuth($pdo);
|
checkAuth($pdo);
|
||||||
$type = $data['type'] ?? 'critique';
|
$type = $data['type'] ?? 'critique';
|
||||||
$id = !empty($data['id']) ? $data['id'] : makeStableId($type, $data['title'] ?? '', $data['year'] ?? '0000');
|
$id = !empty($data['id']) ? $data['id'] : makeStableId($type, $data['title'] ?? '', $data['year'] ?? '0000');
|
||||||
|
|
||||||
|
// 🔥 Récupération des données manquantes via TMDB uniquement (plus de UPC)
|
||||||
if (empty($data['director']) || empty($data['poster'])) {
|
if (empty($data['director']) || empty($data['poster'])) {
|
||||||
$tmdbData = fetchTMDBFull($data['title'] ?? '', $data['year'] ?? '', getTmdbApiKey($pdo), $pdo);
|
$tmdbData = fetchTMDBFull($data['title'] ?? '', $data['year'] ?? '', getTmdbApiKey($pdo), $pdo);
|
||||||
if ($tmdbData) {
|
if ($tmdbData) {
|
||||||
@@ -525,34 +495,21 @@ case 'import_batch':
|
|||||||
$poster = $rowData['poster'] ?? '';
|
$poster = $rowData['poster'] ?? '';
|
||||||
$director = '';
|
$director = '';
|
||||||
|
|
||||||
// 1. UPCitemDB
|
// 1.5 DVDFr : toutes les métadonnées techniques
|
||||||
if (!empty($ean)) {
|
if (!empty($ean)) {
|
||||||
$upcData = fetchUPCitemdb($ean, $pdo);
|
|
||||||
if ($upcData) {
|
|
||||||
if (empty($poster) && !empty($upcData['poster'])) $poster = $upcData['poster'];
|
|
||||||
if ($title === 'Sans titre') $title = $upcData['title'];
|
|
||||||
if (empty($publisher)) $publisher = $upcData['publisher'];
|
|
||||||
if (empty($format) || $format === 'Blu-ray') $format = $upcData['format'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1.5 DVDFr : affiche FR + métadonnées techniques complètes
|
|
||||||
$dvdfrData = fetchDVDFr($ean, $pdo);
|
$dvdfrData = fetchDVDFr($ean, $pdo);
|
||||||
if (!empty($dvdfrData)) {
|
if (!empty($dvdfrData)) {
|
||||||
// Récupération de TOUS les champs retournés par DVDfr
|
// Récupération de TOUS les champs retournés par DVDfr
|
||||||
if (!empty($dvdfrData['poster'])) $poster = $dvdfrData['poster'];
|
if (!empty($dvdfrData['poster'])) $poster = $dvdfrData['poster'];
|
||||||
if (!empty($dvdfrData['publisher'])) $publisher = $dvdfrData['publisher'];
|
if (!empty($dvdfrData['publisher'])) $publisher = $dvdfrData['publisher'];
|
||||||
if (!empty($dvdfrData['format']) && (empty($format) || $format === 'Blu-ray'))
|
if (!empty($dvdfrData['format'])) $format = $dvdfrData['format'];
|
||||||
$format = $dvdfrData['format'];
|
if (!empty($dvdfrData['length'])) $length = $dvdfrData['length'];
|
||||||
if (!empty($dvdfrData['length']) && empty($length))
|
if (!empty($dvdfrData['aspect'])) $aspect = $dvdfrData['aspect'];
|
||||||
$length = $dvdfrData['length'];
|
if (!empty($dvdfrData['discs'])) $discs = (int)$dvdfrData['discs'];
|
||||||
if (!empty($dvdfrData['aspect']) && empty($aspect))
|
|
||||||
$aspect = $dvdfrData['aspect'];
|
|
||||||
if (!empty($dvdfrData['discs']) && $discs === 1)
|
|
||||||
$discs = (int)$dvdfrData['discs'];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. TMDB - 🔥 NETTOYAGE AGRESSIF DU TITRE
|
// 2. TMDB (Données Officielles & Synopsis)
|
||||||
if ($tmdbApiKey && !empty($title)) {
|
if ($tmdbApiKey && !empty($title)) {
|
||||||
// 🔥 CRÉER UNE VERSION PROPRE DU TITRE POUR TMDB
|
// 🔥 CRÉER UNE VERSION PROPRE DU TITRE POUR TMDB
|
||||||
$tmdbTitle = $title;
|
$tmdbTitle = $title;
|
||||||
|
|||||||
Reference in New Issue
Block a user