parent
a3756ea14d
commit
53061be23e
1 changed files with 6 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue