[~] Refactor

This commit is contained in:
Siarhei Siniak 2024-07-06 17:49:44 +03:00
parent 5cb6394e27
commit 7dff2a98f2

@ -289,12 +289,15 @@ def tiktok_videos_process(meta: Iterable[dict[str, Any]]) -> dict[str, Any]:
path_parts = os.path.splitext(path)
processed_path = path_parts[0] + '-proc' + path_parts[1]
processed_path_tmp = path_parts[0] + '-proc.tmp' + path_parts[1]
print(processed_path)
if not os.path.exists(path) or os.path.exists(processed_path):
stats['skipped'] += 1
continue
if os.path.exists(processed_path_tmp):
os.unlink(processed_path_tmp)
ffmpeg = [
'ffmpeg',
'-i', path,
@ -308,9 +311,18 @@ def tiktok_videos_process(meta: Iterable[dict[str, Any]]) -> dict[str, Any]:
'-sws_flags', 'bilinear',
'-map', '0:v:0',
'-map', '1:a:0',
processed_path,
processed_path_tmp,
]
subprocess.check_call(ffmpeg)
subprocess.check_call(
ffmpeg,
stdin=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
stdout=subprocess.DEVNULL
)
os.rename(processed_path_tmp, processed_path)
stats['saved'] += 1
except KeyboardInterrupt:
break