def do(self): runner = ctask.SyncRunner() device = self.options.device # if necessary, load and unmount sys.stdout.write('Checking device %s\n' % device) utils.load_device(device) utils.unmount_device(device) # first get the Table Of Contents of the CD t = cdrdao.ReadTOCTask(device) table = t.table logger.debug("CDDB disc id: %r", table.getCDDBDiscId()) url = table.getAccurateRipURL() logger.debug("AccurateRip URL: %s", url) # FIXME: download url as a task too responses = [] import urllib2 try: handle = urllib2.urlopen(url) data = handle.read() responses = accurip.getAccurateRipResponses(data) except urllib2.HTTPError, e: if e.code == 404: sys.stdout.write( 'Album not found in AccurateRip database.\n') return 1 else: raise
def do(self): runner = ctask.SyncRunner() device = self.options.device # if necessary, load and unmount sys.stdout.write('Checking device %s\n' % device) utils.load_device(device) utils.unmount_device(device) # first get the Table Of Contents of the CD t = cdrdao.ReadTOCTask(device) table = t.table logger.debug("CDDB disc id: %r", table.getCDDBDiscId()) url = table.getAccurateRipURL() logger.debug("AccurateRip URL: %s", url) # FIXME: download url as a task too responses = [] import urllib2 try: handle = urllib2.urlopen(url) data = handle.read() responses = accurip.getAccurateRipResponses(data) except urllib2.HTTPError, e: if e.code == 404: sys.stdout.write('Album not found in AccurateRip database.\n') return 1 else: raise
def do(self): self.config = config.Config() self.program = program.Program(self.config, record=self.options.record, stdout=sys.stdout) self.runner = task.SyncRunner() # if the device is mounted (data session), unmount it self.device = self.options.device sys.stdout.write('Checking device %s\n' % self.device) utils.load_device(self.device) utils.unmount_device(self.device) # first, read the normal TOC, which is fast self.ittoc = self.program.getFastToc(self.runner, self.options.toc_pickle, self.device) # already show us some info based on this self.program.getRipResult(self.ittoc.getCDDBDiscId()) sys.stdout.write("CDDB disc id: %s\n" % self.ittoc.getCDDBDiscId()) self.mbdiscid = self.ittoc.getMusicBrainzDiscId() sys.stdout.write("MusicBrainz disc id %s\n" % self.mbdiscid) sys.stdout.write("MusicBrainz lookup URL %s\n" % 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: sys.stdout.write('FreeDB identifies disc as %s\n' % cddbmd) # also used by rip cd info if not getattr(self.options, 'unknown', False): logger.critical("unable to retrieve disc metadata, " "--unknown 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 # now, read the complete index table, which is slower self.itable = self.program.getTable(self.runner, self.ittoc.getCDDBDiscId(), self.ittoc.getMusicBrainzDiscId(), self.device, self.options.offset) 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()) assert self.itable.accuraterip_path() == \ self.ittoc.accuraterip_path(), \ "full table's AR URL %s differs from toc AR URL %s" % ( self.itable.accuraterip_url(), self.ittoc.accuraterip_url()) if self.program.metadata: self.program.metadata.discid = self.ittoc.getMusicBrainzDiscId() # result self.program.result.cdrdaoVersion = cdrdao.getCDRDAOVersion() 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.title \ or 'Unknown Title' _, self.program.result.vendor, self.program.result.model, \ self.program.result.release = \ cdio.Device(self.device).get_hwinfo() self.doCommand() if self.options.eject in ('success', 'always'): utils.eject_device(self.device)
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
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) utils.load_device(self.device) utils.unmount_device(self.device) # first, read the normal TOC, which is fast logger.info("reading TOC...") self.ittoc = self.program.getFastToc(self.runner, self.device) # already show us some info based on this self.program.getRipResult(self.ittoc.getCDDBDiscId()) 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 self.options.working_directory is not None: os.chdir(os.path.expanduser(self.options.working_directory)) out_bpath = self.options.output_directory.decode('utf-8') # Needed to preserve cdrdao's tocfile out_fpath = self.program.getPath(out_bpath, self.options.disc_template, self.mbdiscid, self.program.metadata) # now, read the complete index table, which is slower self.itable = self.program.getTable(self.runner, self.ittoc.getCDDBDiscId(), self.ittoc.getMusicBrainzDiscId(), self.device, self.options.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()) assert self.itable.accuraterip_path() == \ self.ittoc.accuraterip_path(), \ "full table's AR URL %s differs from toc AR URL %s" % ( self.itable.accuraterip_url(), self.ittoc.accuraterip_url()) if self.program.metadata: self.program.metadata.discid = self.ittoc.getMusicBrainzDiscId() # result self.program.result.cdrdaoVersion = cdrdao.getCDRDAOVersion() 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.title \ or 'Unknown Title' _, self.program.result.vendor, self.program.result.model, \ self.program.result.release = \ cdio.Device(self.device).get_hwinfo() self.doCommand() if self.options.eject in ('success', 'always'): utils.eject_device(self.device)
def do(self): self.config = config.Config() self.program = program.Program(self.config, record=self.options.record, stdout=sys.stdout) self.runner = task.SyncRunner() # if the device is mounted (data session), unmount it self.device = self.options.device sys.stdout.write('Checking device %s\n' % self.device) utils.load_device(self.device) utils.unmount_device(self.device) # first, read the normal TOC, which is fast self.ittoc = self.program.getFastToc(self.runner, self.options.toc_pickle, self.device) # already show us some info based on this self.program.getRipResult(self.ittoc.getCDDBDiscId()) sys.stdout.write("CDDB disc id: %s\n" % self.ittoc.getCDDBDiscId()) self.mbdiscid = self.ittoc.getMusicBrainzDiscId() sys.stdout.write("MusicBrainz disc id %s\n" % self.mbdiscid) sys.stdout.write("MusicBrainz lookup URL %s\n" % 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: sys.stdout.write('FreeDB identifies disc as %s\n' % cddbmd) # also used by rip cd info if not getattr(self.options, 'unknown', False): logger.critical("unable to retrieve disc metadata, " "--unknown 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 # now, read the complete index table, which is slower self.itable = self.program.getTable(self.runner, self.ittoc.getCDDBDiscId(), self.ittoc.getMusicBrainzDiscId(), self.device, self.options.offset) 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()) assert self.itable.accuraterip_path() == \ self.ittoc.accuraterip_path(), \ "full table's AR URL %s differs from toc AR URL %s" % ( self.itable.accuraterip_url(), self.ittoc.accuraterip_url()) if self.program.metadata: self.program.metadata.discid = self.ittoc.getMusicBrainzDiscId() # result self.program.result.cdrdaoVersion = cdrdao.getCDRDAOVersion() 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.title \ or 'Unknown Title' _, self.program.result.vendor, self.program.result.model, \ self.program.result.release = \ cdio.Device(self.device).get_hwinfo() self.doCommand() if self.options.eject in ('success', 'always'): utils.eject_device(self.device)
def do(self): runner = ctask.SyncRunner() device = self.options.device # if necessary, load and unmount logger.info('checking device %s', device) utils.load_device(device) utils.unmount_device(device) # first get the Table Of Contents of the CD t = cdrdao.ReadTOCTask(device) table = t.table logger.debug("CDDB disc id: %r", table.getCDDBDiscId()) responses = None try: responses = accurip.get_db_entry(table.accuraterip_path()) except accurip.EntryNotFound: logger.warning("AccurateRip entry not found: drive offset " "can't be determined, try again with another disc") return if responses: logger.debug('%d AccurateRip responses found.', len(responses)) if responses[0].cddbDiscId != table.getCDDBDiscId(): logger.warning("AccurateRip response discid different: %s", responses[0].cddbDiscId) # now rip the first track at various offsets, calculating AccurateRip # CRC, and matching it against the retrieved ones # archecksums is a tuple of accuraterip checksums: (v1, v2) def match(archecksums, track, responses): for i, r in enumerate(responses): for checksum in archecksums: if checksum == r.checksums[track - 1]: return checksum, i return None, None for offset in self._offsets: logger.info('trying read offset %d...', offset) try: archecksums = self._arcs(runner, table, 1, offset) except task.TaskException as e: # let MissingDependency fall through if isinstance(e.exception, common.MissingDependencyException): raise e if isinstance(e.exception, cdparanoia.FileSizeError): logger.warning('cannot rip with offset %d...', offset) continue logger.warning("unknown task exception for offset %d: %s", offset, e) logger.warning('cannot rip with offset %d...', offset) continue logger.debug('AR checksums calculated: %s %s', archecksums) c, i = match(archecksums, 1, responses) if c: count = 1 logger.debug('matched against response %d', i) logger.info('offset of device is likely %d, confirming...', offset) # now try and rip all other tracks as well, except for the # last one (to avoid readers that can't do overread for track in range(2, (len(table.tracks) + 1) - 1): try: archecksums = self._arcs(runner, table, track, offset) except task.TaskException as e: if isinstance(e.exception, cdparanoia.FileSizeError): logger.warning('cannot rip with offset %d...', offset) continue c, i = match(archecksums, track, responses) if c: logger.debug('matched track %d against response %d', track, i) count += 1 if count == len(table.tracks) - 1: self._foundOffset(device, offset) return 0 else: logger.warning( 'only %d of %d tracks matched, ' 'continuing...', count, len(table.tracks)) logger.error('no matching offset found. ' 'Consider trying again with a different disc')
def do(self): runner = ctask.SyncRunner() device = self.options.device # if necessary, load and unmount sys.stdout.write('Checking device %s\n' % device) utils.load_device(device) utils.unmount_device(device) # first get the Table Of Contents of the CD t = cdrdao.ReadTOCTask(device) table = t.table logger.debug("CDDB disc id: %r", table.getCDDBDiscId()) responses = None try: responses = accurip.get_db_entry(table.accuraterip_path()) except accurip.EntryNotFound: print('Accuraterip entry not found') if responses: logger.debug('%d AccurateRip responses found.' % len(responses)) if responses[0].cddbDiscId != table.getCDDBDiscId(): logger.warning("AccurateRip response discid different: %s", responses[0].cddbDiscId) # now rip the first track at various offsets, calculating AccurateRip # CRC, and matching it against the retrieved ones # archecksums is a tuple of accuraterip checksums: (v1, v2) def match(archecksums, track, responses): for i, r in enumerate(responses): for checksum in archecksums: if checksum == r.checksums[track - 1]: return checksum, i return None, None for offset in self._offsets: sys.stdout.write('Trying read offset %d ...\n' % offset) try: archecksums = self._arcs(runner, table, 1, offset) except task.TaskException, e: # let MissingDependency fall through if isinstance(e.exception, common.MissingDependencyException): raise e if isinstance(e.exception, cdparanoia.FileSizeError): sys.stdout.write( 'WARNING: cannot rip with offset %d...\n' % offset) continue logger.warning("Unknown task exception for offset %d: %r" % ( offset, e)) sys.stdout.write( 'WARNING: cannot rip with offset %d...\n' % offset) continue logger.debug('AR checksums calculated: %s %s' % archecksums) c, i = match(archecksums, 1, responses) if c: count = 1 logger.debug('MATCHED against response %d' % i) sys.stdout.write( 'Offset of device is likely %d, confirming ...\n' % offset) # now try and rip all other tracks as well, except for the # last one (to avoid readers that can't do overread for track in range(2, (len(table.tracks) + 1) - 1): try: archecksums = self._arcs(runner, table, track, offset) except task.TaskException, e: if isinstance(e.exception, cdparanoia.FileSizeError): sys.stdout.write( 'WARNING: cannot rip with offset %d...\n' % offset) continue c, i = match(archecksums, track, responses) if c: logger.debug('MATCHED track %d against response %d' % ( track, i)) count += 1 if count == len(table.tracks) - 1: self._foundOffset(device, offset) return 0 else: sys.stdout.write( 'Only %d of %d tracks matched, continuing ...\n' % ( count, len(table.tracks)))
def do(self): self.config = config.Config() self.program = program.Program(self.config, record=self.options.record, stdout=sys.stdout) self.runner = task.SyncRunner() # if the device is mounted (data session), unmount it #self.device = self.parentCommand.options.device self.device = self.options.device sys.stdout.write('Checking device %s\n' % self.device) utils.load_device(self.device) utils.unmount_device(self.device) # first, read the normal TOC, which is fast self.ittoc = self.program.getFastToc(self.runner, self.options.toc_pickle, self.device) # already show us some info based on this self.program.getRipResult(self.ittoc.getCDDBDiscId()) sys.stdout.write("CDDB disc id: %s\n" % self.ittoc.getCDDBDiscId()) self.mbdiscid = self.ittoc.getMusicBrainzDiscId() sys.stdout.write("MusicBrainz disc id %s\n" % self.mbdiscid) sys.stdout.write("MusicBrainz lookup URL %s\n" % 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: sys.stdout.write('FreeDB identifies disc as %s\n' % cddbmd) # also used by rip cd info if not getattr(self.options, 'unknown', False): logger.critical("unable to retrieve disc metadata, " "--unknown not passed") return -1 # FIXME ????? # Hackish fix for broken commit offset = 0 info = drive.getDeviceInfo(self.device) if info: try: offset = self.config.getReadOffset(*info) except KeyError: pass # now, read the complete index table, which is slower self.itable = self.program.getTable(self.runner, self.ittoc.getCDDBDiscId(), self.ittoc.getMusicBrainzDiscId(), self.device, offset) 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()) assert self.itable.getAccurateRipURL() == \ self.ittoc.getAccurateRipURL(), \ "full table's AR URL %s differs from toc AR URL %s" % ( self.itable.getAccurateRipURL(), self.ittoc.getAccurateRipURL()) if self.program.metadata: self.program.metadata.discid = self.ittoc.getMusicBrainzDiscId() # result self.program.result.cdrdaoVersion = cdrdao.getCDRDAOVersion() self.program.result.cdparanoiaVersion = \ cdparanoia.getCdParanoiaVersion() info = drive.getDeviceInfo(self.device) if info: try: self.program.result.cdparanoiaDefeatsCache = \ self.config.getDefeatsCache(*info) except KeyError, e: logger.debug('Got key error: %r' % (e, ))