diff --git a/.travis.yml b/.travis.yml index bbc063f..ef3f8c3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ install: # Dependencies - sudo apt-get update -qq - sudo pip install --upgrade pip - - sudo apt-get install -qq cdparanoia cdrdao gstreamer0.10-plugins-base gstreamer0.10-plugins-good libcdio-dev libiso9660-dev libsndfile1-dev python-cddb python-gobject swig python-dev python-xdg + - sudo apt-get install -qq cdparanoia cdrdao gstreamer0.10-plugins-base gstreamer0.10-plugins-good libcdio-dev libiso9660-dev libsndfile1-dev python-cddb python-gobject swig python-dev python-xdg sox - sudo pip install musicbrainzngs pycdio # Testing dependencies diff --git a/README.md b/README.md index 2c31c7f..8b16052 100755 --- a/README.md +++ b/README.md @@ -75,10 +75,7 @@ REQUIREMENTS - Required for drive offset and caching behavior to be stored in the config file - libsndfile, for reading wav files - flac, for reading flac files - -Additionally, if you're building from a git checkout: -- autoconf -- automake +- sox, for track peak detection GETTING WHIPPER ---------------- diff --git a/morituri/program/sox.py b/morituri/program/sox.py index e42b37f..93030e3 100644 --- a/morituri/program/sox.py +++ b/morituri/program/sox.py @@ -1,16 +1,24 @@ -import os import logging +import os from subprocess import Popen, PIPE SOX = 'sox' def peak_level(track_path): - if not os.path.exists(track_path): - logging.warning("SoX peak detection failed: file not found") - return None - sox = Popen([SOX, track_path, "-n", "stat"], stderr=PIPE) - out, err = sox.communicate() - if sox.returncode: - logging.warning("SoX peak detection failed: " + s.returncode) - return None - return float(err.split('\n')[3].split()[2]) # Maximum amplitude: 0.123456 + """ + Accepts a path to a sox-decodable audio file. + + Returns track peak level from sox ('maximum amplitude') as a float. + Returns None on error. + """ + if not os.path.exists(track_path): + logging.warning("SoX peak detection failed: file not found") + return None + sox = Popen([SOX, track_path, "-n", "stat"], stderr=PIPE) + out, err = sox.communicate() + if sox.returncode: + logging.warning("SoX peak detection failed: " + str(sox.returncode)) + return None + # relevant captured line looks like: + # Maximum amplitude: 0.123456 + return float(err.splitlines()[3].split()[2]) diff --git a/morituri/test/test_program_sox.py b/morituri/test/test_program_sox.py new file mode 100644 index 0000000..c79cbbc --- /dev/null +++ b/morituri/test/test_program_sox.py @@ -0,0 +1,13 @@ +# -*- Mode: Python; test-case-name: morituri.test.test_program_sox -*- + +import os + +from morituri.program import sox +from morituri.test import common + +class PeakLevelTestCase(common.TestCase): + def setUp(self): + self.path = os.path.join(os.path.dirname(__file__), 'track.flac') + + def testParse(self): + self.assertEquals(0.800018, sox.peak_level(self.path))