From d887231d049b48f6510eaa7c05f94218d3a23e0e Mon Sep 17 00:00:00 2001 From: Heorhii Mykhailenko Date: Fri, 16 Jun 2023 22:19:01 +0300 Subject: [PATCH] Fixed bugs and improved code style --- main.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 988300b..cf877b1 100755 --- a/main.py +++ b/main.py @@ -54,14 +54,14 @@ def getExtension(filename, isWatermark=False): def index(): if request.method == 'POST' and 'video' in request.files: file = request.files['video'] - if not file.filename == '': + if file.filename: extension = getExtension(file.filename) - if extension != False: + if extension: filename = str(uuid.uuid4()) + '.' + extension file.save(os.path.join('videos', filename)) return redirect(url_for('video', id=filename)) - else: - return render_template('index.html', error='Non-allowed file extension.') + else: + return render_template('index.html', error='Non-allowed file extension.') return render_template('index.html') @@ -75,7 +75,7 @@ def video(): if id == None: abort(400) path = os.path.join('videos', id) - if id != None and os.path.isfile(path): + if os.path.isfile(path): clip = moviepy.VideoFileClip(path) if request.method == 'POST': start = request.form.get('start') @@ -91,6 +91,8 @@ def video(): else: clip = clip.subclip(start, end) changed = True + else: + error += 'Invalid start or end times.
' if extension: if extension in ALLOWED_CONVERT_EXTENSIONS: if extension in AUDIO_EXTENSIONS: @@ -104,7 +106,7 @@ def video(): error += 'Requested recode extension not allowed.
' if 'watermark' in request.files: file = request.files['watermark'] - if not file.filename == '': + if file.filename: if audio: error += 'Audio cannot be watermarked.
' else: