Fixed bugs

This commit is contained in:
Heorhii Mykhailenko 2023-06-17 17:09:50 +03:00
parent d887231d04
commit abfece95e7
3 changed files with 77 additions and 72 deletions

2
mail.py Executable file → Normal file
View file

@ -38,7 +38,7 @@ def send_email(destination, attachment):
# Add header as key/value pair to attachment part
part.add_header(
'Content-Disposition',
f'attachment; filename= {os.path.normpath(attachment)}',
f'attachment; filename= {os.path.basename(attachment)}',
)
# Add attachment to message and convert message to string

17
main.py Executable file → Normal file
View file

@ -76,7 +76,8 @@ def video():
abort(400)
path = os.path.join('videos', id)
if os.path.isfile(path):
clip = moviepy.VideoFileClip(path)
with moviepy.VideoFileClip(path) as clip:
length = int(clip.duration)
if request.method == 'POST':
start = request.form.get('start')
end = request.form.get('end')
@ -117,7 +118,7 @@ def video():
file.save(watermarkPath)
formatter = {'PNG': 'RGBA', 'JPEG': 'RGB'}
img = Image.open(watermarkPath)
with Image.open(watermarkPath) as img:
rgbimg = Image.new(formatter.get(
img.format, 'RGB'), img.size)
rgbimg.paste(img)
@ -136,18 +137,22 @@ def video():
if changed:
logger = BarLogger(id)
if 'newId' in locals():
os.remove(path)
id = newId
path = os.path.join('videos', id)
oldPath = path
path = os.path.join('videos', newId)
if audio:
audio.write_audiofile(path, logger=logger)
audio.close()
else:
clip.write_videofile(path, logger=logger)
clip.close()
send_email(email, path)
if changed:
if 'oldPath' in locals():
os.remove(oldPath)
os.remove(path)
return render_template('success.html', error=error)
return render_template('video.html', length=int(clip.duration), error=error)
return render_template('video.html', length=length, error=error)
else:
abort(404)

2
templates/success.html Executable file → Normal file
View file

@ -11,7 +11,7 @@
<p>The following errors occurred:<br>
{{ error | safe }}</p>
{% endif %}
<p><a href="index.html">Upload another video</a></p>
<p><a href="/">Upload another video</a></p>
</body>
</html>