based on code by: Loïc Minier <lool@dooz.org>
* 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.
This commit is contained in:
10
ChangeLog
10
ChangeLog
@@ -1,3 +1,13 @@
|
||||
2011-05-22 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
based on code by: Loïc Minier <lool@dooz.org>
|
||||
|
||||
* 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 <thomas at apestaart dot org>
|
||||
|
||||
* morituri/image/table.py:
|
||||
|
||||
@@ -4,6 +4,7 @@ morituridir = $(PYTHONLIBDIR)/morituri/rip
|
||||
|
||||
morituri_PYTHON = \
|
||||
__init__.py \
|
||||
accurip.py \
|
||||
cd.py \
|
||||
drive.py \
|
||||
image.py \
|
||||
|
||||
93
morituri/rip/accurip.py
Normal file
93
morituri/rip/accurip.py
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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, ]
|
||||
|
||||
|
||||
@@ -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 ?
|
||||
|
||||
Reference in New Issue
Block a user