Beispiel #1
0
    def doCommand(self):
        # here to avoid import gst eating our options
        from morituri.common import encode
        profile = encode.PROFILES['flac']()
        self.program.result.profileName = profile.name
        self.program.result.profilePipeline = profile.pipeline
        elementFactory = profile.pipeline.split(' ')[0]
        self.program.result.gstreamerVersion = gstreamer.gstreamerVersion()
        self.program.result.gstPythonVersion = gstreamer.gstPythonVersion()
        self.program.result.encoderVersion = gstreamer.elementFactoryVersion(
            elementFactory)

        self.program.setWorkingDirectory(self.options.working_directory)
        self.program.outdir = self.options.output_directory.decode('utf-8')
        self.program.result.offset = int(self.options.offset)
        self.program.result.overread = self.options.overread
        self.program.result.logger = self.options.logger

        ### write disc files
        disambiguate = False
        while True:
            discName = self.program.getPath(self.program.outdir,
                self.options.disc_template, self.mbdiscid, 0,
                profile=profile, disambiguate=disambiguate)
            dirname = os.path.dirname(discName)
            if os.path.exists(dirname):
                sys.stdout.write("Output directory %s already exists\n" %
                    dirname.encode('utf-8'))
                logs = glob.glob(os.path.join(dirname, '*.log'))
                if logs:
                    sys.stdout.write(
                        "Output directory %s is a finished rip\n" %
                        dirname.encode('utf-8'))
                    if not disambiguate:
                        disambiguate = True
                        continue
                    return
                else:
                    break

            else:
                sys.stdout.write("Creating output directory %s\n" %
                    dirname.encode('utf-8'))
                os.makedirs(dirname)
                break

        # FIXME: say when we're continuing a rip
        # FIXME: disambiguate if the pre-existing rip is different


        # FIXME: turn this into a method

        def ripIfNotRipped(number):
            logger.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:
                logger.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
            logger.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
                    logger.debug('previous result %r, expected %r' % (
                        trackResult.filename, path))

                sys.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):
                    sys.stdout.write('Verification failed, reripping...\n')
                    os.unlink(path)

            if not os.path.exists(path):
                logger.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
                    sys.stdout.write('Ripping track %d of %d%s: %s\n' % (
                        number, len(self.itable.tracks), extra,
                        os.path.basename(path).encode('utf-8')))
                    try:
                        logger.debug('ripIfNotRipped: track %d, try %d',
                            number, tries)
                        self.program.ripTrack(self.runner, trackResult,
                            offset=int(self.options.offset),
                            device=self.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:
                        logger.debug('Got exception %r on try %d',
                            e, tries)


                if tries == MAX_TRIES:
                    logger.critical('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:
                    sys.stdout.write('Checksums match for track %d\n' %
                        number)
                else:
                    sys.stdout.write(
                        'ERROR: checksums did not match for track %d\n' %
                        number)
                    raise

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

                sys.stdout.write('Rip quality: {:.2%}\n'.format(trackResult.quality))

            # overlay this rip onto the Table
            if number == 0:
                # HTOA goes on index 0 of track 1
                # ignore silence in PREGAP
                if trackResult.peak <= SILENT:
                    logger.debug('HTOA peak %r is below SILENT threshold, disregarding', trackResult.peak)
                    self.itable.setFile(1, 0, None,
                        self.ittoc.getTrackStart(1), number)
                    logger.debug('Unlinking %r', trackResult.filename)
                    os.unlink(trackResult.filename)
                    trackResult.filename = None
                    sys.stdout.write('HTOA discarded, contains digital silence\n')
                else:
                    self.itable.setFile(1, 0, trackResult.filename,
                        self.ittoc.getTrackStart(1), number)
            else:
                self.itable.setFile(number, 1, trackResult.filename,
                    self.ittoc.getTrackLength(number), number)

            self.program.saveRipResult()
 def testGSTPython(self):
     version = gstreamer.gstPythonVersion()
     self.failUnless(version.startswith('0.'))
Beispiel #3
0
    def doCommand(self):
        # here to avoid import gst eating our options
        from morituri.common import encode
        profile = encode.PROFILES[self.options.profile]()
        self.program.result.profileName = profile.name
        self.program.result.profilePipeline = profile.pipeline
        elementFactory = profile.pipeline.split(' ')[0]
        self.program.result.gstreamerVersion = gstreamer.gstreamerVersion()
        self.program.result.gstPythonVersion = gstreamer.gstPythonVersion()
        self.program.result.encoderVersion = gstreamer.elementFactoryVersion(
            elementFactory)

        self.program.setWorkingDirectory(self.options.working_directory)
        self.program.outdir = self.options.output_directory.decode('utf-8')
        self.program.result.offset = int(self.options.offset)
        self.program.result.overread = self.options.overread
        self.program.result.logger = self.options.logger

        ### write disc files
        disambiguate = False
        while True:
            discName = self.program.getPath(self.program.outdir,
                                            self.options.disc_template,
                                            self.mbdiscid,
                                            0,
                                            profile=profile,
                                            disambiguate=disambiguate)
            dirname = os.path.dirname(discName)
            if os.path.exists(dirname):
                self.stdout.write("Output directory %s already exists\n" %
                                  dirname.encode('utf-8'))
                logs = glob.glob(os.path.join(dirname, '*.log'))
                if logs:
                    self.stdout.write(
                        "Output directory %s is a finished rip\n" %
                        dirname.encode('utf-8'))
                    if not disambiguate:
                        disambiguate = True
                        continue
                    return
                else:
                    break

            else:
                self.stdout.write("Creating output directory %s\n" %
                                  dirname.encode('utf-8'))
                os.makedirs(dirname)
                break

        # FIXME: say when we're continuing a rip
        # FIXME: disambiguate if the pre-existing rip is different

        # FIXME: turn this into a method

        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))

            # overlay this rip onto the Table
            if number == 0:
                # HTOA goes on index 0 of track 1
                # ignore silence in PREGAP
                if trackResult.peak <= SILENT:
                    self.debug(
                        'HTOA peak %r is below SILENT threshold, disregarding',
                        trackResult.peak)
                    self.itable.setFile(1, 0, None,
                                        self.ittoc.getTrackStart(1), number)
                    self.debug('Unlinking %r', trackResult.filename)
                    os.unlink(trackResult.filename)
                    trackResult.filename = None
                    self.stdout.write(
                        'HTOA discarded, contains digital silence\n')
                else:
                    self.itable.setFile(1, 0, trackResult.filename,
                                        self.ittoc.getTrackStart(1), number)
            else:
                self.itable.setFile(number, 1, trackResult.filename,
                                    self.ittoc.getTrackLength(number), number)

            self.program.saveRipResult()
 def testGSTPython(self):
     version = gstreamer.gstPythonVersion()
     self.failUnless(version.startswith('0.'))