Actualiser api.php
This commit is contained in:
@@ -120,43 +120,55 @@ function extractYear($dateStr) {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── FONCTION POUR RÉCUPÉRER LES IMAGES DEPUIS BLU-RAY.COM ──
|
// ── FONCTION POUR RÉCUPÉRER LES IMAGES DEPUIS NOTRECINEMA.COM ──
|
||||||
function fetchBluRayCom($ean, $title = '', $year = '', $pdo = null) {
|
function fetchNotreCinema($title, $year = '', $ean = '', $pdo = null) {
|
||||||
$defaultPoster = 'assets/img/default_physical_media.jpg';
|
$defaultPoster = 'assets/img/default_physical_media.jpg';
|
||||||
|
|
||||||
if (empty($ean) && empty($title)) {
|
if (empty($title)) {
|
||||||
return ['poster' => $defaultPoster, 'title' => $title, 'format' => 'Blu-ray'];
|
return ['poster' => $defaultPoster, 'title' => '', 'format' => 'Blu-ray'];
|
||||||
}
|
|
||||||
|
|
||||||
// Nettoyer l'EAN
|
|
||||||
$cleanEan = '';
|
|
||||||
if (!empty($ean)) {
|
|
||||||
$cleanEan = preg_replace('/[^0-9]/', '', $ean);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$cleanTitle = cleanTitle($title);
|
||||||
$userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
|
$userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
|
||||||
|
|
||||||
// Recherche par EAN/UPC d'abord
|
// ÉTAPE 1 : Recherche sur notrecinema.com
|
||||||
if (!empty($cleanEan)) {
|
$searchUrl = "https://www.notrecinema.com/communaute/stubs.php?stub=" . urlencode($cleanTitle);
|
||||||
$searchUrl = "https://www.blu-ray.com/search/?quicksearch=1&searchtype=products&q=" . urlencode($cleanEan);
|
if (!empty($year)) {
|
||||||
$searchRes = httpGet($searchUrl, 5, $userAgent);
|
$searchUrl .= "&annee=" . $year;
|
||||||
|
}
|
||||||
if ($searchRes && preg_match('/<a href="\/products\/\?id=(\d+)"[^>]*>/i', $searchRes, $matches)) {
|
|
||||||
$productId = $matches[1];
|
$searchRes = httpGet($searchUrl, 10, $userAgent);
|
||||||
$productUrl = "https://www.blu-ray.com/products/?id=" . $productId;
|
|
||||||
|
if ($searchRes) {
|
||||||
|
// Extraire le lien vers la page du film
|
||||||
|
if (preg_match('/<a href="\/communaute\/stubs\.php\?stub=([^"]+)"[^>]*>/i', $searchRes, $matches)) {
|
||||||
|
$filmSlug = $matches[1];
|
||||||
|
$filmUrl = "https://www.notrecinema.com/communaute/stubs.php?stub=" . $filmSlug;
|
||||||
|
|
||||||
$productRes = httpGet($productUrl, 5, $userAgent);
|
$filmRes = httpGet($filmUrl, 10, $userAgent);
|
||||||
|
|
||||||
if ($productRes) {
|
if ($filmRes) {
|
||||||
// Extraire l'image principale
|
// Extraire l'image d'affiche
|
||||||
if (preg_match('/<img[^>]*id="home_release_img"[^>]*src="([^"]+)"/i', $productRes, $imgMatches)) {
|
$posterUrl = null;
|
||||||
|
|
||||||
|
// Chercher l'image principale du film
|
||||||
|
if (preg_match('/<img[^>]*class="[^"]*affiche[^"]*"[^>]*src="([^"]+)"/i', $filmRes, $imgMatches)) {
|
||||||
$posterUrl = $imgMatches[1];
|
$posterUrl = $imgMatches[1];
|
||||||
// Convertir en haute résolution
|
} elseif (preg_match('/<div[^>]*class="[^"]*film_affiche[^"]*"[^>]*>.*?<img[^>]*src="([^"]+)"/is', $filmRes, $imgMatches)) {
|
||||||
$posterUrl = str_replace('/resized/', '/', $posterUrl);
|
$posterUrl = $imgMatches[1];
|
||||||
|
} elseif (preg_match('/<img[^>]*src="(https:\/\/www\.notrecinema\.com\/images\/films\/[^"]+)"/i', $filmRes, $imgMatches)) {
|
||||||
|
$posterUrl = $imgMatches[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($posterUrl)) {
|
||||||
|
// S'assurer que l'URL est absolue
|
||||||
|
if (strpos($posterUrl, 'http') !== 0) {
|
||||||
|
$posterUrl = 'https://www.notrecinema.com' . $posterUrl;
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'poster' => $posterUrl,
|
'poster' => $posterUrl,
|
||||||
'title' => $title,
|
'title' => $cleanTitle,
|
||||||
'format' => 'Blu-ray'
|
'format' => 'Blu-ray'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -164,33 +176,30 @@ function fetchBluRayCom($ean, $title = '', $year = '', $pdo = null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback : recherche par titre
|
// ÉTAPE 2 : Recherche alternative par EAN si disponible
|
||||||
if (!empty($title)) {
|
if (!empty($ean)) {
|
||||||
$cleanTitle = cleanTitle($title);
|
$cleanEan = preg_replace('/[^0-9]/', '', $ean);
|
||||||
$searchUrl = "https://www.blu-ray.com/search/?quicksearch=1&searchtype=movies&q=" . urlencode($cleanTitle);
|
$searchUrl = "https://www.notrecinema.com/communaute/recherche.php?recherche=" . urlencode($cleanEan);
|
||||||
|
|
||||||
$searchRes = httpGet($searchUrl, 5, $userAgent);
|
$searchRes = httpGet($searchUrl, 10, $userAgent);
|
||||||
|
|
||||||
if ($searchRes && preg_match('/<a href="\/movies\/\?id=(\d+)"[^>]*>/i', $searchRes, $matches)) {
|
if ($searchRes && preg_match('/<a href="\/communaute\/stubs\.php\?stub=([^"]+)"[^>]*>/i', $searchRes, $matches)) {
|
||||||
$movieId = $matches[1];
|
$filmSlug = $matches[1];
|
||||||
$movieUrl = "https://www.blu-ray.com/movies/?id=" . $movieId;
|
$filmUrl = "https://www.notrecinema.com/communaute/stubs.php?stub=" . $filmSlug;
|
||||||
|
|
||||||
$movieRes = httpGet($movieUrl, 5, $userAgent);
|
$filmRes = httpGet($filmUrl, 10, $userAgent);
|
||||||
|
|
||||||
if ($movieRes && preg_match('/<img[^>]*id="home_release_img"[^>]*src="([^"]+)"/i', $movieRes, $imgMatches)) {
|
if ($filmRes && preg_match('/<img[^>]*src="(https:\/\/www\.notrecinema\.com\/images\/films\/[^"]+)"/i', $filmRes, $imgMatches)) {
|
||||||
$posterUrl = $imgMatches[1];
|
|
||||||
$posterUrl = str_replace('/resized/', '/', $posterUrl);
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'poster' => $posterUrl,
|
'poster' => $imgMatches[1],
|
||||||
'title' => $title,
|
'title' => $cleanTitle,
|
||||||
'format' => 'Blu-ray'
|
'format' => 'Blu-ray'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ['poster' => $defaultPoster, 'title' => $title, 'format' => 'Blu-ray'];
|
return ['poster' => $defaultPoster, 'title' => $cleanTitle, 'format' => 'Blu-ray'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── ROUTEUR PRINCIPAL ──
|
// ── ROUTEUR PRINCIPAL ──
|
||||||
@@ -483,64 +492,64 @@ case 'get_config_keys':
|
|||||||
else { http_response_code(400); echo json_encode(["success" => false, "error" => "Aucun élément sélectionné."]); }
|
else { http_response_code(400); echo json_encode(["success" => false, "error" => "Aucun élément sélectionné."]); }
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'import_batch':
|
case 'import_batch':
|
||||||
checkAuth($pdo);
|
checkAuth($pdo);
|
||||||
$data = json_decode(file_get_contents("php://input"), true);
|
$data = json_decode(file_get_contents("php://input"), true);
|
||||||
$type = $data['type'] ?? 'critique';
|
$type = $data['type'] ?? 'critique';
|
||||||
$items = $data['items'] ?? [];
|
$items = $data['items'] ?? [];
|
||||||
|
|
||||||
|
$pdo->beginTransaction();
|
||||||
|
$imported = 0;
|
||||||
|
|
||||||
|
if ($type === 'videotheque') {
|
||||||
|
$stmtVideo = $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
|
||||||
|
ean_isbn13 = VALUES(ean_isbn13),
|
||||||
|
poster = VALUES(poster),
|
||||||
|
description = VALUES(description),
|
||||||
|
format = VALUES(format),
|
||||||
|
length = VALUES(length),
|
||||||
|
number_of_discs = VALUES(number_of_discs),
|
||||||
|
aspect_ratio = VALUES(aspect_ratio),
|
||||||
|
actors = VALUES(actors),
|
||||||
|
publisher = VALUES(publisher)");
|
||||||
|
|
||||||
$pdo->beginTransaction();
|
foreach ($items as $item) {
|
||||||
$imported = 0;
|
$title = $item['title'] ?? '';
|
||||||
|
if (empty($title)) continue;
|
||||||
if ($type === 'videotheque') {
|
|
||||||
$stmtVideo = $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
|
|
||||||
ean_isbn13 = VALUES(ean_isbn13),
|
|
||||||
poster = VALUES(poster),
|
|
||||||
description = VALUES(description),
|
|
||||||
format = VALUES(format),
|
|
||||||
length = VALUES(length),
|
|
||||||
number_of_discs = VALUES(number_of_discs),
|
|
||||||
aspect_ratio = VALUES(aspect_ratio),
|
|
||||||
actors = VALUES(actors),
|
|
||||||
publisher = VALUES(publisher)");
|
|
||||||
|
|
||||||
foreach ($items as $item) {
|
$year = $item['year'] ?? '';
|
||||||
$title = $item['title'] ?? '';
|
$ean = $item['ean'] ?? '';
|
||||||
if (empty($title)) continue;
|
$desc = $item['description'] ?? '';
|
||||||
|
$length = $item['length'] ?? '';
|
||||||
$year = $item['year'] ?? '';
|
$discs = $item['number_of_discs'] ?? 1;
|
||||||
$ean = $item['ean'] ?? '';
|
$aspect = $item['aspect_ratio'] ?? '';
|
||||||
$desc = $item['description'] ?? '';
|
$actors = $item['actors'] ?? '';
|
||||||
$length = $item['length'] ?? '';
|
$publisher = $item['publisher'] ?? '';
|
||||||
$discs = $item['number_of_discs'] ?? 1;
|
$director = $item['director'] ?? '';
|
||||||
$aspect = $item['aspect_ratio'] ?? '';
|
|
||||||
$actors = $item['actors'] ?? '';
|
$id = makeStableId('videotheque', $title, $year);
|
||||||
$publisher = $item['publisher'] ?? '';
|
|
||||||
$director = $item['director'] ?? '';
|
// Utiliser notrecinema.com pour récupérer l'image
|
||||||
|
$notreCinemaData = fetchNotreCinema($title, $year, $ean, $pdo);
|
||||||
$id = makeStableId('videotheque', $title, $year);
|
$poster = $notreCinemaData['poster'];
|
||||||
|
|
||||||
// Utiliser blu-ray.com pour récupérer l'image
|
// Déterminer le format
|
||||||
$bluRayData = fetchBluRayCom($ean, $title, $year, $pdo);
|
$format = 'Blu-ray';
|
||||||
$poster = $bluRayData['poster'];
|
if (stripos($title, '4K') !== false || stripos($title, 'UHD') !== false) {
|
||||||
|
$format = '4K Ultra HD';
|
||||||
// Déterminer le format
|
} elseif (stripos($desc, 'DVD') !== false) {
|
||||||
$format = 'Blu-ray';
|
$format = 'DVD';
|
||||||
if (stripos($title, '4K') !== false || stripos($title, 'UHD') !== false) {
|
|
||||||
$format = '4K Ultra HD';
|
|
||||||
} elseif (stripos($desc, 'DVD') !== false) {
|
|
||||||
$format = 'DVD';
|
|
||||||
}
|
|
||||||
|
|
||||||
$stmtVideo->execute([
|
|
||||||
$id, $title, $year, $format, $poster, $ean, $desc,
|
|
||||||
$length, $discs, $aspect, $actors, $publisher, $director
|
|
||||||
]);
|
|
||||||
$imported++;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
|
$stmtVideo->execute([
|
||||||
|
$id, $title, $year, $format, $poster, $ean, $desc,
|
||||||
|
$length, $discs, $aspect, $actors, $publisher, $director
|
||||||
|
]);
|
||||||
|
$imported++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
$ratingRaw = $rowData['Rating'] ?? $rowData['rating'] ?? '';
|
$ratingRaw = $rowData['Rating'] ?? $rowData['rating'] ?? '';
|
||||||
$rating = ($ratingRaw !== '' && $ratingRaw !== null) ? (float)$ratingRaw : null;
|
$rating = ($ratingRaw !== '' && $ratingRaw !== null) ? (float)$ratingRaw : null;
|
||||||
$review = $rowData['Review'] ?? $rowData['review'] ?? '';
|
$review = $rowData['Review'] ?? $rowData['review'] ?? '';
|
||||||
|
|||||||
Reference in New Issue
Block a user