diff --git a/css/index.css b/css/index.css index 4dc4e57..66b790b 100755 --- a/css/index.css +++ b/css/index.css @@ -18,6 +18,8 @@ background-color: #7F7F7F; cursor: pointer; opacity: 0.9; + border: 10px; + border-radius: 20px; } .videopreview:hover { @@ -27,10 +29,12 @@ .previewtitle { height: 10%; + color: white; + text-align: center; } .previewpic { - height: 90%; + height: 80%; } .hideit { @@ -38,6 +42,11 @@ } .closebutton { - height: 15px; + color: white; + height: 35px; + width: 90px; + margin-right: 80px; + float: right; background-color: #FF0000; + cursor: pointer; } diff --git a/database.sql b/database.sql new file mode 100644 index 0000000..5c0a5b2 --- /dev/null +++ b/database.sql @@ -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 +); diff --git a/index.html b/index.html index 5420873..d199cb2 100755 --- a/index.html +++ b/index.html @@ -14,9 +14,7 @@

lukis pornhub

-
- -
+
Close
diff --git a/js/index.js b/js/index.js index d6e4ac5..df1c4d2 100755 --- a/js/index.js +++ b/js/index.js @@ -1,10 +1,11 @@ -var videos; -var loadindex = 0; -var scrollposition = 0; +let videos; +let loadindex = 0; +let scrollposition = 0; $(document).ready(function () { - $.post('php/videoload.php', 'action', function (data) { + $.post('php/videoload.php', 'action=getMovies', function (data) { videos = data; + console.log(videos); loadPreviewBlock(12); }, 'json'); @@ -28,44 +29,48 @@ $(window).scroll(function () { function loadPreviewBlock(nr) { for (let i = 0; i < nr; i++) { if (loadindex + i < videos.length) { - if (videos[loadindex + i] != "." && videos[loadindex + i] != "..") { - loadPreview(videos[loadindex + i]); - } else { - nr++; - } - + loadPreview(videos[loadindex + i]); } } loadindex += nr; } function loadPreview(src) { - var preview = $("
" + src + "
no thumbnail found
"); - preview.attr('videourl', "videos/prn/" + src); - preview.attr('thumbnailurl', "videos/thumbnails/" + src); - preview.click(function () { - console.log("preview clicked"); - scrollposition = $(window).scrollTop(); - loadVideo($(this).attr("videourl"), $(this).attr("thumbnailurl") + ".jpg"); - }); - $(".previewcontainer").append(preview); + $.post('php/videoload.php', 'action=readThumbnail&movieid=' + src.movie_id, function (data) { + var preview = $(` +
+
${src.movie_name}
+
+ no thumbnail found +
+
`); + preview.attr('movie_id', src.movie_id); + preview.click(function () { + console.log("preview clicked"); + scrollposition = $(window).scrollTop(); + loadVideo($(this).attr("movie_id")); + }); + $(".previewcontainer").append(preview); + }, 'text'); } -function loadVideo(src, posterlink) { - $(".videowrapper").html("
"); +function loadVideo(movieid) { + $.post('php/videoload.php', 'action=loadVideo&movieid=' + movieid, function (data) { + $(".videowrapper").html("
"); - const player = new Plyr('#player'); - player.source = { - type: 'video', - sources: [ - { - src: src, - type: 'video/mp4', - size: 1080, - } - ], - poster: posterlink - }; - $(".videopagewrapper").show(); - $(".previewcontainer").hide(); + const player = new Plyr('#player'); + player.source = { + type: 'video', + sources: [ + { + src: data.movie_url, + type: 'video/mp4', + size: 1080, + } + ], + poster: data.thumbnail + }; + $(".videopagewrapper").show(); + $(".previewcontainer").hide(); + }, "json"); } diff --git a/php/Database.php b/php/Database.php new file mode 100644 index 0000000..11c563d --- /dev/null +++ b/php/Database.php @@ -0,0 +1,37 @@ +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; + } +} diff --git a/php/extractvideopreviews.php b/php/extractvideopreviews.php index 141cd91..59b26a9 100755 --- a/php/extractvideopreviews.php +++ b/php/extractvideopreviews.php @@ -1,6 +1,41 @@ 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"; diff --git a/php/sqlinit.php b/php/sqlinit.php deleted file mode 100755 index af4eace..0000000 --- a/php/sqlinit.php +++ /dev/null @@ -1,11 +0,0 @@ -connect_errno) { - echo "connecton failed... nr: " . $mysqli->connect_errno . " -- " . $mysqli->connect_error; -} diff --git a/php/videoload.php b/php/videoload.php index 4e661af..cd8ac57 100755 --- a/php/videoload.php +++ b/php/videoload.php @@ -1,8 +1,61 @@ 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; +