From 0bd15d39140c510087b84a4840307a85e8a7c54c Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 23 May 2022 21:00:14 +0200 Subject: [PATCH] burgers? --- files/helpers/media.py | 25 ++++++++++++------------- files/routes/comments.py | 4 ++-- files/routes/posts.py | 6 +++--- files/routes/settings.py | 2 +- files/routes/static.py | 2 +- files/routes/users.py | 2 +- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/files/helpers/media.py b/files/helpers/media.py index 5df115684..90065f98c 100644 --- a/files/helpers/media.py +++ b/files/helpers/media.py @@ -9,12 +9,12 @@ import time from .const import * -def process_audio(patron, file): +def process_audio(file): name = f'/audio/{time.time()}'.replace('.','') + '.mp3' file.save(name) size = os.stat(name).st_size - if size > 16 * 1024 * 1024 or not patron and size > 8 * 1024 * 1024: + if size > 8 * 1024 * 1024: with open(name, 'rb') as f: os.remove(name) req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=20).json() @@ -27,19 +27,18 @@ def process_video(file): name = f'/videos/{time.time()}'.replace('.','') file.save(name) - spider = os.system(f'ffmpeg -y -loglevel warning -i {name} -map_metadata -1 -c:v copy -c:a copy {name}.mp4') - - if spider: print(f'ffmpeg returned {spider}', flush=True) + os.system(f'ffmpeg -y -loglevel warning -i {name} -map_metadata -1 -c:v copy -c:a copy {name}.mp4') os.remove(name) + name += '.mp4' - with open(f"{name}.mp4", 'rb') as f: - if SITE_NAME != 'rDrama' or os.stat(f'{name}.mp4').st_size > 8 * 1024 * 1024: - os.remove(f"{name}.mp4") - try: req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=20).json() - except requests.Timeout: return {"error": "Video upload timed out, please try again!"} - - try: return req['files'][0]['url'] - except: return {"error": req['description']} + size = os.stat(name).st_size + if size > 8 * 1024 * 1024: + with open(name, 'rb') as f: + os.remove(name) + req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=20).json() + return req['files'][0]['url'] + + return f'{SITE_FULL}{name}' def process_image(patron, filename=None, resize=0): diff --git a/files/routes/comments.py b/files/routes/comments.py index 198bbc918..86648c661 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -313,7 +313,7 @@ def api_comment(v): if type(value) is str: body += f"\n\n{value}" else: return value elif file.content_type.startswith('audio/'): - body += f"\n\n{process_audio(v.patron, file)}" + body += f"\n\n{process_audio(file)}" else: return {"error": "Image/Video/Audio files only"}, 400 body = body.strip() @@ -773,7 +773,7 @@ def edit_comment(cid, v): if type(value) is str: body += f"\n\n{value}" else: return value elif file.content_type.startswith('audio/'): - body += f"\n\n{process_audio(v.patron, file)}" + body += f"\n\n{process_audio(file)}" else: return {"error": "Image/Video/Audio files only"}, 400 body = body.strip() diff --git a/files/routes/posts.py b/files/routes/posts.py index 163132046..2ea151e03 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -468,7 +468,7 @@ def edit_post(pid, v): if type(value) is str: body += f"\n\n{value}" else: return value elif file.content_type.startswith('audio/'): - body += f"\n\n{process_audio(v.patron, file)}" + body += f"\n\n{process_audio(file)}" else: return {"error": "Image/Video/Audio files only"}, 400 body = body.strip() @@ -1081,7 +1081,7 @@ def submit_post(v, sub=None): if type(value) is str: body += f"\n\n{value}" else: return error(value['error']) elif file.content_type.startswith('audio/'): - body += f"\n\n{process_audio(v.patron, file)}" + body += f"\n\n{process_audio(file)}" else: return error("Image/Video/Audio files only.") @@ -1186,7 +1186,7 @@ def submit_post(v, sub=None): if type(value) is str: post.url = value else: return error(value['error']) elif file.content_type.startswith('audio/'): - post.url = process_audio(v.patron, file) + post.url = process_audio(file) else: return error("Image/Video/Audio files only.") diff --git a/files/routes/settings.py b/files/routes/settings.py index f7af375fb..b1c1ae5e5 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -221,7 +221,7 @@ def settings_profile_post(v): if type(value) is str: bio += f"\n\n{value}" else: return value elif file.content_type.startswith('audio/'): - bio += f"\n\n{process_audio(v.patron, file)}" + bio += f"\n\n{process_audio(file)}" else: if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "Image/Video/Audio files only"}, 400 return render_template("settings_profile.html", v=v, error="Image/Video/Audio files only."), 400 diff --git a/files/routes/static.py b/files/routes/static.py index ce1b87e82..937f7a0eb 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -408,7 +408,7 @@ def submit_contact(v): if type(value) is str: body_html += f"

{value}

" else: return value elif file.content_type.startswith('audio/'): - body_html += f"

{process_audio(v.patron, file)}

" + body_html += f"

{process_audio(file)}

" else: return {"error": "Image/Video/Audio files only"}, 400 diff --git a/files/routes/users.py b/files/routes/users.py index 4c57b32e9..aed425894 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -705,7 +705,7 @@ def messagereply(v): if type(value) is str: body_html += f"

{value}

" else: return value elif file.content_type.startswith('audio/'): - body_html += f"

{process_audio(v.patron, file)}

" + body_html += f"

{process_audio(file)}

" else: return {"error": "Image/Video/Audio files only"}, 400