This commit is contained in:
gabrielkheisa 2022-10-23 18:15:14 +07:00
commit b84c625fcc
7 changed files with 474 additions and 0 deletions

47
check.php Normal file
View File

@ -0,0 +1,47 @@
<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";
//Query params
$q = $_REQUEST["q"];
$vid = $q.".mp4";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT status FROM meme WHERE session='".$q."' ORDER BY id DESC LIMIT 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
if($row["status"] == "1"){
echo "<a href=\"$vid\">Click here</a>";
}
else {
echo "Processing";
}
}
} else {
echo "0 results";
}
$conn->close();
?>

183
index.php Normal file
View File

@ -0,0 +1,183 @@
<html>
<body>
<script src="https://cdn.jsdelivr.net/npm/js-base64@2.5.2/base64.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js" integrity="sha256-/H4YS+7aYb9kJ5OKhFYPUjSJdrtV6AeyJOtTkw6X72o=" crossorigin="anonymous"></script>
<script src="https://gabrielkheisa.xyz/js/qrcode.min.js"></script>
<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";
$sesid = rand(1,999999999);
$cookie_name = "session";
if(!isset($_COOKIE[$cookie_name])) {
//echo "Cookie named '" . $cookie_name . "' is not set!";
$cookie_value = $sesid;
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
/*
$sql = "INSERT INTO meme (session, status)
VALUES ('". $sesid ."', '0')";
if ($conn->query($sql) === TRUE) {
// echo "New record created successfully";
}
else {
// echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
*/
}
else {
// echo "Cookie '" . $cookie_name . "' is set!<br>";
// echo "Value is: " . $_COOKIE[$cookie_name];
$sesid = $_COOKIE[$cookie_name];
}
?>
<title>Meme generator</title>
<style>
.center {
margin: auto;
width: 50%;
padding: 10px;
}
body {
transition: 0.5s;
}
img {
display: block;
margin-left: auto;
margin-right: auto;
}
@media only screen and (max-width: 1100px){
body {
font-size:4em;
}
video {
width:100%;
}
h2 {
font-size:1.5em;
text-align: center;
}
h4 {
font-size:0.8em;
}
h5 {
font-size:0.8em;
}
input {
font-size:1em !important;
}
select {
font-size:0.8em !important;
}
.center {
margin: 5px;
width: 100%;
padding: 10px;
}
#tombol{
font-size:1em !important;
}
.progress {
height:50px !important;
}
}
</style>
<?php
$fileContent = file_get_contents("teks.txt");
if($fileContent != "S0VUSUtBIDEsS0VUSUtBIDIsS0VUSUtBIDMsS0VUSUtBIDQsS0VUSUtBIDUsS0VUSUtBIDYsS0VUSUtBIDcsS0VUSUtBIDgsS0VUSUtBIDks"){
echo "Server is busy";
}
else {
echo
"
<video width=\"400\" controls class=\"center\">
<source src=\"contoh.mp4\" type=\"video/mp4\">
Your browser does not support HTML video.
</video>
<br><br>
<div class=\"form-group m-3 center\">
Text 1:<input type=\"text\" id=\"text1\" value=\"KETIKA 1\" oninput=\"gae();\"><br>
Text 2:<input type=\"text\" id=\"text2\" value=\"KETIKA 2\" oninput=\"gae();\"><br>
Text 3:<input type=\"text\" id=\"text3\" value=\"KETIKA 3\" oninput=\"gae();\"><br>
Text 4:<input type=\"text\" id=\"text4\" value=\"KETIKA 4\" oninput=\"gae();\"><br>
Text 5:<input type=\"text\" id=\"text5\" value=\"KETIKA 5\" oninput=\"gae();\"><br>
Text 6:<input type=\"text\" id=\"text6\" value=\"KETIKA 6\" oninput=\"gae();\"><br>
Text 7:<input type=\"text\" id=\"text7\" value=\"KETIKA 7\" oninput=\"gae();\"><br>
Text 8:<input type=\"text\" id=\"text8\" value=\"KETIKA 8\" oninput=\"gae();\"><br>
Text 9:<input type=\"text\" id=\"text9\" value=\"KETIKA 9\" oninput=\"gae();\"><br>
</div>
<br><br>
<form action=\"process.php\" method=\"get\">
<input hidden type=\"text\" id=\"keluaran_\" name=\"hasil\"><br>
<input type=\"submit\">
</form>
";
}
?>
<script>
var nilai = [0,0,0,0,0,0,0,0,0];
var i;
function gae() {
for(i=0;i<=8;i++){
nilai[i] = document.getElementById("text"+String(i+1)).value;
}
}
function cetak() {
var keluaran = "";
for(i=0;i<=8;i++){
keluaran = keluaran + String(nilai[i]).toUpperCase() + ",";
}
document.getElementById("keluaran_").value = Base64.encode(keluaran);
}
timeout();
function timeout() {
setTimeout(function () {
cetak();
timeout();
}, 200);
}
</script>
</body>
</html>

BIN
output.mp4 Normal file

Binary file not shown.

125
process.php Normal file
View File

@ -0,0 +1,125 @@
<html>
<body>
<?php
/*
$fileContent = file_get_contents("teks.txt");
if($fileContent != "S0VUSUtBIDEsS0VUSUtBIDIsS0VUSUtBIDMsS0VUSUtBIDQsS0VUSUtBIDUsS0VUSUtBIDYsS0VUSUtBIDcsS0VUSUtBIDgsS0VUSUtBIDks"){
echo "Server is busy";
}
else {
$teks = $_GET["hasil"];
$myfile = fopen("teks.txt", "w") or die("Unable to open file!");
$txt = $teks;
fwrite($myfile, $txt);
fclose($myfile);
}
*/
$servername = "";
$username = "";
$password = "";
$dbname = "";
$sesid = rand(1,999999999);
$cookie_name = "session";
if(!isset($_COOKIE[$cookie_name])) {
//echo "Cookie named '" . $cookie_name . "' is not set!";
die("Error, please return to form");
/*
$cookie_value = $sesid;
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO meme (session, status)
VALUES ('". $sesid ."', '0')";
if ($conn->query($sql) === TRUE) {
// echo "New record created successfully";
}
else {
// echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
*/
}
else {
// echo "Cookie '" . $cookie_name . "' is set!<br>";
// echo "Value is: " . $_COOKIE[$cookie_name];
$sesid = $_COOKIE[$cookie_name];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//"UPDATE MyGuests SET lastname='Doe' WHERE id=2";
// $sql = "UPDATE meme SET status='0' value='". $_GET["hasil"]. "' WHERE sesid='". $sesid ."'";
$sql = "INSERT INTO meme (session, status, value)
VALUES ('". $sesid ."', '0', '". $_GET["hasil"] ."') ON DUPLICATE KEY UPDATE
session='".$sesid."', status='0', value='".$_GET["hasil"]."' " ;
if ($conn->query($sql) === TRUE) {
// echo "New record created successfully";
}
else {
// echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
?>
<br><br>
<p>Please wait... dont refresh<p>
<br><br>
<p id=hasil></p>
<script>
function get_ram(str, the_id) {
if (str.length == 0) {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById(the_id).innerHTML = this.responseText;
}
};
xmlhttp.open("GET", "check.php?q=" + str, true);
xmlhttp.send();
}
}
function timeout2() {
setTimeout(function () {
get_ram("<?php echo $sesid ?>","hasil");
timeout2();
}, 1000);
}
timeout2();
</script>
</body>
</html>

14
readme.md Normal file
View File

@ -0,0 +1,14 @@
<h1>Video meme generator</h1>
<h3>Generate subtitle and render it to a video</h3>
<h2>Requirements:</h2>
<ul>
<li>PHP 7.2</li>
<li>Python 3 (MoviePy, FFmpeg, MySQL module)</li>
<li>MySQL (optional, you can modify the code to use SQLite DB instead)</li>
</ul>
<h2>Preview:</h2>
<ul>
<li><a href="https://meme.gabrielkheisa.xyz/">Slander</a></li>
<li><a href="https://meme.gabrielkheisa.xyz/therock">The Rock</a></li>
<li><a href="https://meme.gabrielkheisa.xyz/noot">Noot</a></li>
</ul>

105
renderDB.py Normal file
View File

@ -0,0 +1,105 @@
#!/usr/bin/env python3
from moviepy.editor import *
import base64
import time
import textwrap
import mysql.connector
bendera = 0
theteks = ""
picture = VideoFileClip("video.mp4")
thesize = 25
def checkindo():
mycursor = mydb.cursor()
sql = "SELECT * FROM meme WHERE status = '0' "
mycursor.execute(sql)
myresult = mycursor.fetchall()
if not myresult:
print("No input video")
return
for x in myresult:
user_empty = x[1]
text_db = x[4] # Fetch from Teks
print(text_db)
if (len(user_empty)) <= 1:
print("Ok")
return
else:
print("User " + user_empty + " kosong, rendering " + str(user_empty))
text_dbd = str(base64.b64decode(text_db))
theteks = text_dbd[2:]
tp = theteks.split(",")
t1 = textwrap.fill(tp[0].upper(), thesize)
t2 = textwrap.fill(tp[1].upper(), thesize)
t3 = textwrap.fill(tp[2].upper(), thesize)
t4 = textwrap.fill(tp[3].upper(), thesize)
t5 = textwrap.fill(tp[4].upper(), thesize)
t6 = textwrap.fill(tp[5].upper(), thesize)
t7 = textwrap.fill(tp[6].upper(), thesize)
t8 = textwrap.fill(tp[7].upper(), thesize)
t9 = textwrap.fill(tp[8].upper(), thesize)
t10 = "10 KETIKA 11"
texts = [t1,t2,t3,t4,t5,t6,t7,t8,t9]
step = 3 #each 15 sec: 0, 15, 30
duration = 3
t = 0
txt_clips = []
starts = [0,3,6,9,12,15,20,23,26] # or whatever
durations = [3,3,3,3,3,5,3,3,3]
for text,t,duration in zip(texts, starts, durations):
txt_clip = TextClip(text, fontsize = 40, color='white', font="Roboto Mono", stroke_color="black")
txt_clip = txt_clip.set_start(t)
txt_clip = txt_clip.set_pos('bottom').set_duration(duration)
txt_clips.append(txt_clip)
final_video = CompositeVideoClip([picture,txt_clips[0],txt_clips[1],txt_clips[2],txt_clips[3],txt_clips[4],txt_clips[5],txt_clips[6],txt_clips[7],txt_clips[8]])
final_video.write_videofile(str(user_empty)+".mp4")
#with open('teks.txt', "w") as myfile:
#myfile.write("S0VUSUtBIDEsS0VUSUtBIDIsS0VUSUtBIDMsS0VUSUtBIDQsS0VUSUtBIDUsS0VUSUtBIDYsS0VUSUtBIDcsS0VUSUtBIDgsS0VUSUtBIDks")
sql = "UPDATE meme SET status = \'"+ "1" +"\' WHERE session = \'" + str(user_empty) +"\'"
mycursor.execute(sql)
# myresult = mycursor.fetchall()
mydb.commit()
return
while True:
mydb = mysql.connector.connect(
host="",
user="",
password="",
database=""
)
checkindo()
time.sleep(1)
# textwrap.fill(tp[0].upper(), thesize)

BIN
video.mp4 Normal file

Binary file not shown.