netv-mam/media.php

56 lines
1.7 KiB
PHP
Executable File

<?php
$db = new SQLite3('netv-mam.sqlite');
if (isset($_GET['id']) && $_GET['id'] !== "") {
// get info about single file
$query = $db->prepare("SELECT * FROM media WHERE id = :id");
$query->bindValue(":id", intval($_GET['id']));
$result = $query->execute();
if ($result) {
$row = $result->fetchArray(SQLITE3_ASSOC);
echo(json_encode($row));
}
} else if (isset($_GET['filter']) && trim($_GET['filter']) !== "") {
// get info about a subset of media files
$query = $db->prepare("SELECT m.id AS id,
m.title,
m.description,
m.season,
m.episode_number,
m.duration_secs,
m.source_path
FROM media m
JOIN media_tags mt ON m.id = mt.media_id
JOIN tags t ON mt.tag_id = t.id
WHERE m.title LIKE :filter
OR m.description LIKE :filter
OR t.tag LIKE :filter
ORDER BY m.id DESC");
$query->bindValue(":filter", "%" . $_GET['filter'] . "%");
error_log($query->getSQL(true));
$result = $query->execute();
if ($result) {
$rows = array();
while ($res = $result->fetchArray(SQLITE3_ASSOC)) {
$rows[] = $res;
}
echo(json_encode($rows));
} else {
error_log($db->lastErrorMsg());
}
} else {
// get info about all media files
$query = "SELECT m.id AS id, m.title, m.description, m.season, m.episode_number, m.duration_secs, m.source_path, me.id AS edl_id, me.edl_name, me.edl_definition FROM media m JOIN media_edls me ON m.id = me.media_id ORDER BY id DESC";
$result = $db->query($query);
if ($result) {
$rows = array();
while ($res = $result->fetchArray(SQLITE3_ASSOC)) {
$rows[] = $res;
}
}
echo(json_encode($rows));
}
?>