mirror of
https://github.com/beetbox/beets.git
synced 2025-12-16 05:34:47 +01:00
echonest: clean up FFmpeg-based audio conversion
subprocess.check_call helps a lot here. --HG-- extra : amend_source : 009a79de8f97407fc60b62aa6b7bd23856286082
This commit is contained in:
parent
a0056afeaf
commit
9bcd7aecae
1 changed files with 19 additions and 24 deletions
|
|
@ -20,7 +20,7 @@ import socket
|
|||
import os
|
||||
import tempfile
|
||||
from string import Template
|
||||
from subprocess import Popen
|
||||
import subprocess
|
||||
|
||||
from beets import util, config, plugins, ui
|
||||
import pyechonest
|
||||
|
|
@ -214,36 +214,31 @@ class EchonestMetadataPlugin(plugins.BeetsPlugin):
|
|||
fd, dest = tempfile.mkstemp(u'.ogg')
|
||||
os.close(fd)
|
||||
source = item.path
|
||||
|
||||
log.info(u'echonest: encoding {0} to {1}'.format(
|
||||
util.displayable_path(source),
|
||||
util.displayable_path(dest),
|
||||
))
|
||||
|
||||
# Build up the FFmpeg command line.
|
||||
# FIXME: use avconv?
|
||||
command = u'ffmpeg -i $source -y -acodec libvorbis -vn -aq 2 $dest'.split(u' ')
|
||||
log.info(u'echonest: encoding {0} to {1}'
|
||||
.format(util.displayable_path(source),
|
||||
util.displayable_path(dest)))
|
||||
command = u'ffmpeg -i $source -y -acodec libvorbis -vn -aq 2 $dest'
|
||||
opts = []
|
||||
for arg in command:
|
||||
for arg in command.split():
|
||||
arg = arg.encode('utf-8')
|
||||
opts.append(Template(arg).substitute({
|
||||
'source': source,
|
||||
'dest': dest
|
||||
}))
|
||||
opts.append(Template(arg).substitute(source=source, dest=dest))
|
||||
|
||||
# Run the command.
|
||||
try:
|
||||
encode = Popen(opts, close_fds=True, stderr=DEVNULL)
|
||||
encode.wait()
|
||||
except Exception as exc:
|
||||
log.error(u'echonest: encode failed: {0}'.format(str(exc)))
|
||||
subprocess.check_call(opts, close_fds=True, stderr=DEVNULL)
|
||||
except (OSError, subprocess.CalledProcessError) as exc:
|
||||
log.debug(u'echonest: encode failed: {0}'.format(exc))
|
||||
util.remove(dest)
|
||||
util.prune_dirs(os.path.dirname(dest))
|
||||
return None
|
||||
return
|
||||
|
||||
if encode.returncode != 0:
|
||||
log.info(u'echonest: encoding {0} failed ({1}). Cleaning up...'
|
||||
.format(util.displayable_path(source), encode.returncode))
|
||||
util.remove(dest)
|
||||
util.prune_dirs(os.path.dirname(dest))
|
||||
return None
|
||||
log.info(u'echonest: finished encoding {0}'
|
||||
.format(util.displayable_path(source)))
|
||||
log.info(u'echonest: finished encoding {0}'.format(
|
||||
util.displayable_path(source))
|
||||
)
|
||||
return dest
|
||||
|
||||
def analyze(self, item):
|
||||
|
|
|
|||
Loading…
Reference in a new issue