From f569d267445c319b83af2cc44b01621927cdbf7c Mon Sep 17 00:00:00 2001 From: Sundog Date: Tue, 3 Sep 2024 10:37:30 -0400 Subject: [PATCH] initial commit --- README.md | 0 composer.json | 5 + edl.php | 31 +++ index.php | 226 +++++++++++++++++ layout.html | 660 ++++++++++++++++++++++++++++++++++++++++++++++++++ media.php | 48 ++++ play.php | 29 +++ tags.php | 91 +++++++ update.php | 34 +++ upload.php | 49 ++++ 10 files changed, 1173 insertions(+) create mode 100644 README.md create mode 100644 composer.json create mode 100644 edl.php create mode 100644 index.php create mode 100644 layout.html create mode 100644 media.php create mode 100644 play.php create mode 100644 tags.php create mode 100644 update.php create mode 100644 upload.php diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..9f4ee7d --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "php-ffmpeg/php-ffmpeg": "^1.2" + } +} diff --git a/edl.php b/edl.php new file mode 100644 index 0000000..b2e4b4d --- /dev/null +++ b/edl.php @@ -0,0 +1,31 @@ +prepare("SELECT * FROM media WHERE id = :id"); + $query->bindValue(':id', $id); + $result = $query->execute(); + + if ($result) { + // record exists + $update_query = $db->prepare("INSERT INTO media_edls (media_id, edl_name, edl_contents) VALUES (:media_id, :edl_name, :edl_contents)"); + $update_query->bindValue(':media_id', $_REQUEST['id']); + $update_query->bindValue(':edl_name', $_REQUEST['edl_name']); + $update_query->bindValue(':edl_contents', $_REQUEST['edl_contents']); + $update_result = $update_query->execute(); + if ($update_result) { + $query = $db->prepare("SELECT * FROM media m JOIN media_edls em ON m.id = me.media_id WHERE m.id = :id"); + $query->bindValue(':id', $id); + $final_result = $query->execute(); + if ($final_result) { + echo(json_encode($final_result->fetchArray(SQLITE3_ASSOC))); + } + } + } +} + +?> diff --git a/index.php b/index.php new file mode 100644 index 0000000..9e25985 --- /dev/null +++ b/index.php @@ -0,0 +1,226 @@ + + + + NETV MAM + + + + + +

NETV MAM

+
+
+
+ +
+
+

Preview

+
+
+

On-Air

+
+
+ +
+
+
+
+
Library
+
Scheduler
+
EPG
+
+
+
+
+
+ +
+ +
+
+
+ +
+
+
+
+ Scheduler goes here +
+
+ EPG goes here +
+
+
+
Drop A Video File Here To Upload
+
+
+ + + + + diff --git a/layout.html b/layout.html new file mode 100644 index 0000000..78cd830 --- /dev/null +++ b/layout.html @@ -0,0 +1,660 @@ + + + + + NETV MAM + + + +
+
+

NETV MAM

+

+

+
+ +
+
+ +
+ +
+
+ + + + + + + + + diff --git a/media.php b/media.php new file mode 100644 index 0000000..3987ae0 --- /dev/null +++ b/media.php @@ -0,0 +1,48 @@ +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 * 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 * FROM media ORDER BY id DESC"; + $result = $db->query($query); + if ($result) { + $rows = array(); + while ($res = $result->fetchArray(SQLITE3_ASSOC)) { + $rows[] = $res; + } + } + echo(json_encode($rows)); + } + +?> diff --git a/play.php b/play.php new file mode 100644 index 0000000..ef37198 --- /dev/null +++ b/play.php @@ -0,0 +1,29 @@ +prepare("SELECT * FROM media WHERE id = :id"); + $query->bindValue(':id', intval($_GET['id'])); + $result = $query->execute(); + + if ($result) { + $row = $result->fetchArray(SQLITE3_ASSOC); + $path = $row['source_path']; + + // get the file's mime type to send the correct content type header + $finfo = finfo_open(FILEINFO_MIME_TYPE); + $mime_type = finfo_file($finfo, $path); + $public_name = basename($path); + + // send the headers + if (isset($_GET['download']) && $_GET['download'] === "true") { header("Content-Disposition: attachment; filename=$public_name;"); } + header("Content-Type: $mime_type"); + header('Content-Length: ' . filesize($path)); + + $fp = fopen($path, 'rb'); + fpassthru($fp); + exit; + } + } +?> diff --git a/tags.php b/tags.php new file mode 100644 index 0000000..e389ccd --- /dev/null +++ b/tags.php @@ -0,0 +1,91 @@ +prepare("INSERT INTO tags (tag) VALUES (:new_tag)"); + $query->bindValue(":new_tag", $_POST['new_tag']); + $result = $query->execute(); + + if ($result) { + $id = $db->lastInsertRowID(); + $record = array( + "id" => $id, + "tag" => $_POST['new_tag'] + ); + header('Content-Type: application/json'); + echo(json_encode($record)); + exit(); + } +} else if (isset($_GET['enable']) && isset($_GET['media_id']) && intval($_GET['media_id']) > -1 && isset($_GET['tag_id']) && intval($_GET['tag_id']) > -1) { + // set or unset tag for media_id + if ($_GET['enable'] === "true") { + $query = $db->prepare("INSERT INTO media_tags (media_id, tag_id) VALUES (:media_id, :tag_id)"); + } else { + $query = $db->prepare("DELETE FROM media_tags WHERE media_id = :media_id AND tag_id = :tag_id"); + } + $query->bindValue(":media_id", $_GET['media_id']); + $query->bindValue(":tag_id", $_GET['tag_id']); + $result = $query->execute(); + + header("Content-Type: application/json"); + if ($result) { + echo('{"ok": true}'); + } else { + echo('{"ok": false}'); + } + exit(); +} else if (isset($_GET['media_id']) && intval($_GET['media_id']) > -1) { + // get all tags and on/off status for a particular media item + $tagsQuery = "SELECT * FROM tags ORDER BY tag ASC"; + $tagsResult = $db->query($tagsQuery); + + if ($tagsResult) { + $tags = array(); + + while ($row = $tagsResult->fetchArray(SQLITE3_ASSOC)) { + $tags[] = $row; + } + + $tagsForMediaQuery = $db->prepare("SELECT * FROM media_tags WHERE media_id = :media_id"); + $tagsForMediaQuery->bindValue(":media_id", intval($_GET['media_id'])); + $tagsForMediaResult = $tagsForMediaQuery->execute(); + + if ($tagsForMediaResult) { + $tagsForMedia = array(); + + while ($row = $tagsForMediaResult->fetchArray(SQLITE3_ASSOC)) { + $tagsForMedia[] = $row['tag_id']; + } + + for ($i = 0; $i < sizeof($tags); $i++) { + if (array_search($tags[$i]['id'], $tagsForMedia) !== false) { + $tags[$i]['enabled'] = 'true'; + } else { + $tags[$i]['enabled'] = 'false'; + } + } + + header('Content-Type: application/json'); + echo(json_encode($tags)); + } + } +} else { + // get all tags + $query = "SELECT * FROM tags ORDER BY tag ASC"; + $result = $db->query($query); + + if ($result) { + $rows = array(); + header('Content-Type: application/json'); + while ($row = $result->fetchArray(SQLITE3_ASSOC)) { + $rows[] = $row; + } + echo( json_encode($rows) ); + } + exit(); +} + +?> diff --git a/update.php b/update.php new file mode 100644 index 0000000..54c57ba --- /dev/null +++ b/update.php @@ -0,0 +1,34 @@ +prepare("SELECT * FROM media WHERE id = :id"); + $query->bindValue(':id', $id); + $result = $query->execute(); + + if ($result) { + // record exists, update it + $update_query = $db->prepare("UPDATE media SET title=:title, description=:description, season=:season, episode_number=:episode_number WHERE id = :id"); + $update_query->bindValue(':title', $_REQUEST['title']); + $update_query->bindValue(':description', $_REQUEST['description']); + $update_query->bindValue(':season', $_REQUEST['season']); + $update_query->bindValue(':episode_number', $_REQUEST['episode_number']); + $update_query->bindValue(':id', $id); + error_log($update_query->getSQL(true)); + $update_result = $update_query->execute(); + if ($update_result) { + $query = $db->prepare("SELECT * FROM media WHERE id = :id"); + $query->bindValue(':id', $id); + $final_result = $query->execute(); + if ($final_result) { + echo(json_encode($final_result->fetchArray(SQLITE3_ASSOC))); + } + } + } +} + +?> diff --git a/upload.php b/upload.php new file mode 100644 index 0000000..05bc4ab --- /dev/null +++ b/upload.php @@ -0,0 +1,49 @@ +format($uploadfile) + ->get('duration'); + + $query = "INSERT INTO media (source_path, title, duration_secs) VALUES (:source_path, 'unknown', :duration_secs)"; + $statement = $db->prepare($query); + $statement->bindValue(':source_path', $uploadfile); + $statement->bindValue(':duration_secs', $duration_secs); + $result = $statement->execute(); + if ($result) { + $new_media_file = array( + 'id' => $db->lastInsertRowID(), + 'title' => 'unknown', + 'source_path' => $uploadfile, + 'duration_secs' => $duration_secs, + 'has_metadata' => false + ); + error_log("Adding media file:"); + error_log(json_encode($new_media_file)); + echo(json_encode($new_media_file)); + } else { + error_log("Problem inserting new media into db:"); + error_log($db->lastErrorMsg()); + echo("{}"); + } + } else { + echo("{}"); + } + +?>