parent
a3756ea14d
commit
53061be23e
1 changed files with 6 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
import tempfile
|
||||||
import os
|
import os
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
|
@ -121,8 +122,10 @@ def create_mp3(start, end, outfile, options={}, **kwargs):
|
||||||
metadata_list.append("-metadata")
|
metadata_list.append("-metadata")
|
||||||
metadata_list.append("%s=%s" % (tag, value))
|
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(
|
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:
|
if get_config()["FORGE_TIMEOUT"] == 0:
|
||||||
p.wait()
|
p.wait()
|
||||||
|
@ -137,12 +140,13 @@ def create_mp3(start, end, outfile, options={}, **kwargs):
|
||||||
if p.returncode is None:
|
if p.returncode is None:
|
||||||
os.kill(p.pid, 15)
|
os.kill(p.pid, 15)
|
||||||
try:
|
try:
|
||||||
os.remove(outfile)
|
os.remove(tmp_file.name)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
raise Exception("timeout") # TODO: make a specific TimeoutError
|
raise Exception("timeout") # TODO: make a specific TimeoutError
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
raise OSError("return code was %d" % p.returncode)
|
raise OSError("return code was %d" % p.returncode)
|
||||||
|
os.rename(tmp_file.name, outfile)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue