commit
fa2d048625
@ -1,4 +1,4 @@
|
|||||||
blank_issues_enabled: true
|
blank_issues_enabled: false
|
||||||
contact_links:
|
contact_links:
|
||||||
- name: Ask a question
|
- name: Ask a question
|
||||||
about: Join our discord server to ask questions and discuss with maintainers and contributors.
|
about: Join our discord server to ask questions and discuss with maintainers and contributors.
|
||||||
|
@ -1,32 +1,118 @@
|
|||||||
# Import the server module
|
|
||||||
import http.server
|
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# Used "tomlkit" instead of "toml" because it doesn't change formatting on "dump"
|
||||||
|
import tomlkit
|
||||||
|
from flask import (
|
||||||
|
Flask,
|
||||||
|
redirect,
|
||||||
|
render_template,
|
||||||
|
request,
|
||||||
|
send_from_directory,
|
||||||
|
url_for,
|
||||||
|
)
|
||||||
|
|
||||||
|
import utils.gui_utils as gui
|
||||||
|
|
||||||
# Set the hostname
|
# Set the hostname
|
||||||
HOST = "localhost"
|
HOST = "localhost"
|
||||||
# Set the port number
|
# Set the port number
|
||||||
PORT = 4000
|
PORT = 4000
|
||||||
|
|
||||||
# Define class to display the index page of the web server
|
# Configure application
|
||||||
class PythonServer(http.server.SimpleHTTPRequestHandler):
|
app = Flask(__name__, template_folder="GUI")
|
||||||
def do_GET(self):
|
|
||||||
if self.path == "/GUI":
|
# Configure secret key only to use 'flash'
|
||||||
self.path = "index.html"
|
app.secret_key = b'_5#y2L"F4Q8z\n\xec]/'
|
||||||
return http.server.SimpleHTTPRequestHandler.do_GET(self)
|
|
||||||
|
|
||||||
|
# Ensure responses aren't cached
|
||||||
# Declare object of the class
|
@app.after_request
|
||||||
webServer = http.server.HTTPServer((HOST, PORT), PythonServer)
|
def after_request(response):
|
||||||
# Print the URL of the webserver, new =2 opens in a new tab
|
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
|
||||||
print(f"Server started at http://{HOST}:{PORT}/GUI/")
|
response.headers["Expires"] = 0
|
||||||
webbrowser.open(f"http://{HOST}:{PORT}/GUI/", new=2)
|
response.headers["Pragma"] = "no-cache"
|
||||||
print("Website opened in new tab")
|
return response
|
||||||
print("Press Ctrl+C to quit")
|
|
||||||
try:
|
|
||||||
# Run the web server
|
# Display index.html
|
||||||
webServer.serve_forever()
|
@app.route("/")
|
||||||
except KeyboardInterrupt:
|
def index():
|
||||||
# Stop the web server
|
return render_template("index.html", file="videos.json")
|
||||||
webServer.server_close()
|
|
||||||
print("The server is stopped.")
|
|
||||||
exit()
|
@app.route("/backgrounds", methods=["GET"])
|
||||||
|
def backgrounds():
|
||||||
|
return render_template("backgrounds.html", file="backgrounds.json")
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/background/add", methods=["POST"])
|
||||||
|
def background_add():
|
||||||
|
# Get form values
|
||||||
|
youtube_uri = request.form.get("youtube_uri").strip()
|
||||||
|
filename = request.form.get("filename").strip()
|
||||||
|
citation = request.form.get("citation").strip()
|
||||||
|
position = request.form.get("position").strip()
|
||||||
|
|
||||||
|
gui.add_background(youtube_uri, filename, citation, position)
|
||||||
|
|
||||||
|
return redirect(url_for("backgrounds"))
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/background/delete", methods=["POST"])
|
||||||
|
def background_delete():
|
||||||
|
key = request.form.get("background-key")
|
||||||
|
gui.delete_background(key)
|
||||||
|
|
||||||
|
return redirect(url_for("backgrounds"))
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/settings", methods=["GET", "POST"])
|
||||||
|
def settings():
|
||||||
|
config_load = tomlkit.loads(Path("config.toml").read_text())
|
||||||
|
config = gui.get_config(config_load)
|
||||||
|
|
||||||
|
# Get checks for all values
|
||||||
|
checks = gui.get_checks()
|
||||||
|
|
||||||
|
if request.method == "POST":
|
||||||
|
# Get data from form as dict
|
||||||
|
data = request.form.to_dict()
|
||||||
|
|
||||||
|
# Change settings
|
||||||
|
config = gui.modify_settings(data, config_load, checks)
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
"settings.html", file="config.toml", data=config, checks=checks
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Make videos.json accessible
|
||||||
|
@app.route("/videos.json")
|
||||||
|
def videos_json():
|
||||||
|
return send_from_directory("video_creation/data", "videos.json")
|
||||||
|
|
||||||
|
|
||||||
|
# Make backgrounds.json accessible
|
||||||
|
@app.route("/backgrounds.json")
|
||||||
|
def backgrounds_json():
|
||||||
|
return send_from_directory("utils", "backgrounds.json")
|
||||||
|
|
||||||
|
|
||||||
|
# Make videos in results folder accessible
|
||||||
|
@app.route("/results/<path:name>")
|
||||||
|
def results(name):
|
||||||
|
return send_from_directory("results", name, as_attachment=True)
|
||||||
|
|
||||||
|
|
||||||
|
# Make voices samples in voices folder accessible
|
||||||
|
@app.route("/voices/<path:name>")
|
||||||
|
def voices(name):
|
||||||
|
return send_from_directory("GUI/voices", name, as_attachment=True)
|
||||||
|
|
||||||
|
|
||||||
|
# Run browser and start the app
|
||||||
|
if __name__ == "__main__":
|
||||||
|
webbrowser.open(f"http://{HOST}:{PORT}", new=2)
|
||||||
|
print("Website opened in new tab. Refresh if it didn't load.")
|
||||||
|
app.run(port=PORT)
|
||||||
|
@ -0,0 +1,263 @@
|
|||||||
|
{% extends "layout.html" %}
|
||||||
|
{% block main %}
|
||||||
|
|
||||||
|
<!-- Delete Background Modal -->
|
||||||
|
<div class="modal fade" id="deleteBtnModal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">Delete background</h5>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
Are you sure you want to delete this background?
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||||
|
<form action="background/delete" method="post">
|
||||||
|
<input type="hidden" id="background-key" name="background-key" value="">
|
||||||
|
<button type="submit" class="btn btn-danger">Delete</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Add Background Modal -->
|
||||||
|
<div class="modal fade" id="backgroundAddModal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">Add background video</h5>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
|
||||||
|
<!-- Add video form -->
|
||||||
|
<form id="addBgForm" action="background/add" method="post" novalidate>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-4 col-form-label" for="youtube_uri">YouTube URI</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-text">
|
||||||
|
<i class="bi bi-youtube"></i>
|
||||||
|
</div>
|
||||||
|
<input name="youtube_uri" placeholder="https://www.youtube.com/watch?v=..." type="text"
|
||||||
|
class="form-control">
|
||||||
|
</div>
|
||||||
|
<span id="feedbackYT" class="form-text feedback-invalid"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="filename" class="col-4 col-form-label">Filename</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-text">
|
||||||
|
<i class="bi bi-file-earmark"></i>
|
||||||
|
</div>
|
||||||
|
<input name="filename" placeholder="Example: cool-background" type="text"
|
||||||
|
class="form-control">
|
||||||
|
</div>
|
||||||
|
<span id="feedbackFilename" class="form-text feedback-invalid"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="citation" class="col-4 col-form-label">Credits (owner of the video)</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-text">
|
||||||
|
<i class="bi bi-person-circle"></i>
|
||||||
|
</div>
|
||||||
|
<input name="citation" placeholder="YouTube Channel" type="text" class="form-control">
|
||||||
|
</div>
|
||||||
|
<span class="form-text text-muted">Include the channel name of the
|
||||||
|
owner of the background video you are adding.</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="position" class="col-4 col-form-label">Position of screenshots</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-text">
|
||||||
|
<i class="bi bi-arrows-fullscreen"></i>
|
||||||
|
</div>
|
||||||
|
<input name="position" placeholder="Example: center" type="text" class="form-control">
|
||||||
|
</div>
|
||||||
|
<span class="form-text text-muted">Advanced option (you can leave it
|
||||||
|
empty). Valid options are "center" and decimal numbers</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||||
|
<button name="submit" type="submit" class="btn btn-success">Add background</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<div class="album py-2 bg-light">
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<div class="row justify-content-between mt-2">
|
||||||
|
<div class="col-12 col-md-3 mb-3">
|
||||||
|
<input type="text" class="form-control searchFilter" placeholder="Search backgrounds"
|
||||||
|
onkeyup="searchFilter()">
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-2 mb-3">
|
||||||
|
<button type="button" class="btn btn-primary form-control" data-toggle="modal"
|
||||||
|
data-target="#backgroundAddModal">
|
||||||
|
Add background video
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3" id="backgrounds">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var keys = [];
|
||||||
|
var youtube_urls = [];
|
||||||
|
|
||||||
|
// Show background videos
|
||||||
|
$(document).ready(function () {
|
||||||
|
$.getJSON("backgrounds.json",
|
||||||
|
function (data) {
|
||||||
|
delete data["__comment"];
|
||||||
|
var background = '';
|
||||||
|
$.each(data, function (key, value) {
|
||||||
|
// Add YT urls and keys (for validation)
|
||||||
|
keys.push(key);
|
||||||
|
youtube_urls.push(value[0]);
|
||||||
|
|
||||||
|
background += '<div class="col">';
|
||||||
|
background += '<div class="card shadow-sm">';
|
||||||
|
background += '<iframe class="bd-placeholder-img card-img-top" width="100%" height="225" src="https://www.youtube-nocookie.com/embed/' + value[0].split("?v=")[1] + '" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';
|
||||||
|
background += '<div class="card-body">';
|
||||||
|
background += '<p class="card-text">' + value[2] + ' • ' + key + '</p>';
|
||||||
|
background += '<div class="d-flex justify-content-between align-items-center">';
|
||||||
|
background += '<div class="btn-group">';
|
||||||
|
background += '<button type="button" class="btn btn-outline-danger" data-toggle="modal" data-target="#deleteBtnModal" data-background-key="' + key + '">Delete</button>';
|
||||||
|
background += '</div>';
|
||||||
|
background += '</div>';
|
||||||
|
background += '</div>';
|
||||||
|
background += '</div>';
|
||||||
|
background += '</div>';
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#backgrounds').append(background);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add background key when deleting
|
||||||
|
$('#deleteBtnModal').on('show.bs.modal', function (event) {
|
||||||
|
var button = $(event.relatedTarget);
|
||||||
|
var key = button.data('background-key');
|
||||||
|
|
||||||
|
$('#background-key').prop('value', key);
|
||||||
|
});
|
||||||
|
|
||||||
|
var searchFilter = () => {
|
||||||
|
const input = document.querySelector(".searchFilter");
|
||||||
|
const cards = document.getElementsByClassName("col");
|
||||||
|
console.log(cards[1])
|
||||||
|
let filter = input.value
|
||||||
|
for (let i = 0; i < cards.length; i++) {
|
||||||
|
let title = cards[i].querySelector(".card-text");
|
||||||
|
if (title.innerText.toLowerCase().indexOf(filter.toLowerCase()) > -1) {
|
||||||
|
cards[i].classList.remove("d-none")
|
||||||
|
} else {
|
||||||
|
cards[i].classList.add("d-none")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate form
|
||||||
|
$("#addBgForm").submit(function (event) {
|
||||||
|
$("#addBgForm input").each(function () {
|
||||||
|
if (!(validate($(this)))) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#addBgForm input[type="text"]').on("keyup", function () {
|
||||||
|
validate($(this));
|
||||||
|
});
|
||||||
|
|
||||||
|
function validate(object) {
|
||||||
|
let bool = check(object.prop("name"), object.prop("value"));
|
||||||
|
|
||||||
|
// Change class
|
||||||
|
if (bool) {
|
||||||
|
object.removeClass("is-invalid");
|
||||||
|
object.addClass("is-valid");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
object.removeClass("is-valid");
|
||||||
|
object.addClass("is-invalid");
|
||||||
|
}
|
||||||
|
|
||||||
|
return bool;
|
||||||
|
|
||||||
|
// Check values (return true/false)
|
||||||
|
function check(name, value) {
|
||||||
|
if (name == "youtube_uri") {
|
||||||
|
// URI validation
|
||||||
|
let regex = /(?:\/|%3D|v=|vi=)([0-9A-z-_]{11})(?:[%#?&]|$)/;
|
||||||
|
if (!(regex.test(value))) {
|
||||||
|
$("#feedbackYT").html("Invalid URI");
|
||||||
|
$("#feedbackYT").show();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if this background already exists
|
||||||
|
if (youtube_urls.includes(value)) {
|
||||||
|
$("#feedbackYT").html("This background is already added");
|
||||||
|
$("#feedbackYT").show();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#feedbackYT").hide();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name == "filename") {
|
||||||
|
// Check if key is already taken
|
||||||
|
if (keys.includes(value)) {
|
||||||
|
$("#feedbackFilename").html("This filename is already taken");
|
||||||
|
$("#feedbackFilename").show();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let regex = /^([a-zA-Z0-9\s_-]{1,100})$/;
|
||||||
|
if (!(regex.test(value))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name == "citation") {
|
||||||
|
if (value.trim()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name == "position") {
|
||||||
|
if (!(value == "center" || value.length == 0 || value % 1 == 0)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{% endblock %}
|
@ -0,0 +1,142 @@
|
|||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<meta http-equiv="cache-control" content="no-cache" />
|
||||||
|
<title>RedditVideoMakerBot</title>
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/css/bootstrap.min.css"
|
||||||
|
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
|
||||||
|
<link href="https://getbootstrap.com/docs/5.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/bootstrap-icons.css">
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.bd-placeholder-img {
|
||||||
|
font-size: 1.125rem;
|
||||||
|
text-anchor: middle;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
-moz-user-select: none;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.feedback-invalid {
|
||||||
|
color: #dc3545;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 768px) {
|
||||||
|
.bd-placeholder-img-lg {
|
||||||
|
font-size: 3.5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.bi {
|
||||||
|
vertical-align: -.125em;
|
||||||
|
fill: currentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
padding-bottom: 1rem;
|
||||||
|
margin-top: -1px;
|
||||||
|
overflow-x: auto;
|
||||||
|
text-align: center;
|
||||||
|
white-space: nowrap;
|
||||||
|
-webkit-overflow-scrolling: touch;
|
||||||
|
}
|
||||||
|
|
||||||
|
#tooltip {
|
||||||
|
background-color: #333;
|
||||||
|
color: white;
|
||||||
|
padding: 5px 10px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tooltip-inner {
|
||||||
|
max-width: 500px !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<script src="https://code.jquery.com/jquery-3.1.1.js" integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA="
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.14.3/dist/umd/popper.min.js"
|
||||||
|
integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/js/bootstrap.min.js"
|
||||||
|
integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.10/clipboard.min.js"></script>
|
||||||
|
<script src="https://unpkg.com/isotope-layout@3/dist/isotope.pkgd.js"></script>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
{% if get_flashed_messages() %}
|
||||||
|
{% for category, message in get_flashed_messages(with_categories=true) %}
|
||||||
|
|
||||||
|
{% if category == "error" %}
|
||||||
|
<div class="alert alert-danger mb-0 text-center" role="alert">
|
||||||
|
{{ message }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
<div class="alert alert-success mb-0 text-center" role="alert">
|
||||||
|
{{ message }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||||
|
<div class="container">
|
||||||
|
<a href="/" class="navbar-brand d-flex align-items-center">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" stroke="currentColor"
|
||||||
|
stroke-linecap="round" stroke-linejoin="round" stroke-width="2" aria-hidden="true" class="me-2"
|
||||||
|
viewBox="0 0 24 24">
|
||||||
|
<path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z" />
|
||||||
|
<circle cx="12" cy="13" r="4" />
|
||||||
|
</svg>
|
||||||
|
<strong>RedditVideoMakerBot</strong>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<div class="collapse navbar-collapse">
|
||||||
|
<ul class="navbar-nav mr-auto">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="backgrounds">Background Manager</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="settings">Settings</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<!-- Future feature
|
||||||
|
<ul class="navbar-nav">
|
||||||
|
<li class="nav-item">
|
||||||
|
<button class="btn btn-outline-success mr-auto mt-2 mt-lg-0">Create new short</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
-->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
{% block main %}{% endblock %}
|
||||||
|
|
||||||
|
<footer class="text-muted py-5">
|
||||||
|
<div class="container">
|
||||||
|
<p class="float-end mb-1">
|
||||||
|
<a href="#">Back to top</a>
|
||||||
|
</p>
|
||||||
|
<p class="mb-1"><a href="https://getbootstrap.com/docs/5.2/examples/album/" target="_blank">Album</a>
|
||||||
|
Example
|
||||||
|
Theme by © Bootstrap. <a
|
||||||
|
href="https://github.com/elebumm/RedditVideoMakerBot/blob/master/README.md#developers-and-maintainers"
|
||||||
|
target="_blank">Developers and Maintainers</a></p>
|
||||||
|
<p class="mb-0">If your data is not refreshing, try to hard reload(Ctrl + F5) and visit your local
|
||||||
|
<strong>{{ file }}</strong> file.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
@ -0,0 +1,576 @@
|
|||||||
|
{% extends "layout.html" %}
|
||||||
|
{% block main %}
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<br>
|
||||||
|
<div class="container">
|
||||||
|
<form id="settingsForm" action="/settings" method="post" novalidate>
|
||||||
|
|
||||||
|
<!-- Reddit Credentials -->
|
||||||
|
<p class="h4">Reddit Credentials</p>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="client_id" class="col-4">Client ID</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-text">
|
||||||
|
<i class="bi bi-person"></i>
|
||||||
|
</div>
|
||||||
|
<input name="client_id" value="{{ data.client_id }}" placeholder="Your Reddit app's client ID"
|
||||||
|
type="text" class="form-control" data-toggle="tooltip"
|
||||||
|
data-original-title='Text under "personal use script" on www.reddit.com/prefs/apps'>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="client_secret" class="col-4">Client Secret</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-text">
|
||||||
|
<i class="bi bi-key-fill"></i>
|
||||||
|
</div>
|
||||||
|
<input name="client_secret" value="{{ data.client_secret }}"
|
||||||
|
placeholder="Your Reddit app's client secret" type="text" class="form-control"
|
||||||
|
data-toggle="tooltip" data-original-title='"Secret" on www.reddit.com/prefs/apps'>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="username" class="col-4">Reddit Username</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-text">
|
||||||
|
<i class="bi bi-person-fill"></i>
|
||||||
|
</div>
|
||||||
|
<input name="username" value="{{ data.username }}" placeholder="Your Reddit account's username"
|
||||||
|
type="text" class="form-control">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="password" class="col-4">Reddit Password</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-text">
|
||||||
|
<i class="bi bi-lock-fill"></i>
|
||||||
|
</div>
|
||||||
|
<input name="password" value="{{ data.password }}" placeholder="Your Reddit account's password"
|
||||||
|
type="password" class="form-control">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label class="col-4">Do you have Reddit 2FA enabled?</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="form-check form-switch">
|
||||||
|
<input name="2fa" class="form-check-input" type="checkbox" value="True" data-toggle="tooltip"
|
||||||
|
data-original-title='Check it if you have enabled 2FA on your Reddit account'>
|
||||||
|
</div>
|
||||||
|
<span class="form-text text-muted"><a
|
||||||
|
href="https://reddit-video-maker-bot.netlify.app/docs/configuring#setting-up-the-api"
|
||||||
|
target="_blank">Need help? Click here to open step-by-step guide.</a></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Reddit Thread -->
|
||||||
|
<p class="h4">Reddit Thread</p>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label class="col-4">Random Thread</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="form-check form-switch">
|
||||||
|
<input name="random" class="form-check-input" type="checkbox" value="True" data-toggle="tooltip"
|
||||||
|
data-original-title='If disabled, it will ask you for a thread link, instead of picking random one'>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="subreddit" class="col-4">Subreddit</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-text">
|
||||||
|
<i class="bi bi-reddit"></i>
|
||||||
|
</div>
|
||||||
|
<input value="{{ data.subreddit }}" name="subreddit" type="text" class="form-control"
|
||||||
|
placeholder="Subreddit to pull posts from (e.g. AskReddit)" data-toggle="tooltip"
|
||||||
|
data-original-title='You can have multiple subreddits,
|
||||||
|
add "+" between them (e.g. AskReddit+Redditdev)'>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="post_id" class="col-4">Post ID</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-text">
|
||||||
|
<i class="bi bi-file-text"></i>
|
||||||
|
</div>
|
||||||
|
<input value="{{ data.post_id }}" name="post_id" type="text" class="form-control"
|
||||||
|
placeholder="Used if you want to use a specific post (e.g. urdtfx)">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="max_comment_length" class="col-4">Max Comment Length</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<input name="max_comment_length" type="range" class="form-range" min="10" max="10000" step="1"
|
||||||
|
value="{{ data.max_comment_length }}" data-toggle="tooltip"
|
||||||
|
data-original-title="{{ data.max_comment_length }}">
|
||||||
|
</div>
|
||||||
|
<span class="form-text text-muted">Max number of characters a comment can have.</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="post_lang" class="col-4">Post Language</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-text">
|
||||||
|
<i class="bi bi-translate"></i>
|
||||||
|
</div>
|
||||||
|
<input value="{{ data.post_lang }}" name="post_lang" type="text" class="form-control"
|
||||||
|
placeholder="The language you would like to translate to">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="min_comments" class="col-4">Minimum Comments</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<input name="min_comments" type="range" class="form-range" min="15" max="1000" step="1"
|
||||||
|
value="{{ data.min_comments }}" data-toggle="tooltip"
|
||||||
|
data-original-title="{{ data.min_comments }}">
|
||||||
|
</div>
|
||||||
|
<span class="form-text text-muted">The minimum number of comments a post should have to be
|
||||||
|
included.</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- General Settings -->
|
||||||
|
<p class="h4">General Settings</p>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label class="col-4">Allow NSFW</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="form-check form-switch">
|
||||||
|
<input name="allow_nsfw" class="form-check-input" type="checkbox" value="True"
|
||||||
|
data-toggle="tooltip" data-original-title='If checked NSFW posts will be allowed'>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="theme" class="col-4">Reddit Theme</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<select name="theme" class="form-select" data-toggle="tooltip"
|
||||||
|
data-original-title='Sets the theme of Reddit screenshots'>
|
||||||
|
<option value="dark">Dark</option>
|
||||||
|
<option value="light">Light</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="times_to_run" class="col-4">Times To Run</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<input name="times_to_run" type="range" class="form-range" min="1" max="1000" step="1"
|
||||||
|
value="{{ data.times_to_run }}" data-toggle="tooltip"
|
||||||
|
data-original-title="{{ data.times_to_run }}">
|
||||||
|
</div>
|
||||||
|
<span class="form-text text-muted">Used if you want to create multiple videos.</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="opacity" class="col-4">Opacity Of Comments</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<input name="opacity" type="range" class="form-range" min="0" max="1" step="0.05"
|
||||||
|
value="{{ data.opacity }}" data-toggle="tooltip" data-original-title="{{ data.opacity }}">
|
||||||
|
</div>
|
||||||
|
<span class="form-text text-muted">Sets the opacity of the comments when overlayed over the
|
||||||
|
background.</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="transition" class="col-4">Transition</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<input name="transition" type="range" class="form-range" min="0" max="2" step="0.05"
|
||||||
|
value="{{ data.transition }}" data-toggle="tooltip"
|
||||||
|
data-original-title="{{ data.transition }}">
|
||||||
|
</div>
|
||||||
|
<span class="form-text text-muted">Sets the transition time (in seconds) between the
|
||||||
|
comments. Set to 0 if you want to disable it.</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="background_choice" class="col-4">Background Choice</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<select name="background_choice" class="form-select" data-toggle="tooltip"
|
||||||
|
data-original-title='Sets the background of the video'>
|
||||||
|
<option value=" ">Random Video</option>
|
||||||
|
{% for background in checks["background_choice"]["options"][1:] %}
|
||||||
|
<option value="{{background}}">{{background}}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<span class="form-text text-muted"><a href="/backgrounds" target="_blank">See all available
|
||||||
|
backgrounds</a></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- TTS Settings -->
|
||||||
|
<p class="h4">TTS Settings</p>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="voice_choice" class="col-4">TTS Voice Choice</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<select name="voice_choice" class="form-select" data-toggle="tooltip"
|
||||||
|
data-original-title='The voice platform used for TTS generation'>
|
||||||
|
<option value="streamlabspolly">Streamlabspolly</option>
|
||||||
|
<option value="tiktok">TikTok</option>
|
||||||
|
<option value="googletranslate">Google Translate</option>
|
||||||
|
<option value="awspolly">AWS Polly</option>
|
||||||
|
<option value="pyttsx">Python TTS (pyttsx)</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="aws_polly_voice" class="col-4">AWS Polly Voice</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group voices">
|
||||||
|
<select name="aws_polly_voice" class="form-select" data-toggle="tooltip"
|
||||||
|
data-original-title='The voice used for AWS Polly'>
|
||||||
|
<option value="Brian">Brian</option>
|
||||||
|
<option value="Emma">Emma</option>
|
||||||
|
<option value="Russell">Russell</option>
|
||||||
|
<option value="Joey">Joey</option>
|
||||||
|
<option value="Matthew">Matthew</option>
|
||||||
|
<option value="Joanna">Joanna</option>
|
||||||
|
<option value="Kimberly">Kimberly</option>
|
||||||
|
<option value="Amy">Amy</option>
|
||||||
|
<option value="Geraint">Geraint</option>
|
||||||
|
<option value="Nicole">Nicole</option>
|
||||||
|
<option value="Justin">Justin</option>
|
||||||
|
<option value="Ivy">Ivy</option>
|
||||||
|
<option value="Kendra">Kendra</option>
|
||||||
|
<option value="Salli">Salli</option>
|
||||||
|
<option value="Raveena">Raveena</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<button type="button" class="btn btn-primary"><i id="awspolly_icon"
|
||||||
|
class="bi-volume-up-fill"></i></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="streamlabs_polly_voice" class="col-4">Streamlabs Polly Voice</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group voices">
|
||||||
|
<select id="streamlabs_polly_voice" name="streamlabs_polly_voice" class="form-select"
|
||||||
|
data-toggle="tooltip" data-original-title='The voice used for Streamlabs Polly'>
|
||||||
|
<option value="Brian">Brian</option>
|
||||||
|
<option value="Emma">Emma</option>
|
||||||
|
<option value="Russell">Russell</option>
|
||||||
|
<option value="Joey">Joey</option>
|
||||||
|
<option value="Matthew">Matthew</option>
|
||||||
|
<option value="Joanna">Joanna</option>
|
||||||
|
<option value="Kimberly">Kimberly</option>
|
||||||
|
<option value="Amy">Amy</option>
|
||||||
|
<option value="Geraint">Geraint</option>
|
||||||
|
<option value="Nicole">Nicole</option>
|
||||||
|
<option value="Justin">Justin</option>
|
||||||
|
<option value="Ivy">Ivy</option>
|
||||||
|
<option value="Kendra">Kendra</option>
|
||||||
|
<option value="Salli">Salli</option>
|
||||||
|
<option value="Raveena">Raveena</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<button type="button" class="btn btn-primary"><i id="streamlabs_icon"
|
||||||
|
class="bi bi-volume-up-fill"></i></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="tiktok_voice" class="col-4">TikTok Voice</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group voices">
|
||||||
|
<select name="tiktok_voice" class="form-select" data-toggle="tooltip"
|
||||||
|
data-original-title='The voice used for TikTok TTS'>
|
||||||
|
<option disabled value="">-----Disney Voices-----</option>
|
||||||
|
<option value="en_us_ghostface">Ghost Face</option>
|
||||||
|
<option value="en_us_chewbacca">Chewbacca</option>
|
||||||
|
<option value="en_us_c3po">C3PO</option>
|
||||||
|
<option value="en_us_stitch">Stitch</option>
|
||||||
|
<option value="en_us_stormtrooper">Stormtrooper</option>
|
||||||
|
<option value="en_us_rocket">Rocket</option>
|
||||||
|
<option disabled value="">-----English Voices-----</option>
|
||||||
|
<option value="en_au_001">English AU - Female</option>
|
||||||
|
<option value="en_au_002">English AU - Male</option>
|
||||||
|
<option value="en_uk_001">English UK - Male 1</option>
|
||||||
|
<option value="en_uk_003">English UK - Male 2</option>
|
||||||
|
<option value="en_us_001">English US - Female (Int. 1)</option>
|
||||||
|
<option value="en_us_002">English US - Female (Int. 2)</option>
|
||||||
|
<option value="en_us_006">English US - Male 1</option>
|
||||||
|
<option value="en_us_007">English US - Male 2</option>
|
||||||
|
<option value="en_us_009">English US - Male 3</option>
|
||||||
|
<option value="en_us_010">English US - Male 4</option>
|
||||||
|
<option disabled value="">-----European Voices-----</option>
|
||||||
|
<option value="fr_001">French - Male 1</option>
|
||||||
|
<option value="fr_002">French - Male 2</option>
|
||||||
|
<option value="de_001">German - Female</option>
|
||||||
|
<option value="de_002">German - Male</option>
|
||||||
|
<option value="es_002">Spanish - Male</option>
|
||||||
|
<option disabled value="">-----American Voices-----</option>
|
||||||
|
<option value="es_mx_002">Spanish MX - Male</option>
|
||||||
|
<option value="br_001">Portuguese BR - Female 1</option>
|
||||||
|
<option value="br_003">Portuguese BR - Female 2</option>
|
||||||
|
<option value="br_004">Portuguese BR - Female 3</option>
|
||||||
|
<option value="br_005">Portuguese BR - Male</option>
|
||||||
|
<option disabled value="">-----Asian Voices-----</option>
|
||||||
|
<option value="id_001">Indonesian - Female</option>
|
||||||
|
<option value="jp_001">Japanese - Female 1</option>
|
||||||
|
<option value="jp_003">Japanese - Female 2</option>
|
||||||
|
<option value="jp_005">Japanese - Female 3</option>
|
||||||
|
<option value="jp_006">Japanese - Male</option>
|
||||||
|
<option value="kr_002">Korean - Male 1</option>
|
||||||
|
<option value="kr_003">Korean - Female</option>
|
||||||
|
<option value="kr_004">Korean - Male 2</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<button type="button" class="btn btn-primary"><i id="tiktok_icon"
|
||||||
|
class="bi-volume-up-fill"></i></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="python_voice" class="col-4">Python Voice</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-text">
|
||||||
|
<i class="bi bi-mic-fill"></i>
|
||||||
|
</div>
|
||||||
|
<input value="{{ data.python_voice }}" name="python_voice" type="text" class="form-control"
|
||||||
|
data-toggle="tooltip"
|
||||||
|
data-original-title='The index of the system TTS voices (can be downloaded externally, run ptt.py to find value, start from zero)'>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="py_voice_num" class="col-4">Py Voice Number</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-text">
|
||||||
|
<i class="bi bi-headset"></i>
|
||||||
|
</div>
|
||||||
|
<input value="{{ data.py_voice_num }}" name="py_voice_num" type="text" class="form-control"
|
||||||
|
data-toggle="tooltip"
|
||||||
|
data-original-title='The number of system voices (2 are pre-installed in Windows)'>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-2">
|
||||||
|
<label for="silence_duration" class="col-4">Silence Duration</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<div class="input-group">
|
||||||
|
<input name="silence_duration" type="range" class="form-range" min="0" max="5" step="0.05"
|
||||||
|
value="{{ data.silence_duration }}" data-toggle="tooltip"
|
||||||
|
data-original-title="{{ data.silence_duration }}">
|
||||||
|
</div>
|
||||||
|
<span class="form-text text-muted">Time in seconds between TTS comments.</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col text-center">
|
||||||
|
<br>
|
||||||
|
<button id="defaultSettingsBtn" type="button" class="btn btn-secondary">Default
|
||||||
|
Settings</button>
|
||||||
|
<button id="submitButton" type="submit" class="btn btn-success">Save
|
||||||
|
Changes</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<audio src=""></audio>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Test voices buttons
|
||||||
|
var playing = false;
|
||||||
|
|
||||||
|
$(".voices button").click(function () {
|
||||||
|
var icon = $(this).find("i");
|
||||||
|
var audio = $("audio");
|
||||||
|
|
||||||
|
if (playing) {
|
||||||
|
playing.toggleClass("bi-volume-up-fill bi-stop-fill");
|
||||||
|
|
||||||
|
// Clicked the same button - stop audio
|
||||||
|
if (playing.prop("id") == icon.prop("id")) {
|
||||||
|
audio[0].pause();
|
||||||
|
playing = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
icon.toggleClass("bi-volume-up-fill bi-stop-fill");
|
||||||
|
let path = "voices/" + $(this).closest(".voices").find("select").prop("value").toLowerCase() + ".mp3";
|
||||||
|
|
||||||
|
audio.prop("src", path);
|
||||||
|
audio[0].play();
|
||||||
|
playing = icon;
|
||||||
|
|
||||||
|
audio[0].onended = function () {
|
||||||
|
icon.toggleClass("bi-volume-up-fill bi-stop-fill");
|
||||||
|
playing = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wait for DOM to load
|
||||||
|
$(document).ready(function () {
|
||||||
|
// Add tooltips
|
||||||
|
$('[data-toggle="tooltip"]').tooltip();
|
||||||
|
$('[data-toggle="tooltip"]').on('click', function () {
|
||||||
|
$(this).tooltip('hide');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update slider tooltip
|
||||||
|
$(".form-range").on("input", function () {
|
||||||
|
$(this).attr("value", $(this).val());
|
||||||
|
$(this).attr("data-original-title", $(this).val());
|
||||||
|
$(this).tooltip("show");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Get current config
|
||||||
|
var data = JSON.parse('{{data | tojson}}');
|
||||||
|
|
||||||
|
// Set current checkboxes
|
||||||
|
$('.form-check-input').each(function () {
|
||||||
|
$(this).prop("checked", data[$(this).prop("name")]);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set current select options
|
||||||
|
$('.form-select').each(function () {
|
||||||
|
$(this).prop("value", data[$(this).prop("name")]);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Submit "False" when checkbox isn't ticked
|
||||||
|
$('#settingsForm').submit(function () {
|
||||||
|
$('.form-check-input').each(function () {
|
||||||
|
if (!($(this).is(':checked'))) {
|
||||||
|
$(this).prop("value", "False");
|
||||||
|
$(this).prop("checked", true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Get validation values
|
||||||
|
let validateChecks = JSON.parse('{{checks | tojson}}');
|
||||||
|
|
||||||
|
// Set default values
|
||||||
|
$("#defaultSettingsBtn").click(function (event) {
|
||||||
|
$("#settingsForm input, #settingsForm select").each(function () {
|
||||||
|
let check = validateChecks[$(this).prop("name")];
|
||||||
|
|
||||||
|
if (check["default"]) {
|
||||||
|
$(this).prop("value", check["default"]);
|
||||||
|
|
||||||
|
// Update tooltip value for input[type="range"]
|
||||||
|
if ($(this).prop("type") == "range") {
|
||||||
|
$(this).attr("data-original-title", check["default"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Validate form
|
||||||
|
$('#settingsForm').submit(function (event) {
|
||||||
|
$("#settingsForm input, #settingsForm select").each(function () {
|
||||||
|
if (!(validate($(this)))) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
$("html, body").animate({
|
||||||
|
scrollTop: $(this).offset().top
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#settingsForm input").on("keyup", function () {
|
||||||
|
validate($(this));
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#settingsForm select").on("change", function () {
|
||||||
|
validate($(this));
|
||||||
|
});
|
||||||
|
|
||||||
|
function validate(object) {
|
||||||
|
let bool = check(object.prop("name"), object.prop("value"));
|
||||||
|
|
||||||
|
// Change class
|
||||||
|
if (bool) {
|
||||||
|
object.removeClass("is-invalid");
|
||||||
|
object.addClass("is-valid");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
object.removeClass("is-valid");
|
||||||
|
object.addClass("is-invalid");
|
||||||
|
}
|
||||||
|
|
||||||
|
return bool;
|
||||||
|
|
||||||
|
// Check values (return true/false)
|
||||||
|
function check(name, value) {
|
||||||
|
let check = validateChecks[name];
|
||||||
|
|
||||||
|
// If value is empty - check if it's optional
|
||||||
|
if (value.length == 0) {
|
||||||
|
if (check["optional"] == false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
object.prop("value", check["default"]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if value is too short
|
||||||
|
if (check["nmin"]) {
|
||||||
|
if (check["type"] == "int" || check["type"] == "float") {
|
||||||
|
if (value < check["nmin"]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (value.length < check["nmin"]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if value is too long
|
||||||
|
if (check["nmax"]) {
|
||||||
|
if (check["type"] == "int" || check["type"] == "float") {
|
||||||
|
if (value > check["nmax"]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (value.length > check["nmax"]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if value matches regex
|
||||||
|
if (check["regex"]) {
|
||||||
|
let regex = new RegExp(check["regex"]);
|
||||||
|
if (!(regex.test(value))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{% endblock %}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,45 +0,0 @@
|
|||||||
# Supported Background. Can add/remove background video here....
|
|
||||||
# <key>-<value> : key -> used as keyword for TOML file. value -> background configuration
|
|
||||||
# Format (value):
|
|
||||||
# 1. Youtube URI
|
|
||||||
# 2. filename
|
|
||||||
# 3. Citation (owner of the video)
|
|
||||||
# 4. Position of image clips in the background. See moviepy reference for more information. (https://zulko.github.io/moviepy/ref/VideoClip/VideoClip.html#moviepy.video.VideoClip.VideoClip.set_position)
|
|
||||||
background_options = {
|
|
||||||
"motor-gta": ( # Motor-GTA Racing
|
|
||||||
"https://www.youtube.com/watch?v=vw5L4xCPy9Q",
|
|
||||||
"bike-parkour-gta.mp4",
|
|
||||||
"Achy Gaming",
|
|
||||||
lambda t: ("center", 480 + t),
|
|
||||||
),
|
|
||||||
"rocket-league": ( # Rocket League
|
|
||||||
"https://www.youtube.com/watch?v=2X9QGY__0II",
|
|
||||||
"rocket_league.mp4",
|
|
||||||
"Orbital Gameplay",
|
|
||||||
lambda t: ("center", 200 + t),
|
|
||||||
),
|
|
||||||
"minecraft": ( # Minecraft parkour
|
|
||||||
"https://www.youtube.com/watch?v=n_Dv4JMiwK8",
|
|
||||||
"parkour.mp4",
|
|
||||||
"bbswitzer",
|
|
||||||
"center",
|
|
||||||
),
|
|
||||||
"gta": ( # GTA Stunt Race
|
|
||||||
"https://www.youtube.com/watch?v=qGa9kWREOnE",
|
|
||||||
"gta-stunt-race.mp4",
|
|
||||||
"Achy Gaming",
|
|
||||||
lambda t: ("center", 480 + t),
|
|
||||||
),
|
|
||||||
"csgo-surf": ( # CSGO Surf
|
|
||||||
"https://www.youtube.com/watch?v=E-8JlyO59Io",
|
|
||||||
"csgo-surf.mp4",
|
|
||||||
"Aki",
|
|
||||||
"center",
|
|
||||||
),
|
|
||||||
"cluster-truck": ( # Cluster Truck Gameplay
|
|
||||||
"https://www.youtube.com/watch?v=uVKxtdMgJVU",
|
|
||||||
"cluster_truck.mp4",
|
|
||||||
"No Copyright Gameplay",
|
|
||||||
lambda t: ("center", 480 + t),
|
|
||||||
),
|
|
||||||
}
|
|
@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"__comment": "Supported Backgrounds. Can add/remove background video here...",
|
||||||
|
"motor-gta": [
|
||||||
|
"https://www.youtube.com/watch?v=vw5L4xCPy9Q",
|
||||||
|
"bike-parkour-gta.mp4",
|
||||||
|
"Achy Gaming",
|
||||||
|
480
|
||||||
|
],
|
||||||
|
"rocket-league": [
|
||||||
|
"https://www.youtube.com/watch?v=2X9QGY__0II",
|
||||||
|
"rocket_league.mp4",
|
||||||
|
"Orbital Gameplay",
|
||||||
|
200
|
||||||
|
],
|
||||||
|
"minecraft": [
|
||||||
|
"https://www.youtube.com/watch?v=n_Dv4JMiwK8",
|
||||||
|
"parkour.mp4",
|
||||||
|
"bbswitzer",
|
||||||
|
"center"
|
||||||
|
],
|
||||||
|
"gta": [
|
||||||
|
"https://www.youtube.com/watch?v=qGa9kWREOnE",
|
||||||
|
"gta-stunt-race.mp4",
|
||||||
|
"Achy Gaming",
|
||||||
|
480
|
||||||
|
],
|
||||||
|
"csgo-surf": [
|
||||||
|
"https://www.youtube.com/watch?v=E-8JlyO59Io",
|
||||||
|
"csgo-surf.mp4",
|
||||||
|
"Aki",
|
||||||
|
"center"
|
||||||
|
],
|
||||||
|
"cluster-truck": [
|
||||||
|
"https://www.youtube.com/watch?v=uVKxtdMgJVU",
|
||||||
|
"cluster_truck.mp4",
|
||||||
|
"No Copyright Gameplay",
|
||||||
|
480
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,226 @@
|
|||||||
|
import json
|
||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import toml
|
||||||
|
import tomlkit
|
||||||
|
from flask import flash
|
||||||
|
|
||||||
|
|
||||||
|
# Get validation checks from template
|
||||||
|
def get_checks():
|
||||||
|
template = toml.load("utils/.config.template.toml")
|
||||||
|
checks = {}
|
||||||
|
|
||||||
|
def unpack_checks(obj: dict):
|
||||||
|
for key in obj.keys():
|
||||||
|
if "optional" in obj[key].keys():
|
||||||
|
checks[key] = obj[key]
|
||||||
|
else:
|
||||||
|
unpack_checks(obj[key])
|
||||||
|
|
||||||
|
unpack_checks(template)
|
||||||
|
|
||||||
|
return checks
|
||||||
|
|
||||||
|
|
||||||
|
# Get current config (from config.toml) as dict
|
||||||
|
def get_config(obj: dict, done={}):
|
||||||
|
for key in obj.keys():
|
||||||
|
if not isinstance(obj[key], dict):
|
||||||
|
done[key] = obj[key]
|
||||||
|
else:
|
||||||
|
get_config(obj[key], done)
|
||||||
|
|
||||||
|
return done
|
||||||
|
|
||||||
|
|
||||||
|
# Checks if value is valid
|
||||||
|
def check(value, checks):
|
||||||
|
incorrect = False
|
||||||
|
|
||||||
|
if value == "False":
|
||||||
|
value = ""
|
||||||
|
|
||||||
|
if not incorrect and "type" in checks:
|
||||||
|
try:
|
||||||
|
value = eval(checks["type"])(value)
|
||||||
|
except Exception:
|
||||||
|
incorrect = True
|
||||||
|
|
||||||
|
if (
|
||||||
|
not incorrect and "options" in checks and value not in checks["options"]
|
||||||
|
): # FAILSTATE Value is not one of the options
|
||||||
|
incorrect = True
|
||||||
|
if (
|
||||||
|
not incorrect
|
||||||
|
and "regex" in checks
|
||||||
|
and (
|
||||||
|
(isinstance(value, str) and re.match(checks["regex"], value) is None)
|
||||||
|
or not isinstance(value, str)
|
||||||
|
)
|
||||||
|
): # FAILSTATE Value doesn't match regex, or has regex but is not a string.
|
||||||
|
incorrect = True
|
||||||
|
|
||||||
|
if (
|
||||||
|
not incorrect
|
||||||
|
and not hasattr(value, "__iter__")
|
||||||
|
and (
|
||||||
|
("nmin" in checks and checks["nmin"] is not None and value < checks["nmin"])
|
||||||
|
or (
|
||||||
|
"nmax" in checks
|
||||||
|
and checks["nmax"] is not None
|
||||||
|
and value > checks["nmax"]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
):
|
||||||
|
incorrect = True
|
||||||
|
|
||||||
|
if (
|
||||||
|
not incorrect
|
||||||
|
and hasattr(value, "__iter__")
|
||||||
|
and (
|
||||||
|
(
|
||||||
|
"nmin" in checks
|
||||||
|
and checks["nmin"] is not None
|
||||||
|
and len(value) < checks["nmin"]
|
||||||
|
)
|
||||||
|
or (
|
||||||
|
"nmax" in checks
|
||||||
|
and checks["nmax"] is not None
|
||||||
|
and len(value) > checks["nmax"]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
):
|
||||||
|
incorrect = True
|
||||||
|
|
||||||
|
if incorrect:
|
||||||
|
return "Error"
|
||||||
|
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
# Modify settings (after form is submitted)
|
||||||
|
def modify_settings(data: dict, config_load, checks: dict):
|
||||||
|
# Modify config settings
|
||||||
|
def modify_config(obj: dict, name: str, value: any):
|
||||||
|
for key in obj.keys():
|
||||||
|
if name == key:
|
||||||
|
obj[key] = value
|
||||||
|
elif not isinstance(obj[key], dict):
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
modify_config(obj[key], name, value)
|
||||||
|
|
||||||
|
# Remove empty/incorrect key-value pairs
|
||||||
|
data = {key: value for key, value in data.items() if value and key in checks.keys()}
|
||||||
|
|
||||||
|
# Validate values
|
||||||
|
for name in data.keys():
|
||||||
|
value = check(data[name], checks[name])
|
||||||
|
|
||||||
|
# Value is invalid
|
||||||
|
if value == "Error":
|
||||||
|
flash("Some values were incorrect and didn't save!", "error")
|
||||||
|
else:
|
||||||
|
# Value is valid
|
||||||
|
modify_config(config_load, name, value)
|
||||||
|
|
||||||
|
# Save changes in config.toml
|
||||||
|
with Path("config.toml").open("w") as toml_file:
|
||||||
|
toml_file.write(tomlkit.dumps(config_load))
|
||||||
|
|
||||||
|
flash("Settings saved!")
|
||||||
|
|
||||||
|
return get_config(config_load)
|
||||||
|
|
||||||
|
|
||||||
|
# Delete background video
|
||||||
|
def delete_background(key):
|
||||||
|
# Read backgrounds.json
|
||||||
|
with open("utils/backgrounds.json", "r", encoding="utf-8") as backgrounds:
|
||||||
|
data = json.load(backgrounds)
|
||||||
|
|
||||||
|
# Remove background from backgrounds.json
|
||||||
|
with open("utils/backgrounds.json", "w", encoding="utf-8") as backgrounds:
|
||||||
|
if data.pop(key, None):
|
||||||
|
json.dump(data, backgrounds, ensure_ascii=False, indent=4)
|
||||||
|
else:
|
||||||
|
flash("Couldn't find this background. Try refreshing the page.", "error")
|
||||||
|
return
|
||||||
|
|
||||||
|
# Remove background video from ".config.template.toml"
|
||||||
|
config = tomlkit.loads(Path("utils/.config.template.toml").read_text())
|
||||||
|
config["settings"]["background"]["background_choice"]["options"].remove(key)
|
||||||
|
|
||||||
|
with Path("utils/.config.template.toml").open("w") as toml_file:
|
||||||
|
toml_file.write(tomlkit.dumps(config))
|
||||||
|
|
||||||
|
flash(f'Successfully removed "{key}" background!')
|
||||||
|
|
||||||
|
|
||||||
|
# Add background video
|
||||||
|
def add_background(youtube_uri, filename, citation, position):
|
||||||
|
# Validate YouTube URI
|
||||||
|
regex = re.compile(r"(?:\/|%3D|v=|vi=)([0-9A-z-_]{11})(?:[%#?&]|$)").search(
|
||||||
|
youtube_uri
|
||||||
|
)
|
||||||
|
|
||||||
|
if not regex:
|
||||||
|
flash("YouTube URI is invalid!", "error")
|
||||||
|
return
|
||||||
|
|
||||||
|
youtube_uri = f"https://www.youtube.com/watch?v={regex.group(1)}"
|
||||||
|
|
||||||
|
# Check if position is valid
|
||||||
|
if position == "" or position == "center":
|
||||||
|
position = "center"
|
||||||
|
|
||||||
|
elif position.isdecimal():
|
||||||
|
position = int(position)
|
||||||
|
|
||||||
|
else:
|
||||||
|
flash('Position is invalid! It can be "center" or decimal number.', "error")
|
||||||
|
return
|
||||||
|
|
||||||
|
# Sanitize filename
|
||||||
|
regex = re.compile(r"^([a-zA-Z0-9\s_-]{1,100})$").match(filename)
|
||||||
|
|
||||||
|
if not regex:
|
||||||
|
flash("Filename is invalid!", "error")
|
||||||
|
return
|
||||||
|
|
||||||
|
filename = filename.replace(" ", "_")
|
||||||
|
|
||||||
|
# Check if background doesn't already exist
|
||||||
|
with open("utils/backgrounds.json", "r", encoding="utf-8") as backgrounds:
|
||||||
|
data = json.load(backgrounds)
|
||||||
|
|
||||||
|
# Check if key isn't already taken
|
||||||
|
if filename in list(data.keys()):
|
||||||
|
flash("Background video with this name already exist!", "error")
|
||||||
|
return
|
||||||
|
|
||||||
|
# Check if the YouTube URI isn't already used under different name
|
||||||
|
if youtube_uri in [data[i][0] for i in list(data.keys())]:
|
||||||
|
flash("Background video with this YouTube URI is already added!", "error")
|
||||||
|
return
|
||||||
|
|
||||||
|
# Add background video to json file
|
||||||
|
with open("utils/backgrounds.json", "r+", encoding="utf-8") as backgrounds:
|
||||||
|
data = json.load(backgrounds)
|
||||||
|
|
||||||
|
data[filename] = [youtube_uri, filename + ".mp4", citation, position]
|
||||||
|
backgrounds.seek(0)
|
||||||
|
json.dump(data, backgrounds, ensure_ascii=False, indent=4)
|
||||||
|
|
||||||
|
# Add background video to ".config.template.toml"
|
||||||
|
config = tomlkit.loads(Path("utils/.config.template.toml").read_text())
|
||||||
|
config["settings"]["background"]["background_choice"]["options"].append(filename)
|
||||||
|
|
||||||
|
with Path("utils/.config.template.toml").open("w") as toml_file:
|
||||||
|
toml_file.write(tomlkit.dumps(config))
|
||||||
|
|
||||||
|
flash(f'Added "{citation}-{filename}.mp4" as a new background video!')
|
||||||
|
|
||||||
|
return
|
@ -1,10 +1,12 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from utils.console import print_substep
|
from utils.console import print_substep
|
||||||
|
|
||||||
|
|
||||||
def id(reddit_obj: dict):
|
def id(reddit_obj: dict):
|
||||||
"""
|
"""
|
||||||
This function takes a reddit object and returns the post id
|
This function takes a reddit object and returns the post id
|
||||||
"""
|
"""
|
||||||
id = re.sub(r"[^\w\s-]", "", reddit_obj["thread_id"])
|
id = re.sub(r"[^\w\s-]", "", reddit_obj["thread_id"])
|
||||||
print_substep(f"Thread ID is {id}", style="bold blue")
|
print_substep(f"Thread ID is {id}", style="bold blue")
|
||||||
return id
|
return id
|
||||||
|
@ -1 +1 @@
|
|||||||
[]
|
[]
|
||||||
|
Loading…
Reference in new issue