From 3365e933dfa7d783b586fea4954a26ad2d19eba9 Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 17 Mar 2023 11:39:01 +0200 Subject: [PATCH] only use audio/video extensions that CF caches by default --- files/helpers/media.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/files/helpers/media.py b/files/helpers/media.py index 9bb0e3f50..40fc1a18a 100644 --- a/files/helpers/media.py +++ b/files/helpers/media.py @@ -73,6 +73,10 @@ def process_audio(file, v): name_original = secure_filename(file.filename) extension = name_original.split('.')[-1].lower() + + if extension not in {'mp3','ogg','flac'}: + extension = 'mp3' + name = name + '.' + extension file.save(name) @@ -95,7 +99,7 @@ def process_audio(file, v): return name -def webm_to_mp4(old, new, vid, db): +def convert_to_mp4(old, new, vid, db): tmp = new.replace('.mp4', '-t.mp4') subprocess.run(["ffmpeg", "-y", "-loglevel", "warning", "-nostats", "-threads:v", "1", "-i", old, "-map_metadata", "-1", tmp], check=True, stderr=subprocess.STDOUT) os.replace(tmp, new) @@ -133,11 +137,11 @@ def process_video(file, v): extension = name_original.split('.')[-1].lower() new = old + '.' + extension - if extension == 'webm': - new = new.replace('.webm', '.mp4') + if extension not in {'mp4','avi','mkv'}: + new = new.replace(f'.{extension}', '.mp4') copyfile(old, new) db = Session(bind=g.db.get_bind(), autoflush=False) - gevent.spawn(webm_to_mp4, old, new, v.id, db) + gevent.spawn(convert_to_mp4, old, new, v.id, db) else: subprocess.run(["ffmpeg", "-y", "-loglevel", "warning", "-nostats", "-i", old, "-map_metadata", "-1", "-c:v", "copy", "-c:a", "copy", new], check=True) remove_media(old)