echonest: mock convert and truncate commands

This commit is contained in:
Thomas Scholtes 2014-12-02 11:51:18 +01:00
parent d0e8be45a9
commit c248a71494
2 changed files with 9 additions and 7 deletions

View file

@ -39,6 +39,11 @@ DEVNULL = open(os.devnull, 'wb')
ALLOWED_FORMATS = ('MP3', 'OGG', 'AAC')
UPLOAD_MAX_SIZE = 50 * 1024 * 1024
# FIXME: use avconv?
CONVERT_COMMAND = u'ffmpeg -i $source -y -acodec libvorbis -vn -aq 2 $dest'
TRUNCATE_COMMAND = u'ffmpeg -t 300 -i $source'\
u'-y -acodec libvorbis -vn -aq 2 $dest'
# Maps attribute names from echonest to their field names in beets.
# The attributes are retrieved from a songs `audio_summary`. See:
# http://echonest.github.io/pyechonest/song.html#pyechonest.song.profile
@ -289,11 +294,8 @@ class EchonestMetadataPlugin(plugins.BeetsPlugin):
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'
opts = []
for arg in command.split():
for arg in CONVERT_COMMAND.split():
arg = arg.encode('utf-8')
opts.append(Template(arg).substitute(source=source, dest=dest))
@ -320,10 +322,8 @@ class EchonestMetadataPlugin(plugins.BeetsPlugin):
util.displayable_path(dest),
))
command = u'ffmpeg -t 300 -i $source '\
u'-y -acodec libvorbis -vn -aq 2 $dest'
opts = []
for arg in command.split():
for arg in TRUNCATE_COMMAND.split():
arg = arg.encode('utf-8')
opts.append(Template(arg).substitute(source=source, dest=dest))

View file

@ -90,6 +90,7 @@ class EchonestCliTest(unittest.TestCase, TestHelper):
@patch('pyechonest.song.profile')
@patch('pyechonest.song.search')
@patch('pyechonest.track.track_from_filename')
@patch('beetsplug.echonest.CONVERT_COMMAND', 'cp $source $dest')
def test_analyze_convert(self, echonest_track, echonest_search,
echonest_profile):
item = self.add_item(title='title', length=10, format='FLAC',
@ -110,6 +111,7 @@ class EchonestCliTest(unittest.TestCase, TestHelper):
@patch('pyechonest.track.track_from_filename')
# Force truncation
@patch('beetsplug.echonest.UPLOAD_MAX_SIZE', 0)
@patch('beetsplug.echonest.TRUNCATE_COMMAND', 'cp $source $dest')
def test_analyze_truncate(self, echonest_track, echonest_search,
echonest_profile):
item = self.add_item(title='title', length=10, format='MP3',