2024-09-03 10:37:30 -04:00
< ? 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
2024-09-03 11:52:04 -04:00
$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
2024-09-03 10:37:30 -04:00
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
2024-09-17 09:27:11 -04:00
$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 LEFT JOIN media_edls me ON m.id = me.media_id ORDER BY id DESC " ;
2024-09-03 10:37:30 -04:00
$result = $db -> query ( $query );
if ( $result ) {
$rows = array ();
while ( $res = $result -> fetchArray ( SQLITE3_ASSOC )) {
$rows [] = $res ;
}
}
echo ( json_encode ( $rows ));
}
?>