Impoved style
This commit is contained in:
parent
749a36b445
commit
4d9aecf18e
6 changed files with 58 additions and 23 deletions
9
.gitignore
vendored
9
.gitignore
vendored
|
@ -129,3 +129,12 @@ dmypy.json
|
|||
.pyre/
|
||||
|
||||
config.ini
|
||||
videos/
|
||||
*.mp4
|
||||
*.webm
|
||||
*.mkv
|
||||
*.avi
|
||||
*.ogv
|
||||
*.ogg
|
||||
*.mp3
|
||||
*.flac
|
7
mail.py
7
mail.py
|
@ -1,4 +1,8 @@
|
|||
import configparser, email, os, smtplib, ssl
|
||||
import configparser
|
||||
import email
|
||||
import os
|
||||
import smtplib
|
||||
import ssl
|
||||
|
||||
from email import encoders
|
||||
from email.mime.base import MIMEBase
|
||||
|
@ -8,6 +12,7 @@ from email.mime.text import MIMEText
|
|||
config = configparser.ConfigParser()
|
||||
config.read('config.ini')
|
||||
|
||||
|
||||
def send_email(destination, attachment):
|
||||
subject = 'Your modified video'
|
||||
body = 'You have recently used our service to modify a video. The result is attached.'
|
||||
|
|
26
main.py
26
main.py
|
@ -10,12 +10,15 @@ import moviepy.editor as moviepy
|
|||
app = Flask(__name__)
|
||||
|
||||
ALLOWED_UPLOAD_EXTENSIONS = {'mp4', 'webm', 'mkv', 'avi', 'ogv'}
|
||||
ALLOWED_CONVERT_EXTENSIONS = {'mp4', 'webm', 'mkv', 'avi', 'ogv', 'ogg', 'mp3', 'flac'}
|
||||
ALLOWED_CONVERT_EXTENSIONS = {'mp4', 'webm',
|
||||
'mkv', 'avi', 'ogv', 'ogg', 'mp3', 'flac'}
|
||||
AUDIO_EXTENSIONS = {'ogg', 'mp3', 'flac'}
|
||||
ALLOWED_WATERMARK_EXTENSIONS = {'bmp', 'png', 'jpg', 'jpeg', 'tiff', 'tga', 'svg'}
|
||||
ALLOWED_WATERMARK_EXTENSIONS = {
|
||||
'bmp', 'png', 'jpg', 'jpeg', 'tiff', 'tga', 'svg'}
|
||||
|
||||
percentages = {}
|
||||
|
||||
|
||||
class BarLogger(ProgressBarLogger):
|
||||
global percentages
|
||||
id = None
|
||||
|
@ -27,12 +30,14 @@ class BarLogger(ProgressBarLogger):
|
|||
super(self.__class__, self).__init__()
|
||||
self.id = id
|
||||
|
||||
|
||||
def is_integer(n):
|
||||
try:
|
||||
return float(n).is_integer()
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
|
||||
def getExtension(filename, isWatermark=False):
|
||||
if not '.' in filename:
|
||||
return False
|
||||
|
@ -44,6 +49,7 @@ def getExtension(filename, isWatermark=False):
|
|||
else:
|
||||
return False
|
||||
|
||||
|
||||
@app.route('/', methods=['GET', 'POST'])
|
||||
def index():
|
||||
if request.method == 'POST' and 'video' in request.files:
|
||||
|
@ -59,12 +65,15 @@ def index():
|
|||
|
||||
return render_template('index.html')
|
||||
|
||||
|
||||
@app.route('/video', methods=['GET', 'POST'])
|
||||
def video():
|
||||
error = ''
|
||||
changed = False
|
||||
audio = None
|
||||
id = request.args.get('id')
|
||||
if id == None:
|
||||
abort(400)
|
||||
path = os.path.join('videos', id)
|
||||
if id != None and os.path.isfile(path):
|
||||
clip = moviepy.VideoFileClip(path)
|
||||
|
@ -101,12 +110,14 @@ def video():
|
|||
else:
|
||||
watermarkExtension = getExtension(file.filename, True)
|
||||
if watermarkExtension:
|
||||
watermarkPath = os.path.join('videos', id + '-watermark' + '.' + watermarkExtension)
|
||||
watermarkPath = os.path.join(
|
||||
'videos', id + '-watermark' + '.' + watermarkExtension)
|
||||
file.save(watermarkPath)
|
||||
|
||||
formatter = {'PNG': 'RGBA', 'JPEG': 'RGB'}
|
||||
img = Image.open(watermarkPath)
|
||||
rgbimg = Image.new(formatter.get(img.format, 'RGB'), img.size)
|
||||
rgbimg = Image.new(formatter.get(
|
||||
img.format, 'RGB'), img.size)
|
||||
rgbimg.paste(img)
|
||||
rgbimg.save(watermarkPath, format=img.format)
|
||||
|
||||
|
@ -114,7 +125,8 @@ def video():
|
|||
.set_duration(clip.duration)
|
||||
.set_pos(('right', 'bottom')))
|
||||
|
||||
clip = moviepy.CompositeVideoClip([clip, watermark])
|
||||
clip = moviepy.CompositeVideoClip(
|
||||
[clip, watermark])
|
||||
os.remove(watermarkPath)
|
||||
changed = True
|
||||
else:
|
||||
|
@ -133,10 +145,11 @@ def video():
|
|||
os.remove(path)
|
||||
return render_template('success.html', error=error)
|
||||
|
||||
return render_template('video.html', id=id, length=int(clip.duration), error=error)
|
||||
return render_template('video.html', length=int(clip.duration), error=error)
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
|
||||
@app.route('/progress', methods=['GET'])
|
||||
def progress():
|
||||
id = request.args.get('id')
|
||||
|
@ -146,6 +159,7 @@ def progress():
|
|||
else:
|
||||
abort(404)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if not os.path.isdir('videos'):
|
||||
os.mkdir('videos')
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>Video upload</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{% if error %}
|
||||
<p>{{ error | safe }}</p>
|
||||
|
@ -13,5 +15,5 @@
|
|||
<button id="submit" type="submit">Submit</button>
|
||||
</form>
|
||||
</body>
|
||||
</p>
|
||||
|
||||
</html>
|
|
@ -1,8 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>Video upload</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<p>The modified video was sent to your email address. You can upload another one if you want to.</p>
|
||||
{% if error %}
|
||||
|
@ -11,5 +13,5 @@
|
|||
{% endif %}
|
||||
<p><a href="index.html">Upload another video</a></p>
|
||||
</body>
|
||||
</p>
|
||||
|
||||
</html>
|
|
@ -1,13 +1,15 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>Video editing</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{% if error %}
|
||||
<p>{{ error | safe }}</p>
|
||||
{% endif %}
|
||||
<p>Video {{name}} ({{length}})</p>
|
||||
<p>Video length: {{length}} s</p>
|
||||
<form method="POST" enctype="multipart/form-data" onsubmit="trackProgress()">
|
||||
<label for="start">Start (s): </label><br>
|
||||
<input type="text" id="start" name="start"><br>
|
||||
|
@ -27,7 +29,7 @@
|
|||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const id = urlParams.get('id');
|
||||
const xhttp = new XMLHttpRequest();
|
||||
xhttp.onload = function() {
|
||||
xhttp.onload = function () {
|
||||
document.getElementById("bar").value = this.responseText;
|
||||
}
|
||||
xhttp.open("GET", "/progress?id=" + id, true);
|
||||
|
@ -42,4 +44,5 @@
|
|||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
Reference in a new issue