Example #1
0
    def getFastToc(self, runner, device):
        """Retrieve the normal TOC table from the drive.
        Also warn about buggy cdrdao versions.
        """
        from pkg_resources import parse_version as V
        version = cdrdao.version()
        if V(version) < V('1.2.3rc2'):
            logger.warning(
                'cdrdao older than 1.2.3 has a pre-gap length bug.'
                ' See http://sourceforge.net/tracker/?func=detail&aid=604751&group_id=2171&atid=102171'
            )  # noqa: E501

        t = cdrdao.ReadTOCTask(device, fast_toc=True)
        runner.run(t)
        toc = t.toc.table

        assert toc.hasTOC()
        return toc
Example #2
0
    def do(self):
        self.config = config.Config()
        self.program = program.Program(self.config,
                                       record=self.options.record)
        self.runner = task.SyncRunner()

        # if the device is mounted (data session), unmount it
        self.device = self.options.device
        logger.info('checking device %s', self.device)

        if self.options.drive_auto_close is True:
            utils.load_device(self.device)
        utils.unmount_device(self.device)
        # Exit and inform the user if there's no CD in the disk drive
        if drive.get_cdrom_drive_status(self.device) == 1:  # rc 1 -> no disc
            raise OSError("no CD detected, please insert one and retry")

        # first, read the normal TOC, which is fast
        self.ittoc = self.program.getFastToc(self.runner, self.device)

        # already show us some info based on this
        self.program.getRipResult()
        print("CDDB disc id: %s" % self.ittoc.getCDDBDiscId())
        self.mbdiscid = self.ittoc.getMusicBrainzDiscId()
        print("MusicBrainz disc id %s" % self.mbdiscid)

        print("MusicBrainz lookup URL %s" %
              self.ittoc.getMusicBrainzSubmitURL())

        self.program.metadata = (
            self.program.getMusicBrainz(self.ittoc, self.mbdiscid,
                                        release=self.options.release_id,
                                        country=self.options.country,
                                        prompt=self.options.prompt)
        )

        if not self.program.metadata:
            # fall back to FreeDB for lookup
            cddbid = self.ittoc.getCDDBValues()
            cddbmd = self.program.getCDDB(cddbid)
            if cddbmd:
                logger.info('FreeDB identifies disc as %s', cddbmd)

            # also used by rip cd info
            if not getattr(self.options, 'unknown', False):
                logger.critical("unable to retrieve disc metadata, "
                                "--unknown argument not passed")
                return -1

        self.program.result.isCdr = cdrdao.DetectCdr(self.device)
        if (self.program.result.isCdr and
                not getattr(self.options, 'cdr', False)):
            logger.critical("inserted disc seems to be a CD-R, "
                            "--cdr not passed")
            return -1

        # Change working directory before cdrdao's task
        if getattr(self.options, 'working_directory', False):
            os.chdir(os.path.expanduser(self.options.working_directory))
        if hasattr(self.options, 'output_directory'):
            out_bpath = self.options.output_directory
            # Needed to preserve cdrdao's tocfile
            out_fpath = self.program.getPath(out_bpath,
                                             self.options.disc_template,
                                             self.mbdiscid,
                                             self.program.metadata)
        else:
            out_fpath = None
        # now, read the complete index table, which is slower
        offset = getattr(self.options, 'offset', 0)
        self.itable = self.program.getTable(self.runner,
                                            self.ittoc.getCDDBDiscId(),
                                            self.ittoc.getMusicBrainzDiscId(),
                                            self.device, offset, out_fpath)

        assert self.itable.getCDDBDiscId() == self.ittoc.getCDDBDiscId(), \
            "full table's id %s differs from toc id %s" % (
                self.itable.getCDDBDiscId(), self.ittoc.getCDDBDiscId())
        assert self.itable.getMusicBrainzDiscId() == \
            self.ittoc.getMusicBrainzDiscId(), \
            "full table's mb id %s differs from toc id mb %s" % (
            self.itable.getMusicBrainzDiscId(),
            self.ittoc.getMusicBrainzDiscId())

        if self.program.metadata:
            self.program.metadata.discid = self.ittoc.getMusicBrainzDiscId()

        # result

        self.program.result.cdrdaoVersion = cdrdao.version()
        self.program.result.cdparanoiaVersion = \
            cdparanoia.getCdParanoiaVersion()
        info = drive.getDeviceInfo(self.device)
        if info:
            try:
                self.program.result.cdparanoiaDefeatsCache = \
                    self.config.getDefeatsCache(*info)
            except KeyError as e:
                logger.debug('got key error: %r', (e, ))
        self.program.result.artist = self.program.metadata \
            and self.program.metadata.artist \
            or 'Unknown Artist'
        self.program.result.title = self.program.metadata \
            and self.program.metadata.releaseTitle \
            or 'Unknown Title'
        _, self.program.result.vendor, self.program.result.model, \
            self.program.result.release = \
            cdio.Device(self.device).get_hwinfo()
        self.program.result.metadata = self.program.metadata

        ret = self.doCommand()

        if (self.options.eject == 'success' and self.eject or
                self.options.eject == 'always'):
            utils.eject_device(self.device)

        return ret
Example #3
0
 def testGetVersion(self):
     v = cdrdao.version()
     self.assertTrue(v)
     # make sure it starts with a digit
     self.assertTrue(int(v[0]))