Fixed bugs and improved code style

This commit is contained in:
Heorhii Mykhailenko 2023-06-16 22:19:01 +03:00
parent 8ac0f1223b
commit d887231d04

10
main.py
View file

@ -54,9 +54,9 @@ def getExtension(filename, isWatermark=False):
def index(): def index():
if request.method == 'POST' and 'video' in request.files: if request.method == 'POST' and 'video' in request.files:
file = request.files['video'] file = request.files['video']
if not file.filename == '': if file.filename:
extension = getExtension(file.filename) extension = getExtension(file.filename)
if extension != False: if extension:
filename = str(uuid.uuid4()) + '.' + extension filename = str(uuid.uuid4()) + '.' + extension
file.save(os.path.join('videos', filename)) file.save(os.path.join('videos', filename))
return redirect(url_for('video', id=filename)) return redirect(url_for('video', id=filename))
@ -75,7 +75,7 @@ def video():
if id == None: if id == None:
abort(400) abort(400)
path = os.path.join('videos', id) path = os.path.join('videos', id)
if id != None and os.path.isfile(path): if os.path.isfile(path):
clip = moviepy.VideoFileClip(path) clip = moviepy.VideoFileClip(path)
if request.method == 'POST': if request.method == 'POST':
start = request.form.get('start') start = request.form.get('start')
@ -91,6 +91,8 @@ def video():
else: else:
clip = clip.subclip(start, end) clip = clip.subclip(start, end)
changed = True changed = True
else:
error += 'Invalid start or end times.<br>'
if extension: if extension:
if extension in ALLOWED_CONVERT_EXTENSIONS: if extension in ALLOWED_CONVERT_EXTENSIONS:
if extension in AUDIO_EXTENSIONS: if extension in AUDIO_EXTENSIONS:
@ -104,7 +106,7 @@ def video():
error += 'Requested recode extension not allowed.<br>' error += 'Requested recode extension not allowed.<br>'
if 'watermark' in request.files: if 'watermark' in request.files:
file = request.files['watermark'] file = request.files['watermark']
if not file.filename == '': if file.filename:
if audio: if audio:
error += 'Audio cannot be watermarked.<br>' error += 'Audio cannot be watermarked.<br>'
else: else: