created database to store all relevant data
This commit is contained in:
37
php/Database.php
Normal file
37
php/Database.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
class Database
|
||||
{
|
||||
private static $instance = null;
|
||||
private $conn;
|
||||
|
||||
private $servername = "192.168.0.30";
|
||||
private $username = "root";
|
||||
private $password = "1qayxsw2";
|
||||
private $dbname = "hub";
|
||||
|
||||
// The db connection is established in the private constructor.
|
||||
private function __construct()
|
||||
{
|
||||
// Create connection
|
||||
$this->conn = new mysqli($this->servername, $this->username, $this->password, $this->dbname);
|
||||
|
||||
if ($this->conn->connect_errno) {
|
||||
echo "connecton failed... nr: " . $this->conn->connect_errno . " -- " . $this->conn->connect_error;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
if (!self::$instance) {
|
||||
self::$instance = new Database();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function getConnection()
|
||||
{
|
||||
return $this->conn;
|
||||
}
|
||||
}
|
@ -1,6 +1,41 @@
|
||||
<?php
|
||||
require 'Database.php';
|
||||
|
||||
$conn = Database::getInstance()->getConnection();
|
||||
|
||||
$arr = scandir("../videos/prn/");
|
||||
|
||||
$all = 0;
|
||||
$added = 0;
|
||||
$failed = 0;
|
||||
|
||||
foreach ($arr as $elem) {
|
||||
shell_exec("ffmpeg -ss 00:04:00 -i \"../videos/prn/$elem\" -vframes 1 -q:v 2 \"$elem.jpg\"");
|
||||
if ($elem != "." && $elem != "..") {
|
||||
|
||||
$query = "SELECT * FROM videos WHERE movie_name = '" . mysqli_real_escape_string($conn, $elem) . "'";
|
||||
$result = $conn->query($query);
|
||||
if (!mysqli_fetch_assoc($result)) {
|
||||
$pic = shell_exec("ffmpeg -hide_banner -loglevel panic -ss 00:04:00 -i \"../videos/prn/$elem\" -vframes 1 -q:v 2 -f singlejpeg pipe:1 2>/dev/null");
|
||||
|
||||
$image_base64 = base64_encode($pic);
|
||||
|
||||
$image = 'data:image/jpeg;base64,' . $image_base64;
|
||||
$conn = Database::getInstance()->getConnection();
|
||||
|
||||
$query = "INSERT INTO videos(movie_name,movie_url,thumbnail) VALUES ('" . mysqli_real_escape_string($conn, $elem) . "','" . mysqli_real_escape_string($conn, 'videos/prn/' . $elem) . "','$image')";
|
||||
|
||||
if ($conn->query($query) === TRUE) {
|
||||
echo('successfully added ' . $elem . " to video gravity\n");
|
||||
$added++;
|
||||
} else {
|
||||
echo('{"data":"' . $conn->error . '"}');
|
||||
$failed++;
|
||||
}
|
||||
}
|
||||
$all++;
|
||||
}
|
||||
}
|
||||
|
||||
echo "Total gravity: " . $all . "\n";
|
||||
echo "added in this run: " . $added . "\n";
|
||||
echo "errored in this run: " . $failed . "\n";
|
||||
|
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
$server = "172.17.0.2";
|
||||
$user = "mwit";
|
||||
$password = "3MnDApF3bu6XDGOE";
|
||||
$database = "mwitdb";
|
||||
|
||||
$mysqli = new mysqli($server, $user, $password, $database);
|
||||
if ($mysqli->connect_errno) {
|
||||
echo "connecton failed... nr: " . $mysqli->connect_errno . " -- " . $mysqli->connect_error;
|
||||
}
|
@ -1,8 +1,61 @@
|
||||
<?php
|
||||
require 'Database.php';
|
||||
|
||||
$conn = Database::getInstance()->getConnection();
|
||||
|
||||
$arr = scandir("../videos/prn/");
|
||||
echo(json_encode($arr));
|
||||
|
||||
if (isset($_POST['action'])) {
|
||||
$action = $_POST['action'];
|
||||
switch ($action) {
|
||||
case "getMovies":
|
||||
$query = "SELECT movie_id,movie_name FROM videos ORDER BY likes DESC,movie_name ASC";
|
||||
$result = $conn->query($query);
|
||||
$rows = array();
|
||||
while ($r = mysqli_fetch_assoc($result)) {
|
||||
array_push($rows,$r);
|
||||
}
|
||||
|
||||
echo(json_encode($rows));
|
||||
break;
|
||||
case "loadVideo":
|
||||
$query = "SELECT movie_url,thumbnail FROM videos WHERE movie_id='" . $_POST['movieid'] . "'";
|
||||
|
||||
$result = $conn->query($query);
|
||||
$row = $result->fetch_assoc();
|
||||
|
||||
$arr = array();
|
||||
$arr["thumbnail"] = $row["thumbnail"];
|
||||
$arr["movie_url"] = $row["movie_url"];
|
||||
echo(json_encode($arr));
|
||||
|
||||
break;
|
||||
case "getDbSize":
|
||||
$query = "SELECT table_schema AS \"Database\",
|
||||
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS \"Size\"
|
||||
FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA='test'
|
||||
GROUP BY table_schema;";
|
||||
$result = $conn->query($query);
|
||||
|
||||
if ($result->num_rows == 1) {
|
||||
$row = $result->fetch_assoc();
|
||||
|
||||
echo '{"data":"' . $row["Size"] . '"}';
|
||||
}
|
||||
|
||||
break;
|
||||
case "readThumbnail":
|
||||
$query = "SELECT thumbnail FROM videos WHERE movie_id='" . $_POST['movieid'] . "'";
|
||||
|
||||
$result = $conn->query($query);
|
||||
$row = $result->fetch_assoc();
|
||||
|
||||
echo($row["thumbnail"]);
|
||||
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
echo('{"data":"error"}');
|
||||
}
|
||||
return;
|
||||
|
||||
|
Reference in New Issue
Block a user