Actualiser api.php
This commit is contained in:
@@ -230,19 +230,18 @@ function fetchTMDBFull($title, $year, $apiKey, $pdo) {
|
|||||||
$cached = getCache($pdo, $cacheKey);
|
$cached = getCache($pdo, $cacheKey);
|
||||||
if ($cached) return $cached;
|
if ($cached) return $cached;
|
||||||
|
|
||||||
|
// 1. Tenter avec l'année
|
||||||
$searchUrl = "https://api.themoviedb.org/3/search/movie?api_key={$apiKey}&query=" . urlencode($cleanTitle) . "&year={$year}&language=fr-FR";
|
$searchUrl = "https://api.themoviedb.org/3/search/movie?api_key={$apiKey}&query=" . urlencode($cleanTitle) . "&year={$year}&language=fr-FR";
|
||||||
$searchRes = httpGet($searchUrl, 5);
|
$searchRes = httpGet($searchUrl, 5);
|
||||||
if (!$searchRes) return null;
|
|
||||||
$searchData = json_decode($searchRes, true);
|
$searchData = json_decode($searchRes, true);
|
||||||
|
|
||||||
|
// 2. Fallback : Si rien trouvé, on réessaie SANS l'année (au cas où l'année dans le CSV soit fausse)
|
||||||
if (empty($searchData['results'])) {
|
if (empty($searchData['results'])) {
|
||||||
$searchUrl2 = "https://api.themoviedb.org/3/search/movie?api_key={$apiKey}&query=" . urlencode($cleanTitle) . "&language=fr-FR";
|
$searchUrl = "https://api.themoviedb.org/3/search/movie?api_key={$apiKey}&query=" . urlencode($cleanTitle) . "&language=fr-FR";
|
||||||
$searchRes2 = httpGet($searchUrl2, 5);
|
$searchRes = httpGet($searchUrl, 5);
|
||||||
if ($searchRes2) {
|
$searchData = json_decode($searchRes, true);
|
||||||
$searchData2 = json_decode($searchRes2, true);
|
|
||||||
if (!empty($searchData2['results'])) $searchData = $searchData2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($searchData['results'])) return null;
|
if (empty($searchData['results'])) return null;
|
||||||
$movieId = $searchData['results'][0]['id'];
|
$movieId = $searchData['results'][0]['id'];
|
||||||
|
|
||||||
@@ -429,7 +428,22 @@ 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 {
|
||||||
$sql = "INSERT INTO videotheque (id, title, year, director, poster, format, length, publisher, ean_isbn13, number_of_discs, aspect_ratio, description, actors) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE title=VALUES(title), year=VALUES(year), director=VALUES(director), poster=VALUES(poster), format=VALUES(format), length=VALUES(length), publisher=VALUES(publisher), ean_isbn13=VALUES(ean_isbn13), number_of_discs=VALUES(number_of_discs), aspect_ratio=VALUES(aspect_ratio), description=VALUES(description), actors=VALUES(actors)";
|
// Remplacez votre bloc SQL dans 'save_film' par celui-ci :
|
||||||
|
$sql = "INSERT INTO videotheque (id, title, year, director, poster, format, length, publisher, ean_isbn13, number_of_discs, aspect_ratio, description, actors)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
title=VALUES(title),
|
||||||
|
year=VALUES(year),
|
||||||
|
director=IF(VALUES(director)!='', VALUES(director), director),
|
||||||
|
poster=IF(VALUES(poster)!='', VALUES(poster), poster),
|
||||||
|
format=IF(VALUES(format)!='', VALUES(format), format),
|
||||||
|
length=IF(VALUES(length)!='', VALUES(length), length),
|
||||||
|
publisher=IF(VALUES(publisher)!='', VALUES(publisher), publisher),
|
||||||
|
ean_isbn13=IF(VALUES(ean_isbn13)!='', VALUES(ean_isbn13), ean_isbn13),
|
||||||
|
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),
|
||||||
|
description=IF(VALUES(description)!='', VALUES(description), description),
|
||||||
|
actors=IF(VALUES(actors)!='', VALUES(actors), actors)";
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt->execute([$id, $data['title'] ?? '', $data['year'] ?? '', $data['director'] ?? '', $data['poster'] ?? '', $data['format'] ?? '', $data['length'] ?? '', $data['publisher'] ?? '', $data['ean_isbn13'] ?? '', $data['number_of_discs'] ?? 1, $data['aspect_ratio'] ?? '', $data['description'] ?? '', $data['actors'] ?? '']);
|
$stmt->execute([$id, $data['title'] ?? '', $data['year'] ?? '', $data['director'] ?? '', $data['poster'] ?? '', $data['format'] ?? '', $data['length'] ?? '', $data['publisher'] ?? '', $data['ean_isbn13'] ?? '', $data['number_of_discs'] ?? 1, $data['aspect_ratio'] ?? '', $data['description'] ?? '', $data['actors'] ?? '']);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user