diff --git a/files/routes/comments.py b/files/routes/comments.py index 01548e980..2bfc229c4 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -311,8 +311,11 @@ def api_comment(v): return {"error": str(e)}, 400 body += f"\n\n![]({image})" elif file.content_type.startswith('video/'): - file.save("unsanitized.mp4") - os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4') + if file.content_type == 'video/webm': + file.save("video.mp4") + else: + file.save("unsanitized.mp4") + os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4') with open("video.mp4", 'rb') as f: try: req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=5).json() except requests.Timeout: return {"error": "Video upload timed out, please try again!"} @@ -768,8 +771,11 @@ def edit_comment(cid, v): url = process_image(v.patron, name) body += f"\n\n![]({url})" elif file.content_type.startswith('video/'): - file.save("unsanitized.mp4") - os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4') + if file.content_type == 'video/webm': + file.save("video.mp4") + else: + file.save("unsanitized.mp4") + os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4') with open("video.mp4", 'rb') as f: try: req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=5).json() except requests.Timeout: return {"error": "Video upload timed out, please try again!"} diff --git a/files/routes/posts.py b/files/routes/posts.py index 8d9821612..c8fd8d0a0 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -464,8 +464,11 @@ def edit_post(pid, v): url = process_image(v.patron, name) body += f"\n\n![]({url})" elif file.content_type.startswith('video/'): - file.save("unsanitized.mp4") - os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4') + if file.content_type == 'video/webm': + file.save("video.mp4") + else: + file.save("unsanitized.mp4") + os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4') with open("video.mp4", 'rb') as f: try: req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=5).json() except requests.Timeout: return {"error": "Video upload timed out, please try again!"} @@ -1078,8 +1081,11 @@ def submit_post(v, sub=None): file.save(name) body += f"\n\n![]({process_image(v.patron, name)})" elif file.content_type.startswith('video/'): - file.save("unsanitized.mp4") - os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4') + if file.content_type == 'video/webm': + file.save("video.mp4") + else: + file.save("unsanitized.mp4") + os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4') with open("video.mp4", 'rb') as f: try: req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=5).json() except requests.Timeout: return {"error": "Video upload timed out, please try again!"} @@ -1184,8 +1190,11 @@ def submit_post(v, sub=None): copyfile(name, name2) post.thumburl = process_image(v.patron, name2, resize=100) elif file.content_type.startswith('video/'): - file.save("unsanitized.mp4") - os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4') + if file.content_type == 'video/webm': + file.save("video.mp4") + else: + file.save("unsanitized.mp4") + os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4') with open("video.mp4", 'rb') as f: try: req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=5).json() except requests.Timeout: return {"error": "Video upload timed out, please try again!"} diff --git a/files/routes/settings.py b/files/routes/settings.py index 8bc99dce6..8a9157635 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -217,8 +217,11 @@ def settings_profile_post(v): url = process_image(v.patron, name) bio += f"\n\n![]({url})" elif file.content_type.startswith('video/'): - file.save("unsanitized.mp4") - os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4') + if file.content_type == 'video/webm': + file.save("video.mp4") + else: + file.save("unsanitized.mp4") + os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4') with open("video.mp4", 'rb') as f: try: req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=5).json() except requests.Timeout: return {"error": "Video upload timed out, please try again!"} diff --git a/files/routes/static.py b/files/routes/static.py index 8515201bd..4f522d6ad 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -404,8 +404,11 @@ def submit_contact(v): url = process_image(v.patron, name) body_html += f'' elif file.content_type.startswith('video/'): - file.save("unsanitized.mp4") - os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4') + if file.content_type == 'video/webm': + file.save("video.mp4") + else: + file.save("unsanitized.mp4") + os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4') with open("video.mp4", 'rb') as f: try: req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=5).json() except requests.Timeout: return {"error": "Video upload timed out, please try again!"} diff --git a/files/routes/users.py b/files/routes/users.py index 0072b35c7..c76b76925 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -701,8 +701,11 @@ def messagereply(v): url = process_image(v.patron, name) body_html += f'' elif file.content_type.startswith('video/'): - file.save("unsanitized.mp4") - os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4') + if file.content_type == 'video/webm': + file.save("video.mp4") + else: + file.save("unsanitized.mp4") + os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4') with open("video.mp4", 'rb') as f: try: req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=5).json() except requests.exceptions.ConnectionError: return {"error": "Video upload timed out, please try again!"}