-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add configuration option to pass extra args to flac encode
Add an argument to the whipper cd rip comand that can be provided on the command line or in the whipper.cd.rip section of the config file. It is retrieved inside the _ripIfNotRipped() private function, split into a list and passed down through to program/flac.py, which actually calls the flac binary. Add debug logging to that function so the actual command shows up in the debug log. Add a unittest to ensure that arguments passed to flac.encode() work as expected. Tested ripping a disc with --extra-flac-encode-args="--best -e --no-padding" from both the command line and config file as well as with the default empty value. Signed-off-by: Kevin Mitchell <[email protected]>
- Loading branch information
Showing
6 changed files
with
75 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- Mode: Python; test-case-name: whipper.test.test_program_flac -*- | ||
|
||
import os | ||
import subprocess | ||
from tempfile import NamedTemporaryFile | ||
import wave | ||
|
||
from whipper.program import flac | ||
from whipper.test import common | ||
|
||
def read_flac(path): | ||
with NamedTemporaryFile(suffix='.wav') as fp: | ||
subprocess.check_call(['flac', '--silent', '-d', path, '-fo', fp.name]) | ||
wf = wave.open(fp.name) | ||
return wf._data_chunk.read() | ||
|
||
class FlacTestCase(common.TestCase): | ||
def setUp(self): | ||
self.original_path = os.path.join(os.path.dirname(__file__), | ||
'track.flac') | ||
|
||
def testEncode(self): | ||
with (NamedTemporaryFile(suffix='.wav') as decoded, | ||
NamedTemporaryFile(suffix='.flac') as encoded_default, | ||
NamedTemporaryFile(suffix='.flac') as encoded_optimum): | ||
# Create a wav file | ||
subprocess.check_call(['flac', '--silent', '-d', self.original_path, | ||
'-fo', decoded.name]) | ||
|
||
# Encode it with different extraArgs | ||
flac.encode(decoded.name, encoded_default.name) | ||
flac.encode(decoded.name, encoded_optimum.name, | ||
['--best', '-e']) | ||
|
||
# Ensure the file with higher compression is smaller | ||
size_default = os.path.getsize(encoded_default.name) | ||
size_optimum = os.path.getsize(encoded_optimum.name) | ||
self.assertLess(size_optimum, size_default) | ||
|
||
# Make sure the the contents are identical | ||
data_original = read_flac(self.original_path) | ||
data_default = read_flac(encoded_default.name) | ||
data_optimum = read_flac(encoded_default.name) | ||
self.assertEqual(data_original, data_default) | ||
self.assertEqual(data_original, data_optimum) |