improved tagging system

new settings page tab
This commit is contained in:
2020-06-03 12:26:10 +02:00
parent a74cc17e54
commit 0171133d40
11 changed files with 172 additions and 77 deletions

View File

@ -8,7 +8,7 @@ class Database
private $servername = "192.168.0.30";
private $username = "root";
private $password = "1qayxsw2";
private $dbname = "hub";
private $dbname = "mediacenter";
// The db connection is established in the private constructor.
private function __construct()

View File

@ -44,21 +44,21 @@ foreach ($arr as $elem) {
if ($video_attributes['height'] >= 1080) {
$query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,2)";
if ($conn->query($query) !== TRUE) {
echo "failed to add tag here.\n";
echo "failed to add default tag here.\n";
}
}
if ($video_attributes['height'] >= 720 && $video_attributes['height'] < 1080) {
$query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,4)";
if ($conn->query($query) !== TRUE) {
echo "failed to add tag here.\n";
echo "failed to add default tag here.\n";
}
}
if ($video_attributes['height'] < 720) {
$query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,3)";
if ($conn->query($query) !== TRUE) {
echo "failed to add tag here.\n";
echo "failed to add default tag here.\n";
}
}
$added++;
@ -125,19 +125,28 @@ function _get_video_attributes($video)
$command = "$ffmpeg -i \"../videos/prn/$video\" -vstats 2>&1";
$output = shell_exec($command);
$codec = "null";
$width = 0;
$height = 0;
$regex_sizes = "/Video: ([^,]*), ([^,]*), ([0-9]{1,4})x([0-9]{1,4})/"; // or : $regex_sizes = "/Video: ([^\r\n]*), ([^,]*), ([0-9]{1,4})x([0-9]{1,4})/"; (code from @1owk3y)
if (preg_match($regex_sizes, $output, $regs)) {
$codec = $regs [1] ? $regs [1] : null;
$width = $regs [3] ? $regs [3] : null;
$height = $regs [4] ? $regs [4] : null;
$codec = $regs [1] ? $regs [1] : "null";
$width = $regs [3] ? $regs [3] : 0;
$height = $regs [4] ? $regs [4] : 0;
}
$hours = 0;
$mins = 0;
$secs = 0;
$ms = 0;
$regex_duration = "/Duration: ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}).([0-9]{1,2})/";
if (preg_match($regex_duration, $output, $regs)) {
$hours = $regs [1] ? $regs [1] : null;
$mins = $regs [2] ? $regs [2] : null;
$secs = $regs [3] ? $regs [3] : null;
$ms = $regs [4] ? $regs [4] : null;
$hours = $regs [1] ? $regs [1] : 0;
$mins = $regs [2] ? $regs [2] : 0;
$secs = $regs [3] ? $regs [3] : 0;
$ms = $regs [4] ? $regs [4] : 0;
}
return array('codec' => $codec,

View File

@ -3,7 +3,7 @@ require 'Database.php';
$conn = Database::getInstance()->getConnection();
//$_POST['action'] = "getRandomMovies";$_POST['number'] =6;
if (isset($_POST['action'])) {
$action = $_POST['action'];
switch ($action) {
@ -28,14 +28,31 @@ if (isset($_POST['action'])) {
echo(json_encode($rows));
break;
case "getRandomMovies":
$return = new stdClass();
$query = "SELECT movie_id,movie_name FROM videos ORDER BY RAND() LIMIT " . $_POST['number'];
$result = $conn->query($query);
$rows = array();
$return->rows = array();
// get tags of random videos
$ids = [];
while ($r = mysqli_fetch_assoc($result)) {
array_push($rows, $r);
array_push($return->rows, $r);
array_push($ids,"video_tags.video_id=".$r['movie_id']);
}
echo(json_encode($rows));
$idstring = implode(" OR ",$ids);
$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";
$result = $conn->query($query);
while ($r = mysqli_fetch_assoc($result)) {
array_push($return->tags, $r);
}
echo(json_encode($return));
break;
case "loadVideo":
$query = "SELECT movie_name,movie_url,thumbnail,likes,quality,length FROM videos WHERE movie_id='" . $_POST['movieid'] . "'";
@ -50,6 +67,18 @@ if (isset($_POST['action'])) {
$arr["likes"] = $row["likes"];
$arr["quality"] = $row["quality"];
$arr["length"] = $row["length"];
// load tags of this video
$arr['tags'] = Array();
$query = "SELECT t.tag_name FROM video_tags
INNER JOIN tags t on video_tags.tag_id = t.tag_id
WHERE video_tags.video_id=".$_POST['movieid']."
GROUP BY t.tag_name";
$result = $conn->query($query);
while ($r = mysqli_fetch_assoc($result)) {
array_push($arr['tags'], $r);
}
echo(json_encode($arr));
break;
@ -77,6 +106,7 @@ if (isset($_POST['action'])) {
break;
case "getTags":
// todo add this to loadVideo maybe
$movieid = $_POST['movieid'];
$query = "SELECT tag_name FROM video_tags