created database to store all relevant data

This commit is contained in:
lukas 2020-05-23 23:47:15 +02:00
parent 4ad29fd072
commit 90fdb64f85
8 changed files with 189 additions and 54 deletions

View File

@ -18,6 +18,8 @@
background-color: #7F7F7F; background-color: #7F7F7F;
cursor: pointer; cursor: pointer;
opacity: 0.9; opacity: 0.9;
border: 10px;
border-radius: 20px;
} }
.videopreview:hover { .videopreview:hover {
@ -27,10 +29,12 @@
.previewtitle { .previewtitle {
height: 10%; height: 10%;
color: white;
text-align: center;
} }
.previewpic { .previewpic {
height: 90%; height: 80%;
} }
.hideit { .hideit {
@ -38,6 +42,11 @@
} }
.closebutton { .closebutton {
height: 15px; color: white;
height: 35px;
width: 90px;
margin-right: 80px;
float: right;
background-color: #FF0000; background-color: #FF0000;
cursor: pointer;
} }

9
database.sql Normal file
View File

@ -0,0 +1,9 @@
create table if not exists videos
(
movie_id int auto_increment
primary key,
movie_name varchar(200) null,
movie_url varchar(200) null,
thumbnail mediumblob null,
likes int default 0 null
);

View File

@ -14,9 +14,7 @@
<body> <body>
<h1>lukis pornhub</h1> <h1>lukis pornhub</h1>
<div class="videopagewrapper hideit"> <div class="videopagewrapper hideit">
<div class="closebutton"> <div class="closebutton">Close</div>
</div>
<div class="videowrapper"></div> <div class="videowrapper"></div>
</div> </div>

View File

@ -1,10 +1,11 @@
var videos; let videos;
var loadindex = 0; let loadindex = 0;
var scrollposition = 0; let scrollposition = 0;
$(document).ready(function () { $(document).ready(function () {
$.post('php/videoload.php', 'action', function (data) { $.post('php/videoload.php', 'action=getMovies', function (data) {
videos = data; videos = data;
console.log(videos);
loadPreviewBlock(12); loadPreviewBlock(12);
}, 'json'); }, 'json');
@ -28,30 +29,33 @@ $(window).scroll(function () {
function loadPreviewBlock(nr) { function loadPreviewBlock(nr) {
for (let i = 0; i < nr; i++) { for (let i = 0; i < nr; i++) {
if (loadindex + i < videos.length) { if (loadindex + i < videos.length) {
if (videos[loadindex + i] != "." && videos[loadindex + i] != "..") {
loadPreview(videos[loadindex + i]); loadPreview(videos[loadindex + i]);
} else {
nr++;
}
} }
} }
loadindex += nr; loadindex += nr;
} }
function loadPreview(src) { function loadPreview(src) {
var preview = $("<div class='videopreview'><div class='previewtitle'>" + src + "</div><div class='previewpic'><img style='width:100%;height:100%' src=\"videos/thumbnails/" + src + ".jpg\" alt='no thumbnail found'></img></div></div>"); $.post('php/videoload.php', 'action=readThumbnail&movieid=' + src.movie_id, function (data) {
preview.attr('videourl', "videos/prn/" + src); var preview = $(`
preview.attr('thumbnailurl', "videos/thumbnails/" + src); <div class='videopreview'>
<div class='previewtitle'>${src.movie_name}</div>
<div class='previewpic'>
<img style='width:100%;height:100%' src="${data}" alt='no thumbnail found'/>
</div>
</div>`);
preview.attr('movie_id', src.movie_id);
preview.click(function () { preview.click(function () {
console.log("preview clicked"); console.log("preview clicked");
scrollposition = $(window).scrollTop(); scrollposition = $(window).scrollTop();
loadVideo($(this).attr("videourl"), $(this).attr("thumbnailurl") + ".jpg"); loadVideo($(this).attr("movie_id"));
}); });
$(".previewcontainer").append(preview); $(".previewcontainer").append(preview);
}, 'text');
} }
function loadVideo(src, posterlink) { function loadVideo(movieid) {
$.post('php/videoload.php', 'action=loadVideo&movieid=' + movieid, function (data) {
$(".videowrapper").html("<div class='myvideo'><video controls crossorigin playsinline id='player'></video></div>"); $(".videowrapper").html("<div class='myvideo'><video controls crossorigin playsinline id='player'></video></div>");
const player = new Plyr('#player'); const player = new Plyr('#player');
@ -59,13 +63,14 @@ function loadVideo(src, posterlink) {
type: 'video', type: 'video',
sources: [ sources: [
{ {
src: src, src: data.movie_url,
type: 'video/mp4', type: 'video/mp4',
size: 1080, size: 1080,
} }
], ],
poster: posterlink poster: data.thumbnail
}; };
$(".videopagewrapper").show(); $(".videopagewrapper").show();
$(".previewcontainer").hide(); $(".previewcontainer").hide();
}, "json");
} }

37
php/Database.php Normal file
View 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;
}
}

View File

@ -1,6 +1,41 @@
<?php <?php
require 'Database.php';
$conn = Database::getInstance()->getConnection();
$arr = scandir("../videos/prn/"); $arr = scandir("../videos/prn/");
$all = 0;
$added = 0;
$failed = 0;
foreach ($arr as $elem) { 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";

View File

@ -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;
}

View File

@ -1,8 +1,61 @@
<?php <?php
require 'Database.php';
$conn = Database::getInstance()->getConnection();
$arr = scandir("../videos/prn/");
echo(json_encode($arr));
if (isset($_POST['action'])) { 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;