files are generated in TMPDIR

fixes #4
This commit is contained in:
boyska 2021-08-24 23:32:43 +02:00
parent a3756ea14d
commit 53061be23e

View file

@ -1,4 +1,5 @@
import logging
import tempfile
import os
from datetime import datetime, timedelta
from subprocess import Popen
@ -121,8 +122,10 @@ def create_mp3(start, end, outfile, options={}, **kwargs):
metadata_list.append("-metadata")
metadata_list.append("%s=%s" % (tag, value))
prefix, suffix = os.path.basename(outfile).split('.', 1)
tmp_file = tempfile.NamedTemporaryFile(suffix='.%s' % suffix, prefix='forge-%s' % prefix, delete=False)
p = Popen(
mp3_join(intervals) + metadata_list + get_config()["FFMPEG_OPTIONS"] + [outfile]
mp3_join(intervals) + metadata_list + ['-y'] + get_config()["FFMPEG_OPTIONS"] + [tmp_file.name]
)
if get_config()["FORGE_TIMEOUT"] == 0:
p.wait()
@ -137,12 +140,13 @@ def create_mp3(start, end, outfile, options={}, **kwargs):
if p.returncode is None:
os.kill(p.pid, 15)
try:
os.remove(outfile)
os.remove(tmp_file.name)
except:
pass
raise Exception("timeout") # TODO: make a specific TimeoutError
if p.returncode != 0:
raise OSError("return code was %d" % p.returncode)
os.rename(tmp_file.name, outfile)
return True