From ac66d71e6b5c66016ddafc8da8da293fe28f52ba Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Sun, 22 May 2011 18:06:57 +0000 Subject: [PATCH] =?UTF-8?q?=09based=20on=20code=20by:=20Lo=C3=AFc=20Minier?= =?UTF-8?q?=20=20=09*=20morituri/rip/Makefile.am:=20=09*=20?= =?UTF-8?q?morituri/rip/main.py:=20=09*=20morituri/rip/accurip.py=20(added?= =?UTF-8?q?):=20=09=20=20Add=20a=20rip=20accurip=20show=20command=20to=20s?= =?UTF-8?q?how=20the=20accuraterip=20information=20=09=20=20for=20a=20give?= =?UTF-8?q?n=20URL.=20=20See=20#5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ChangeLog | 10 +++++ morituri/rip/Makefile.am | 1 + morituri/rip/accurip.py | 93 ++++++++++++++++++++++++++++++++++++++++ morituri/rip/main.py | 5 ++- 4 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 morituri/rip/accurip.py diff --git a/ChangeLog b/ChangeLog index aa152fa..a7f41a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-05-22 Thomas Vander Stichele + + based on code by: Loïc Minier + + * morituri/rip/Makefile.am: + * morituri/rip/main.py: + * morituri/rip/accurip.py (added): + Add a rip accurip show command to show the accuraterip information + for a given URL. See #5. + 2011-05-22 Thomas Vander Stichele * morituri/image/table.py: diff --git a/morituri/rip/Makefile.am b/morituri/rip/Makefile.am index 7ed18ca..82f6dcb 100644 --- a/morituri/rip/Makefile.am +++ b/morituri/rip/Makefile.am @@ -4,6 +4,7 @@ morituridir = $(PYTHONLIBDIR)/morituri/rip morituri_PYTHON = \ __init__.py \ + accurip.py \ cd.py \ drive.py \ image.py \ diff --git a/morituri/rip/accurip.py b/morituri/rip/accurip.py new file mode 100644 index 0000000..a9d3be7 --- /dev/null +++ b/morituri/rip/accurip.py @@ -0,0 +1,93 @@ +# -*- Mode: Python -*- +# vi:si:et:sw=4:sts=4:ts=4 + +# Morituri - for those about to RIP + +# Copyright (C) 2009 Thomas Vander Stichele + +# This file is part of morituri. +# +# morituri is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# morituri is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with morituri. If not, see . + +from morituri.common import logcommand, accurip + +class Show(logcommand.LogCommand): + summary = "show accuraterip data" + + def do(self, args): + + try: + url = args[0] + except IndexError: + self.stdout.write('Please specify an accuraterip URL.\n') + return 3 + + cache = accurip.AccuCache() + responses = cache.retrieve(url) + + count = responses[0].trackCount + + self.stdout.write("Found %d responses for %d tracks\n\n" % ( + len(responses), count)) + + for (i, r) in enumerate(responses): + if r.trackCount != count: + self.stdout.write( + "Warning: response %d has %d tracks instead of %d\n" % ( + i, r.trackCount, count)) + + + # checksum and confidence by track + tracks = [] + for track in range(count): + self.stdout.write("Track %d:\n" % (track + 1)) + checksums = {} + + for (i, r) in enumerate(responses): + if r.trackCount != count: + continue + + assert len(r.checksums) == r.trackCount + assert len(r.confidences) == r.trackCount + + entry = {} + entry["confidence"] = r.confidences[track] + entry["response"] = i + 1 + checksum = r.checksums[track] + if checksum in checksums: + checksums[checksum].append(entry) + else: + checksums[checksum] = [entry, ] + + # now sort track results in checksum by highest confidence + sortedChecksums = [] + for checksum, entries in checksums.items(): + highest = max(d['confidence'] for d in entries) + sortedChecksums.append((highest, checksum)) + + sortedChecksums.sort() + sortedChecksums.reverse() + + for highest, checksum in sortedChecksums: + self.stdout.write(" %d result(s) for checksum %s: %s\n" % ( + len(checksums[checksum]), checksum, + str(checksums[checksum]))) + + +class AccuRip(logcommand.LogCommand): + summary = "handle AccurateRip information" + + subCommandClasses = [Show, ] + + diff --git a/morituri/rip/main.py b/morituri/rip/main.py index 464d148..69bae1e 100644 --- a/morituri/rip/main.py +++ b/morituri/rip/main.py @@ -4,7 +4,7 @@ import sys from morituri.common import log, logcommand, common, task -from morituri.rip import cd, offset, drive, image +from morituri.rip import cd, offset, drive, image, accurip def main(argv): c = Rip() @@ -46,7 +46,8 @@ Rip gives you a tree of subcommands to work with. You can get help on subcommands by using the -h option to the subcommand. """ - subCommandClasses = [cd.CD, drive.Drive, offset.Offset, image.Image, ] + subCommandClasses = [accurip.AccuRip, + cd.CD, drive.Drive, offset.Offset, image.Image, ] def addOptions(self): # FIXME: is this the right place ?