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
This commit is contained in:
Merlijn Wajer
2018-01-26 22:18:24 +01:00
parent a34942e38d
commit 6bd389b7b1
3 changed files with 21 additions and 9 deletions

View File

@@ -338,8 +338,9 @@ Log files will log the path to tracks relative to this directory.
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

View File

@@ -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)

View File

@@ -531,8 +531,8 @@ class Program:
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)