Film / Serie Update

This commit is contained in:
2025-10-30 20:48:22 +01:00
parent 6ec3ad363c
commit dd21a3ed71
6 changed files with 456 additions and 10 deletions
+68 -6
View File
@@ -170,8 +170,24 @@ try {
}
$id = $pdo->lastInsertId();
if (!$id) {
if ($tmdbId) { $q=$pdo->prepare('SELECT id FROM episodes WHERE tmdb_id=?'); $q->execute([$tmdbId]); $id=$q->fetchColumn(); }
if (!$id) { $q=$pdo->prepare('SELECT id FROM episodes WHERE season_id=? AND episode_number=?'); $q->execute([$seasonId,$epNo]); $id=$q->fetchColumn(); }
if ($tmdbId) {
try {
$q=$pdo->prepare('SELECT id FROM episodes WHERE tmdb_id=?');
$q->execute([$tmdbId]);
$id=$q->fetchColumn();
} catch (Throwable $e) {
if (strpos($e->getMessage(), 'Unknown column') !== false || ($e instanceof PDOException && $e->getCode()==='42S22')) {
$q=$pdo->prepare('SELECT id FROM episodes WHERE season_id=? AND episode_number=?');
$q->execute([$seasonId,$epNo]);
$id=$q->fetchColumn();
} else { throw $e; }
}
}
if (!$id) {
$q=$pdo->prepare('SELECT id FROM episodes WHERE season_id=? AND episode_number=?');
$q->execute([$seasonId,$epNo]);
$id=$q->fetchColumn();
}
}
resp(['ok'=>true,'id'=>(int)$id]);
}
@@ -359,10 +375,56 @@ try {
case 'get_show_by_tmdb': {
$tmdbId = (int)($in['tmdb_id'] ?? 0);
if (!$tmdbId) fail('bad params');
$stmt = $pdo->prepare('SELECT id FROM shows WHERE tmdb_id = ?');
$stmt->execute([$tmdbId]);
$id = $stmt->fetchColumn();
resp(['ok' => true, 'id' => $id ? (int)$id : null]);
try {
$stmt = $pdo->prepare('SELECT id FROM shows WHERE tmdb_id = ?');
$stmt->execute([$tmdbId]);
$id = $stmt->fetchColumn();
resp(['ok' => true, 'id' => $id ? (int)$id : null]);
} catch (Throwable $e) {
// Fallback if column tmdb_id does not exist (older schema): scan JSON
if (strpos($e->getMessage(), 'Unknown column') !== false || ($e instanceof PDOException && $e->getCode()==='42S22')) {
$stmt = $pdo->query('SELECT id, json FROM shows');
$rows = $stmt->fetchAll();
$found = null;
foreach ($rows as $r) {
$j = json_decode($r['json'] ?? 'null', true);
if (is_array($j) && isset($j['id']) && (int)$j['id'] === $tmdbId) {
$found = (int)$r['id'];
break;
}
}
resp(['ok' => true, 'id' => $found]);
} else {
throw $e;
}
}
}
case 'get_tmdb_by_show_id': {
$showId = (int)($in['show_id'] ?? 0);
if (!$showId) fail('bad params');
try {
$stmt = $pdo->prepare('SELECT tmdb_id FROM shows WHERE id = ?');
$stmt->execute([$showId]);
$tm = $stmt->fetchColumn();
resp(['ok' => true, 'tmdb_id' => $tm !== false ? (int)$tm : null]);
} catch (Throwable $e) {
// Fallback if column tmdb_id does not exist: load from JSON
if (strpos($e->getMessage(), 'Unknown column') !== false || ($e instanceof PDOException && $e->getCode()==='42S22')) {
$stmt = $pdo->prepare('SELECT json FROM shows WHERE id = ?');
$stmt->execute([$showId]);
$json = $stmt->fetchColumn();
$m = json_decode($json ?: 'null', true);
$tid = is_array($m) && isset($m['id']) ? (int)$m['id'] : null;
resp(['ok' => true, 'tmdb_id' => $tid]);
} else { throw $e; }
}
}
case 'list_shows': {
$stmt = $pdo->query('SELECT id, tmdb_id, name, json FROM shows');
$rows = $stmt->fetchAll();
resp(['ok' => true, 'items' => $rows]);
}
case 'set_show_meta': {