From 65055914621407b8bacb988d503f488d4d4397a8 Mon Sep 17 00:00:00 2001 From: blueblots <63152708+blueblots@users.noreply.github.com> Date: Sat, 20 Feb 2021 15:15:22 +0000 Subject: [PATCH] Fixed m3u and cue sheet generation Added conditional to `program.write_m3u()` to ignore skipped tracks. Added skipped_tracks support to the `Program` and `image.ImageVerifyTask` classes to avoid crashing when a file for a skipped track doesn't exist. Added conditional to `accurip.calculate_checksums` to check if a path exists before trying to calculate checksums, this prevents `accuraterip-checksum.c` from emitting an error message (`sf_open failed!`) when a path doesn't exist (as when a track is skipped). Signed-off-by: blueblots <63152708+blueblots@users.noreply.github.com> --- whipper/command/cd.py | 21 +++++++++------------ whipper/common/accurip.py | 7 ++++++- whipper/common/program.py | 11 ++++++++++- whipper/image/image.py | 14 ++++++++++++-- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/whipper/command/cd.py b/whipper/command/cd.py index ffd0067..9b03cf6 100644 --- a/whipper/command/cd.py +++ b/whipper/command/cd.py @@ -487,18 +487,17 @@ Log files will log the path to tracks relative to this directory. if self.options.keep_going: logger.warning("track %d failed to rip.", number) logger.debug("adding %s to skipped_tracks", - trackResult.filename) - self.skipped_tracks.append(trackResult.filename) + trackResult) + self.skipped_tracks.append(trackResult) logger.debug("skipped_tracks = %s", self.skipped_tracks) trackResult.skipped = True - logger.debug('trackResult.skipped = True') else: raise RuntimeError("track can't be ripped. " "Rip attempts number is equal " "to %d", self.options.max_retries) - if trackResult.filename in self.skipped_tracks: + if trackResult in self.skipped_tracks: print("Skipping CRC comparison for track %d " "due to rip failure" % number) else: @@ -529,14 +528,9 @@ Log files will log the path to tracks relative to this directory. self.itable.setFile(1, 0, trackResult.filename, self.itable.getTrackStart(1), number) else: - if trackResult.filename in self.skipped_tracks: - logger.debug("track %d (%s) has been skipped; " - "not adding to self.itable", - number, trackResult.filename) - else: - self.itable.setFile(number, 1, trackResult.filename, - self.itable.getTrackLength(number), - number) + self.itable.setFile(number, 1, trackResult.filename, + self.itable.getTrackLength(number), + number) # check for hidden track one audio htoa = self.program.getHTOA() @@ -571,6 +565,9 @@ Log files will log the path to tracks relative to this directory. logger.debug('writing m3u file for %r', discName) self.program.write_m3u(discName) + if len(self.skipped_tracks) > 0: + self.program.skipped_tracks = self.skipped_tracks + try: self.program.verifyImage(self.runner, self.itable) except accurip.EntryNotFound: diff --git a/whipper/common/accurip.py b/whipper/common/accurip.py index 8f504fd..9be9a94 100644 --- a/whipper/common/accurip.py +++ b/whipper/common/accurip.py @@ -21,6 +21,7 @@ import struct import whipper +import os from urllib.error import URLError, HTTPError from urllib.request import urlopen, Request @@ -111,7 +112,11 @@ def calculate_checksums(track_paths): logger.debug('checksumming %d tracks', track_count) # This is done sequentially because it is very fast. for i, path in enumerate(track_paths): - v1_sum, v2_sum = accuraterip_checksum(path, i+1, track_count) + if os.path.exists(path): + v1_sum, v2_sum = accuraterip_checksum(path, i+1, track_count) + else: + logger.warning('Can\'t checksum %s; path doesn\'t exist', path) + v1_sum, v2_sum = None, None if v1_sum is None: logger.error('could not calculate AccurateRip v1 checksum ' 'for track %d %r', i + 1, path) diff --git a/whipper/common/program.py b/whipper/common/program.py index 302a276..58cd9a4 100644 --- a/whipper/common/program.py +++ b/whipper/common/program.py @@ -57,6 +57,7 @@ class Program: metadata = None outdir = None result = None + skipped_tracks = None def __init__(self, config, record=False): """ @@ -612,7 +613,12 @@ class Program: """ cueImage = image.Image(self.cuePath) # assigns track lengths - verifytask = image.ImageVerifyTask(cueImage) + if self.skipped_tracks is not None: + verifytask = image.ImageVerifyTask(cueImage, + [os.path.basename(t.filename) + for t in self.skipped_tracks]) + else: + verifytask = image.ImageVerifyTask(cueImage) runner.run(verifytask) if verifytask.exception: logger.error(verifytask.exceptionMessage) @@ -627,6 +633,7 @@ class Program: ]) if not (checksums and any(checksums['v1']) and any(checksums['v2'])): return False + return accurip.verify_result(self.result, responses, checksums) def write_m3u(self, discname): @@ -637,6 +644,8 @@ class Program: if not track.filename: # false positive htoa continue + if track.skipped: + continue if track.number == 0: length = (self.result.table.getTrackStart(1) / common.FRAMES_PER_SECOND) diff --git a/whipper/image/image.py b/whipper/image/image.py index 224af4a..7a356b7 100644 --- a/whipper/image/image.py +++ b/whipper/image/image.py @@ -120,7 +120,7 @@ class ImageVerifyTask(task.MultiSeparateTask): description = "Checking tracks" lengths = None - def __init__(self, image): + def __init__(self, image, skipped_tracks=[]): task.MultiSeparateTask.__init__(self) self._image = image @@ -147,7 +147,17 @@ class ImageVerifyTask(task.MultiSeparateTask): length = cue.getTrackLength(track) if length == -1: - path = image.getRealPath(index.path) + try: + path = image.getRealPath(index.path) + except KeyError: + logger.debug('Path not found; Checking ' + 'if %s is a skipped track', index.path) + if index.path in skipped_tracks: + logger.warning('Missing file %s due to skipped track', + index.path) + continue + else: + raise assert isinstance(path, str), "%r is not str" % path logger.debug('schedule scan of audio length of %r', path) taskk = AudioLengthTask(path)