From 6bd389b7b13e15269bf9ef7545f5c301372ac764 Mon Sep 17 00:00:00 2001 From: Merlijn Wajer Date: Fri, 26 Jan 2018 22:18:24 +0100 Subject: [PATCH] Fix resuming previous rips Thanks to Freso for testing. command/cd: Only call makedirs when dir does not exist common/checksum: Support flac input files Fixes #136 --- whipper/command/cd.py | 5 +++-- whipper/common/checksum.py | 21 ++++++++++++++++----- whipper/common/program.py | 4 ++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/whipper/command/cd.py b/whipper/command/cd.py index 2cebd2a2..5d5b6306 100644 --- a/whipper/command/cd.py +++ b/whipper/command/cd.py @@ -338,8 +338,9 @@ def doCommand(self): else: sys.stdout.write("output directory %s already exists\n" % dirname.encode('utf-8')) - print("creating output directory %s" % dirname.encode('utf-8')) - os.makedirs(dirname) + else: + print("creating output directory %s" % dirname.encode('utf-8')) + os.makedirs(dirname) # FIXME: turn this into a method diff --git a/whipper/common/checksum.py b/whipper/common/checksum.py index 56ed7b45..d23edea3 100644 --- a/whipper/common/checksum.py +++ b/whipper/common/checksum.py @@ -20,6 +20,9 @@ import binascii import wave +import tempfile +import subprocess +import os from whipper.extern.task import task as etask @@ -34,16 +37,24 @@ class CRC32Task(etask.Task): # TODO: Support sampleStart, sampleLength later on (should be trivial, just # add change the read part in _crc32 to skip some samples and/or not # read too far) - def __init__(self, path, sampleStart=0, sampleLength=-1): + def __init__(self, path, sampleStart=0, sampleLength=-1, is_wave=True): self.path = path + self.is_wave = is_wave def start(self, runner): etask.Task.start(self, runner) self.schedule(0.0, self._crc32) def _crc32(self): - w = wave.open(self.path) - d = w._data_chunk.read() + fd, tmpf = tempfile.mkstemp() - self.checksum = binascii.crc32(d) & 0xffffffff - self.stop() + try: + subprocess.check_call(['flac', '-d', self.path, '-fo', tmpf]) + + w = wave.open(tmpf) + d = w._data_chunk.read() + + self.checksum = binascii.crc32(d) & 0xffffffff + self.stop() + finally: + os.remove(tmpf) diff --git a/whipper/common/program.py b/whipper/common/program.py index 3e6fee1c..57b12642 100644 --- a/whipper/common/program.py +++ b/whipper/common/program.py @@ -531,8 +531,8 @@ def getHTOA(self): return (start, stop) def verifyTrack(self, runner, trackResult): - - t = checksum.CRC32Task(trackResult.filename) + is_wave = not trackResult.filename.endswith('.flac') + t = checksum.CRC32Task(trackResult.filename, is_wave=is_wave) try: runner.run(t)