2020-05-16 18:18:32 +00:00
|
|
|
<?php
|
2020-07-30 23:03:51 +00:00
|
|
|
require_once 'Database.php';
|
|
|
|
require_once 'SSettings.php';
|
|
|
|
require_once 'RequestBase.php';
|
2020-05-23 21:47:15 +00:00
|
|
|
|
2020-07-30 23:03:51 +00:00
|
|
|
class Video extends RequestBase {
|
|
|
|
private string $videopath;
|
2020-07-15 18:08:22 +00:00
|
|
|
|
2020-07-30 23:03:51 +00:00
|
|
|
public function __construct() {
|
|
|
|
$settings = new SSettings();
|
|
|
|
// load video path from settings
|
|
|
|
$this->videopath = $settings->getVideoPath();
|
|
|
|
}
|
2020-05-16 18:18:32 +00:00
|
|
|
|
2020-07-30 23:03:51 +00:00
|
|
|
function initHandlers() {
|
|
|
|
$this->addActionHandler("getMovies", function () {
|
2020-07-30 23:05:58 +00:00
|
|
|
$query = "SELECT movie_id,movie_name FROM videos ORDER BY create_date DESC, movie_name";
|
2020-06-02 14:15:12 +00:00
|
|
|
if (isset($_POST['tag'])) {
|
|
|
|
$tag = $_POST['tag'];
|
2020-06-02 20:52:28 +00:00
|
|
|
if ($_POST['tag'] != "all") {
|
2020-06-02 14:15:12 +00:00
|
|
|
$query = "SELECT movie_id,movie_name FROM videos
|
|
|
|
INNER JOIN video_tags vt on videos.movie_id = vt.video_id
|
|
|
|
INNER JOIN tags t on vt.tag_id = t.tag_id
|
|
|
|
WHERE t.tag_name = '$tag'
|
2020-07-30 23:05:58 +00:00
|
|
|
ORDER BY likes DESC, create_date, movie_name";
|
2020-06-02 14:15:12 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-30 23:03:51 +00:00
|
|
|
$result = $this->conn->query($query);
|
2020-05-29 15:19:19 +00:00
|
|
|
$rows = array();
|
|
|
|
while ($r = mysqli_fetch_assoc($result)) {
|
|
|
|
array_push($rows, $r);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo(json_encode($rows));
|
2020-07-30 23:03:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->addActionHandler("getRandomMovies", function () {
|
2020-06-03 10:26:10 +00:00
|
|
|
$return = new stdClass();
|
2020-06-02 20:52:28 +00:00
|
|
|
$query = "SELECT movie_id,movie_name FROM videos ORDER BY RAND() LIMIT " . $_POST['number'];
|
2020-07-30 23:03:51 +00:00
|
|
|
$result = $this->conn->query($query);
|
2020-06-03 10:26:10 +00:00
|
|
|
$return->rows = array();
|
|
|
|
|
|
|
|
// get tags of random videos
|
|
|
|
$ids = [];
|
2020-05-23 21:47:15 +00:00
|
|
|
while ($r = mysqli_fetch_assoc($result)) {
|
2020-06-03 10:26:10 +00:00
|
|
|
array_push($return->rows, $r);
|
2020-06-06 11:48:12 +00:00
|
|
|
array_push($ids, "video_tags.video_id=" . $r['movie_id']);
|
2020-05-23 21:47:15 +00:00
|
|
|
}
|
|
|
|
|
2020-06-06 11:48:12 +00:00
|
|
|
$idstring = implode(" OR ", $ids);
|
2020-06-03 10:26:10 +00:00
|
|
|
|
|
|
|
$return->tags = array();
|
|
|
|
$query = "SELECT t.tag_name FROM video_tags
|
|
|
|
INNER JOIN tags t on video_tags.tag_id = t.tag_id
|
|
|
|
WHERE $idstring
|
|
|
|
GROUP BY t.tag_name";
|
2020-07-30 23:03:51 +00:00
|
|
|
$result = $this->conn->query($query);
|
2020-06-03 10:26:10 +00:00
|
|
|
while ($r = mysqli_fetch_assoc($result)) {
|
|
|
|
array_push($return->tags, $r);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo(json_encode($return));
|
2020-07-30 23:03:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->addActionHandler("getSearchKeyWord", function () {
|
2020-06-12 17:48:09 +00:00
|
|
|
$search = $_POST['keyword'];
|
|
|
|
|
|
|
|
$query = "SELECT movie_id,movie_name FROM videos
|
|
|
|
WHERE movie_name LIKE '%$search%'
|
2020-07-30 23:05:58 +00:00
|
|
|
ORDER BY likes DESC, create_date DESC, movie_name";
|
2020-07-30 23:03:51 +00:00
|
|
|
$result = $this->conn->query($query);
|
2020-06-12 17:48:09 +00:00
|
|
|
$rows = array();
|
|
|
|
while ($r = mysqli_fetch_assoc($result)) {
|
|
|
|
array_push($rows, $r);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo(json_encode($rows));
|
2020-07-30 23:03:51 +00:00
|
|
|
});
|
2020-06-12 17:48:09 +00:00
|
|
|
|
2020-07-30 23:03:51 +00:00
|
|
|
$this->addActionHandler("loadVideo", function () {
|
2020-06-06 11:48:12 +00:00
|
|
|
$query = "SELECT movie_name,movie_id,movie_url,thumbnail,poster,likes,quality,length FROM videos WHERE movie_id='" . $_POST['movieid'] . "'";
|
2020-05-23 21:47:15 +00:00
|
|
|
|
2020-07-30 23:03:51 +00:00
|
|
|
$result = $this->conn->query($query);
|
2020-05-23 21:47:15 +00:00
|
|
|
$row = $result->fetch_assoc();
|
|
|
|
|
|
|
|
$arr = array();
|
2020-06-06 11:48:12 +00:00
|
|
|
if ($row["poster"] == null) {
|
2020-06-03 22:15:06 +00:00
|
|
|
$arr["thumbnail"] = $row["thumbnail"];
|
2020-06-06 11:48:12 +00:00
|
|
|
} else {
|
2020-06-03 22:15:06 +00:00
|
|
|
$arr["thumbnail"] = $row["poster"];
|
|
|
|
}
|
|
|
|
|
2020-06-06 11:48:12 +00:00
|
|
|
$arr["movie_id"] = $row["movie_id"];
|
2020-06-02 20:52:28 +00:00
|
|
|
$arr["movie_name"] = $row["movie_name"];
|
2020-07-15 18:08:22 +00:00
|
|
|
// todo drop video url from db -- maybe one with and one without extension
|
|
|
|
// extension hardcoded here!!!
|
2020-07-30 23:03:51 +00:00
|
|
|
$arr["movie_url"] = str_replace("?", "%3F", $this->videopath . $row["movie_name"] . ".mp4");
|
2020-05-24 14:16:45 +00:00
|
|
|
$arr["likes"] = $row["likes"];
|
2020-06-02 14:15:12 +00:00
|
|
|
$arr["quality"] = $row["quality"];
|
|
|
|
$arr["length"] = $row["length"];
|
2020-06-03 10:26:10 +00:00
|
|
|
|
|
|
|
// load tags of this video
|
2020-06-06 11:48:12 +00:00
|
|
|
$arr['tags'] = array();
|
2020-06-03 10:26:10 +00:00
|
|
|
$query = "SELECT t.tag_name FROM video_tags
|
|
|
|
INNER JOIN tags t on video_tags.tag_id = t.tag_id
|
2020-06-06 11:48:12 +00:00
|
|
|
WHERE video_tags.video_id=" . $_POST['movieid'] . "
|
2020-06-03 10:26:10 +00:00
|
|
|
GROUP BY t.tag_name";
|
2020-07-30 23:03:51 +00:00
|
|
|
$result = $this->conn->query($query);
|
2020-06-03 10:26:10 +00:00
|
|
|
while ($r = mysqli_fetch_assoc($result)) {
|
|
|
|
array_push($arr['tags'], $r);
|
|
|
|
}
|
|
|
|
|
2020-05-23 21:47:15 +00:00
|
|
|
echo(json_encode($arr));
|
2020-07-30 23:03:51 +00:00
|
|
|
});
|
2020-05-23 21:47:15 +00:00
|
|
|
|
2020-07-30 23:03:51 +00:00
|
|
|
$this->addActionHandler("getDbSize", function () {
|
2020-07-21 21:16:29 +00:00
|
|
|
$dbname = Database::getInstance()->getDatabaseName();
|
|
|
|
|
2020-05-23 21:47:15 +00:00
|
|
|
$query = "SELECT table_schema AS \"Database\",
|
|
|
|
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS \"Size\"
|
|
|
|
FROM information_schema.TABLES
|
2020-07-21 21:16:29 +00:00
|
|
|
WHERE TABLE_SCHEMA='$dbname'
|
2020-05-23 21:47:15 +00:00
|
|
|
GROUP BY table_schema;";
|
2020-07-30 23:03:51 +00:00
|
|
|
$result = $this->conn->query($query);
|
2020-05-23 21:47:15 +00:00
|
|
|
|
|
|
|
if ($result->num_rows == 1) {
|
|
|
|
$row = $result->fetch_assoc();
|
2020-05-24 09:49:37 +00:00
|
|
|
echo '{"data":"' . $row["Size"] . 'MB"}';
|
2020-05-23 21:47:15 +00:00
|
|
|
}
|
2020-07-30 23:03:51 +00:00
|
|
|
});
|
2020-05-23 21:47:15 +00:00
|
|
|
|
2020-07-30 23:03:51 +00:00
|
|
|
$this->addActionHandler("readThumbnail", function () {
|
2020-05-23 21:47:15 +00:00
|
|
|
$query = "SELECT thumbnail FROM videos WHERE movie_id='" . $_POST['movieid'] . "'";
|
|
|
|
|
2020-07-30 23:03:51 +00:00
|
|
|
$result = $this->conn->query($query);
|
2020-05-23 21:47:15 +00:00
|
|
|
$row = $result->fetch_assoc();
|
|
|
|
|
|
|
|
echo($row["thumbnail"]);
|
2020-07-30 23:03:51 +00:00
|
|
|
});
|
2020-05-23 21:47:15 +00:00
|
|
|
|
2020-07-30 23:03:51 +00:00
|
|
|
$this->addActionHandler("getTags", function () {
|
2020-06-03 10:26:10 +00:00
|
|
|
// todo add this to loadVideo maybe
|
2020-05-24 14:16:45 +00:00
|
|
|
$movieid = $_POST['movieid'];
|
|
|
|
|
|
|
|
$query = "SELECT tag_name FROM video_tags
|
|
|
|
INNER JOIN tags t on video_tags.tag_id = t.tag_id
|
|
|
|
WHERE video_id='$movieid'";
|
2020-05-24 09:49:37 +00:00
|
|
|
|
2020-07-30 23:03:51 +00:00
|
|
|
$result = $this->conn->query($query);
|
2020-05-24 09:49:37 +00:00
|
|
|
|
2020-05-24 14:16:45 +00:00
|
|
|
$rows = array();
|
|
|
|
$rows['tags'] = array();
|
|
|
|
while ($r = mysqli_fetch_assoc($result)) {
|
|
|
|
array_push($rows['tags'], $r['tag_name']);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo(json_encode($rows));
|
2020-07-30 23:03:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->addActionHandler("addLike", function () {
|
2020-05-24 14:16:45 +00:00
|
|
|
$movieid = $_POST['movieid'];
|
|
|
|
|
|
|
|
$query = "update videos set likes = likes + 1 where movie_id = '$movieid'";
|
2020-05-24 09:49:37 +00:00
|
|
|
|
2020-07-30 23:03:51 +00:00
|
|
|
if ($this->conn->query($query) === TRUE) {
|
2020-05-24 14:16:45 +00:00
|
|
|
echo('{"result":"success"}');
|
|
|
|
} else {
|
2020-07-30 23:03:51 +00:00
|
|
|
echo('{"result":"' . $this->conn->error . '"}');
|
2020-05-24 14:16:45 +00:00
|
|
|
}
|
2020-07-30 23:03:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->addActionHandler("getStartData", function () {
|
2020-06-02 20:52:28 +00:00
|
|
|
$query = "SELECT COUNT(*) as nr FROM videos";
|
2020-07-30 23:03:51 +00:00
|
|
|
$result = $this->conn->query($query);
|
2020-06-02 20:52:28 +00:00
|
|
|
$r = mysqli_fetch_assoc($result);
|
|
|
|
|
|
|
|
$arr = array();
|
|
|
|
$arr['total'] = $r['nr'];
|
|
|
|
|
|
|
|
$query = "SELECT COUNT(*) as nr FROM videos
|
|
|
|
INNER JOIN video_tags vt on videos.movie_id = vt.video_id
|
|
|
|
INNER JOIN tags t on vt.tag_id = t.tag_id";
|
2020-07-30 23:03:51 +00:00
|
|
|
$result = $this->conn->query($query);
|
2020-06-02 20:52:28 +00:00
|
|
|
$r = mysqli_fetch_assoc($result);
|
|
|
|
$arr['tagged'] = $r['nr'];
|
|
|
|
|
|
|
|
$query = "SELECT COUNT(*) as nr FROM videos
|
|
|
|
INNER JOIN video_tags vt on videos.movie_id = vt.video_id
|
|
|
|
INNER JOIN tags t on vt.tag_id = t.tag_id
|
|
|
|
WHERE t.tag_name='hd'";
|
2020-07-30 23:03:51 +00:00
|
|
|
$result = $this->conn->query($query);
|
2020-06-02 20:52:28 +00:00
|
|
|
$r = mysqli_fetch_assoc($result);
|
|
|
|
$arr['hd'] = $r['nr'];
|
|
|
|
|
|
|
|
$query = "SELECT COUNT(*) as nr FROM videos
|
|
|
|
INNER JOIN video_tags vt on videos.movie_id = vt.video_id
|
|
|
|
INNER JOIN tags t on vt.tag_id = t.tag_id
|
|
|
|
WHERE t.tag_name='fullhd'";
|
2020-07-30 23:03:51 +00:00
|
|
|
$result = $this->conn->query($query);
|
2020-06-02 20:52:28 +00:00
|
|
|
$r = mysqli_fetch_assoc($result);
|
|
|
|
$arr['fullhd'] = $r['nr'];
|
|
|
|
|
|
|
|
$query = "SELECT COUNT(*) as nr FROM videos
|
|
|
|
INNER JOIN video_tags vt on videos.movie_id = vt.video_id
|
|
|
|
INNER JOIN tags t on vt.tag_id = t.tag_id
|
|
|
|
WHERE t.tag_name='lowquality'";
|
2020-07-30 23:03:51 +00:00
|
|
|
$result = $this->conn->query($query);
|
2020-06-02 20:52:28 +00:00
|
|
|
$r = mysqli_fetch_assoc($result);
|
|
|
|
$arr['sd'] = $r['nr'];
|
|
|
|
|
|
|
|
$query = "SELECT COUNT(*) as nr FROM tags";
|
2020-07-30 23:03:51 +00:00
|
|
|
$result = $this->conn->query($query);
|
2020-06-02 20:52:28 +00:00
|
|
|
$r = mysqli_fetch_assoc($result);
|
|
|
|
$arr['tags'] = $r['nr'];
|
|
|
|
|
|
|
|
echo(json_encode($arr));
|
2020-07-30 23:03:51 +00:00
|
|
|
});
|
2020-06-06 11:48:12 +00:00
|
|
|
|
2020-07-30 23:03:51 +00:00
|
|
|
$this->addActionHandler("getAllTags", function () {
|
2020-06-06 11:48:12 +00:00
|
|
|
$query = "SELECT tag_name,tag_id from tags";
|
2020-07-30 23:03:51 +00:00
|
|
|
$result = $this->conn->query($query);
|
2020-06-06 11:48:12 +00:00
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
while ($r = mysqli_fetch_assoc($result)) {
|
|
|
|
array_push($rows, $r);
|
|
|
|
}
|
|
|
|
echo(json_encode($rows));
|
2020-07-30 23:03:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->addActionHandler("addTag", function () {
|
2020-06-06 11:48:12 +00:00
|
|
|
$movieid = $_POST['movieid'];
|
|
|
|
$tagid = $_POST['id'];
|
|
|
|
|
|
|
|
$query = "INSERT INTO video_tags(tag_id, video_id) VALUES ('$tagid','$movieid')";
|
|
|
|
|
2020-07-30 23:03:51 +00:00
|
|
|
if ($this->conn->query($query) === TRUE) {
|
2020-06-06 11:48:12 +00:00
|
|
|
echo('{"result":"success"}');
|
|
|
|
} else {
|
2020-07-30 23:03:51 +00:00
|
|
|
echo('{"result":"' . $this->conn->error . '"}');
|
2020-06-06 11:48:12 +00:00
|
|
|
}
|
2020-07-30 23:03:51 +00:00
|
|
|
});
|
2020-05-23 21:47:15 +00:00
|
|
|
}
|
2020-05-16 18:18:32 +00:00
|
|
|
}
|
2020-05-23 21:47:15 +00:00
|
|
|
|
2020-07-30 23:03:51 +00:00
|
|
|
$video = new Video();
|
|
|
|
$video->handleAction();
|