From 99d90552d33e27e28e554990e7eccd7553742f6b Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Mon, 4 May 2009 08:39:12 +0000 Subject: [PATCH] * examples/ARcue.py: Handle case where we have no matching response. --- ChangeLog | 5 +++++ examples/ARcue.py | 23 ++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index dd26279..afea5d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-05-04 Thomas Vander Stichele + + * examples/ARcue.py: + Handle case where we have no matching response. + 2009-05-03 Thomas Vander Stichele * morituri/common/task.py: diff --git a/examples/ARcue.py b/examples/ARcue.py index 65a51c4..f8a9848 100644 --- a/examples/ARcue.py +++ b/examples/ARcue.py @@ -106,14 +106,16 @@ def main(argv): function(runner, verifytask) function(runner, cuetask) - response = None + response = None # track which response matches, for all tracks + # loop over tracks for i, checksum in enumerate(cuetask.checksums): status = 'rip NOT accurate' confidence = None archecksum = None + # match against each response's checksum for j, r in enumerate(responses): if "%08x" % checksum == r.checksums[i]: if not response: @@ -128,16 +130,19 @@ def main(argv): confidence = response.confidences[i] c = "(not found)" - ar = "" + ar = "(not in database)" if responses: - maxConfidence = max(r.confidences[i] for r in responses) - - c = "(confidence %3d)" % maxConfidence - if confidence is not None: - if confidence < maxConfidence: - c = "(confidence %3d of %3d)" % (confidence, maxConfidence) + if not response: + print 'ERROR: none of the responses matched.' + else: + maxConfidence = max(r.confidences[i] for r in responses) + + c = "(confidence %3d)" % maxConfidence + if confidence is not None: + if confidence < maxConfidence: + c = "(confidence %3d of %3d)" % (confidence, maxConfidence) - ar = ", AR [%s]" % response.checksums[i] + ar = ", AR [%s]" % response.checksums[i] print "Track %2d: %s %s [%08x]%s" % ( i + 1, status, c, checksum, ar)