Ejemplo n.º 1
0
    def testVerify(self):
        path = os.path.join(os.path.dirname(__file__),
                            'dBAR-020-002e5023-029d8e49-040eaa14.bin')
        data = open(path, "rb").read()
        responses = accurip.getAccurateRipResponses(data)

        # these crc's were calculated from an actual rip
        checksums = [
            1644890007, 2945205445, 3983436658, 1528082495, 1203704270,
            1163423644, 3649097244, 100524219, 1583356174, 373652058,
            1842579359, 2850056507, 1329730252, 2526965856, 2525886806,
            209743350, 3184062337, 2099956663, 2943874164, 2321637196
        ]

        prog = program.Program()
        prog.result = result.RipResult()
        # fill it with empty trackresults
        for i, c in enumerate(checksums):
            r = result.TrackResult()
            r.number = i + 1
            prog.result.tracks.append(r)

        prog._verifyImageWithChecksums(responses, checksums)

        # now check if the results were filled in properly
        tr = prog.result.getTrackResult(1)
        self.assertEquals(tr.accurip, False)
        self.assertEquals(tr.ARDBMaxConfidence, 0)
        self.assertEquals(tr.ARDBCRC, 0)
        self.assertEquals(tr.ARDBCRC, 0)

        tr = prog.result.getTrackResult(2)
        self.assertEquals(tr.accurip, True)
        self.assertEquals(tr.ARDBMaxConfidence, 2)
        self.assertEquals(tr.ARDBCRC, checksums[2 - 1])

        tr = prog.result.getTrackResult(10)
        self.assertEquals(tr.accurip, False)
        self.assertEquals(tr.ARDBMaxConfidence, 2)
        # we know track 10 was ripped wrong
        self.assertNotEquals(tr.ARDBCRC, checksums[10 - 1])

        res = prog.getAccurateRipResults()
        self.assertEquals(
            res[1 - 1], "Track  1: rip NOT accurate (not found)             "
            "[620b0797], DB [notfound]")
        self.assertEquals(
            res[2 - 1], "Track  2: rip accurate     (max confidence      2) "
            "[af8c44c5], DB [af8c44c5]")
        self.assertEquals(
            res[10 - 1], "Track 10: rip NOT accurate (max confidence      2) "
            "[16457a5a], DB [eb6e55b4]")
Ejemplo n.º 2
0
    def _track(self, n, filename, pregap, peak, crc, arcrc, arc):
        track = result.TrackResult()

        track.number = n
        track.filename = '/tmp/' + filename
        track.pregap = pregap

        track.peak = peak
        track.testcrc = track.copycrc = crc

        track.accurip = True
        track.ARCRC = track.ARDBCRC = arcrc
        track.ARDBConfidence = arc

        return track
Ejemplo n.º 3
0
    def do(self, args):
        prog = program.Program(self.getRootCommand().config)
        runner = task.SyncRunner()
        cache = accurip.AccuCache()

        for arg in args:
            arg = arg.decode('utf-8')
            cueImage = image.Image(arg)
            cueImage.setup(runner)

            url = cueImage.table.getAccurateRipURL()
            responses = cache.retrieve(url)

            # FIXME: this feels like we're poking at internals.
            prog.cuePath = arg
            prog.result = result.RipResult()
            for track in cueImage.table.tracks:
                tr = result.TrackResult()
                tr.number = track.number
                prog.result.tracks.append(tr)

            prog.verifyImage(runner, responses)

            print "\n".join(prog.getAccurateRipResults()) + "\n"
Ejemplo n.º 4
0
        def ripIfNotRipped(number):
            self.debug('ripIfNotRipped for track %d' % number)
            # we can have a previous result
            trackResult = self.program.result.getTrackResult(number)
            if not trackResult:
                trackResult = result.TrackResult()
                self.program.result.tracks.append(trackResult)
            else:
                self.debug('ripIfNotRipped have trackresult, path %r' %
                           trackResult.filename)

            path = self.program.getPath(self.program.outdir,
                self.options.track_template,
                self.mbdiscid, number,
                profile=profile, disambiguate=disambiguate) \
                + '.' + profile.extension
            self.debug('ripIfNotRipped: path %r' % path)
            trackResult.number = number

            assert type(path) is unicode, "%r is not unicode" % path
            trackResult.filename = path
            if number > 0:
                trackResult.pregap = self.itable.tracks[number - 1].getPregap()

            # FIXME: optionally allow overriding reripping
            if os.path.exists(path):
                if path != trackResult.filename:
                    # the path is different (different name/template ?)
                    # but we can copy it
                    self.debug('previous result %r, expected %r' %
                               (trackResult.filename, path))

                self.stdout.write('Verifying track %d of %d: %s\n' %
                                  (number, len(self.itable.tracks),
                                   os.path.basename(path).encode('utf-8')))
                if not self.program.verifyTrack(self.runner, trackResult):
                    self.stdout.write('Verification failed, reripping...\n')
                    os.unlink(path)

            if not os.path.exists(path):
                self.debug('path %r does not exist, ripping...' % path)
                tries = 0
                # we reset durations for test and copy here
                trackResult.testduration = 0.0
                trackResult.copyduration = 0.0
                extra = ""
                while tries < MAX_TRIES:
                    tries += 1
                    if tries > 1:
                        extra = " (try %d)" % tries
                    self.stdout.write('Ripping track %d of %d%s: %s\n' %
                                      (number, len(self.itable.tracks), extra,
                                       os.path.basename(path).encode('utf-8')))
                    try:
                        self.debug('ripIfNotRipped: track %d, try %d', number,
                                   tries)
                        self.program.ripTrack(
                            self.runner,
                            trackResult,
                            offset=int(self.options.offset),
                            device=self.parentCommand.options.device,
                            profile=profile,
                            taglist=self.program.getTagList(number),
                            overread=self.options.overread,
                            what='track %d of %d%s' %
                            (number, len(self.itable.tracks), extra))
                        break
                    except Exception, e:
                        self.debug('Got exception %r on try %d', e, tries)

                if tries == MAX_TRIES:
                    self.error('Giving up on track %d after %d times' %
                               (number, tries))
                    raise RuntimeError(
                        "track can't be ripped. "
                        "Rip attempts number is equal to 'MAX_TRIES'")
                if trackResult.testcrc == trackResult.copycrc:
                    self.stdout.write('Checksums match for track %d\n' %
                                      number)
                else:
                    self.stdout.write(
                        'ERROR: checksums did not match for track %d\n' %
                        number)
                    raise

                self.stdout.write('Peak level: {:.2%} \n'.format(
                    trackResult.peak))

                self.stdout.write('Rip quality: {:.2%}\n'.format(
                    trackResult.quality))
Ejemplo n.º 5
0
        def ripIfNotRipped(number):
            # we can have a previous result
            trackResult = prog.result.getTrackResult(number)
            if not trackResult:
                trackResult = result.TrackResult()
                prog.result.tracks.append(trackResult)

            path = prog.getPath(prog.outdir, self.options.track_template,
                                mbdiscid, number) + '.' + profile.extension
            trackResult.number = number

            assert type(path) is unicode, "%r is not unicode" % path
            trackResult.filename = path
            if number > 0:
                trackResult.pregap = itable.tracks[number - 1].getPregap()

            # FIXME: optionally allow overriding reripping
            if os.path.exists(path):
                self.stdout.write('Verifying track %d of %d: %s\n' %
                                  (number, len(itable.tracks),
                                   os.path.basename(path).encode('utf-8')))
                if not prog.verifyTrack(runner, trackResult):
                    self.stdout.write('Verification failed, reripping...\n')
                    os.unlink(path)

            if not os.path.exists(path):
                tries = 0
                self.stdout.write('Ripping track %d of %d: %s\n' %
                                  (number, len(itable.tracks),
                                   os.path.basename(path).encode('utf-8')))
                while tries < MAX_TRIES:
                    tries += 1
                    try:
                        self.debug('ripIfNotRipped: track %d, try %d', number,
                                   tries)
                        prog.ripTrack(runner,
                                      trackResult,
                                      offset=int(self.options.offset),
                                      device=self.parentCommand.options.device,
                                      profile=profile,
                                      taglist=prog.getTagList(number),
                                      what='track %d of %d' %
                                      (number, len(itable.tracks)))
                        break
                    except Exception, e:
                        self.debug('Got exception %r on try %d', e, tries)

                if tries == MAX_TRIES:
                    self.error('Giving up on track %d after %d times' %
                               (number, tries))
                if trackResult.testcrc == trackResult.copycrc:
                    self.stdout.write('Checksums match for track %d\n' %
                                      number)
                else:
                    self.stdout.write(
                        'ERROR: checksums did not match for track %d\n' %
                        number)
                    raise

                self.stdout.write('Peak level: %.2f %%\n' %
                                  (math.sqrt(trackResult.peak) * 100.0, ))
                self.stdout.write('Rip quality: %.2f %%\n' %
                                  (trackResult.quality * 100.0, ))