forked from rDrama/rDrama
wrap all subprocess commands we use in media.py in try except to delete old files
parent
a83dc8bba9
commit
1190c9d063
|
@ -101,7 +101,12 @@ def process_audio(file, v):
|
||||||
|
|
||||||
def convert_to_mp4(old, new, vid, db):
|
def convert_to_mp4(old, new, vid, db):
|
||||||
tmp = new.replace('.mp4', '-t.mp4')
|
tmp = new.replace('.mp4', '-t.mp4')
|
||||||
|
try:
|
||||||
subprocess.run(["ffmpeg", "-y", "-loglevel", "warning", "-nostats", "-threads:v", "1", "-i", old, "-map_metadata", "-1", tmp], check=True, stderr=subprocess.STDOUT)
|
subprocess.run(["ffmpeg", "-y", "-loglevel", "warning", "-nostats", "-threads:v", "1", "-i", old, "-map_metadata", "-1", tmp], check=True, stderr=subprocess.STDOUT)
|
||||||
|
except:
|
||||||
|
remove_media(old)
|
||||||
|
abort(400)
|
||||||
|
|
||||||
os.replace(tmp, new)
|
os.replace(tmp, new)
|
||||||
remove_media(old)
|
remove_media(old)
|
||||||
|
|
||||||
|
@ -143,7 +148,12 @@ def process_video(file, v):
|
||||||
db = Session(bind=g.db.get_bind(), autoflush=False)
|
db = Session(bind=g.db.get_bind(), autoflush=False)
|
||||||
gevent.spawn(convert_to_mp4, old, new, v.id, db)
|
gevent.spawn(convert_to_mp4, old, new, v.id, db)
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
subprocess.run(["ffmpeg", "-y", "-loglevel", "warning", "-nostats", "-i", old, "-map_metadata", "-1", "-c:v", "copy", "-c:a", "copy", new], check=True)
|
subprocess.run(["ffmpeg", "-y", "-loglevel", "warning", "-nostats", "-i", old, "-map_metadata", "-1", "-c:v", "copy", "-c:a", "copy", new], check=True)
|
||||||
|
except:
|
||||||
|
remove_media(old)
|
||||||
|
abort(400)
|
||||||
|
|
||||||
remove_media(old)
|
remove_media(old)
|
||||||
|
|
||||||
media = g.db.query(Media).filter_by(filename=new, kind='video').one_or_none()
|
media = g.db.query(Media).filter_by(filename=new, kind='video').one_or_none()
|
||||||
|
@ -189,9 +199,7 @@ def process_image(filename:str, v, resize=0, trim=False, uploader_id:Optional[in
|
||||||
params.extend(["-resize", f"{resize}>"])
|
params.extend(["-resize", f"{resize}>"])
|
||||||
except UnidentifiedImageError as e:
|
except UnidentifiedImageError as e:
|
||||||
print(f"Couldn't identify an image for {filename}; deleting... (user {v.id if v else '-no user-'})")
|
print(f"Couldn't identify an image for {filename}; deleting... (user {v.id if v else '-no user-'})")
|
||||||
try:
|
|
||||||
remove_media(filename)
|
remove_media(filename)
|
||||||
except: pass
|
|
||||||
if has_request:
|
if has_request:
|
||||||
abort(415)
|
abort(415)
|
||||||
return None
|
return None
|
||||||
|
@ -199,9 +207,10 @@ def process_image(filename:str, v, resize=0, trim=False, uploader_id:Optional[in
|
||||||
params.append(filename)
|
params.append(filename)
|
||||||
try:
|
try:
|
||||||
subprocess.run(params, timeout=MAX_IMAGE_CONVERSION_TIMEOUT)
|
subprocess.run(params, timeout=MAX_IMAGE_CONVERSION_TIMEOUT)
|
||||||
except subprocess.TimeoutExpired:
|
except:
|
||||||
|
remove_media(filename)
|
||||||
if has_request:
|
if has_request:
|
||||||
abort(413, ("An uploaded image took too long to convert to WEBP. "
|
abort(400, ("An uploaded image couldn't be converted to WEBP. "
|
||||||
"Please convert it to WEBP elsewhere then upload it again."))
|
"Please convert it to WEBP elsewhere then upload it again."))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue