From c248a714949749e55ed444b134b7f726173abb87 Mon Sep 17 00:00:00 2001 From: Thomas Scholtes Date: Tue, 2 Dec 2014 11:51:18 +0100 Subject: [PATCH] echonest: mock convert and truncate commands --- beetsplug/echonest.py | 14 +++++++------- test/test_echonest.py | 2 ++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/beetsplug/echonest.py b/beetsplug/echonest.py index f594922c4..a59d59d96 100644 --- a/beetsplug/echonest.py +++ b/beetsplug/echonest.py @@ -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)) diff --git a/test/test_echonest.py b/test/test_echonest.py index 5480cd62c..bdaf6e229 100644 --- a/test/test_echonest.py +++ b/test/test_echonest.py @@ -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',