def main(): server = config.Config().get_musicbrainz_server() musicbrainzngs.set_hostname(server) # Find whipper's plugins paths (local paths have higher priority) plugins_p = [directory.data_path('plugins')] # local path (in $HOME) if hasattr(sys, 'real_prefix'): # no getsitepackages() in virtualenv plugins_p.append( get_python_lib( plat_specific=False, standard_lib=False, prefix='/usr/local') + '/whipper/plugins') plugins_p.append( get_python_lib(plat_specific=False, standard_lib=False) + '/whipper/plugins') else: plugins_p += [x + '/whipper/plugins' for x in site.getsitepackages()] # register plugins with pkg_resources distributions, _ = pkg_resources.working_set.find_plugins( pkg_resources.Environment(plugins_p)) list(map(pkg_resources.working_set.add, distributions)) try: cmd = Whipper(sys.argv[1:], os.path.basename(sys.argv[0]), None) ret = cmd.do() except SystemError as e: logger.critical("SystemError: %s", e) if (isinstance(e, common.EjectError) and cmd.options.eject in ('failure', 'always')): eject_device(e.device) return 255 except RuntimeError as e: print(e) return 1 except KeyboardInterrupt: return 2 except ImportError as e: raise except task.TaskException as e: if isinstance(e.exception, ImportError): raise ImportError(e.exception) elif isinstance(e.exception, common.MissingDependencyException): logger.critical('missing dependency "%s"', e.exception.dependency) return 255 if isinstance(e.exception, common.EmptyError): logger.debug("EmptyError: %s", e.exception) logger.critical('could not create encoded file') return 255 # in python3 we can instead do `raise e.exception` as that would show # the exception's original context logger.critical(e.exceptionMessage) return 255 return ret if ret else 0
def main(): server = config.Config().get_musicbrainz_server() musicbrainzngs.set_hostname(server) # Find whipper's plugins paths (local paths have higher priority) plugins_p = [directory.data_path('plugins')] # local path (in $HOME) if hasattr(sys, 'real_prefix'): # no getsitepackages() in virtualenv plugins_p.append( get_python_lib(plat_specific=False, standard_lib=False, prefix='/usr/local') + '/whipper/plugins') plugins_p.append(get_python_lib(plat_specific=False, standard_lib=False) + '/whipper/plugins') else: plugins_p += [x + '/whipper/plugins' for x in site.getsitepackages()] # register plugins with pkg_resources distributions, _ = pkg_resources.working_set.find_plugins( pkg_resources.Environment(plugins_p) ) list(map(pkg_resources.working_set.add, distributions)) try: cmd = Whipper(sys.argv[1:], os.path.basename(sys.argv[0]), None) ret = cmd.do() except SystemError as e: logger.critical("SystemError: %s", e) if (isinstance(e, common.EjectError) and cmd.options.eject in ('failure', 'always')): eject_device(e.device) return 255 except RuntimeError as e: print(e) return 1 except KeyboardInterrupt: return 2 except ImportError as e: raise except task.TaskException as e: if isinstance(e.exception, ImportError): raise ImportError(e.exception) elif isinstance(e.exception, common.MissingDependencyException): logger.critical('missing dependency "%s"', e.exception.dependency) return 255 if isinstance(e.exception, common.EmptyError): logger.debug("EmptyError: %s", e.exception) logger.critical('could not create encoded file') return 255 # in python3 we can instead do `raise e.exception` as that would show # the exception's original context logger.critical(e.exceptionMessage) return 255 return ret if ret else 0
def main(): try: server = config.Config().get_musicbrainz_server() except KeyError as e: sys.stderr.write('whipper: %s\n' % str(e)) sys.exit() musicbrainzngs.set_hostname(server) # register plugins with pkg_resources distributions, _ = pkg_resources.working_set.find_plugins( pkg_resources.Environment([directory.data_path('plugins')])) list(map(pkg_resources.working_set.add, distributions)) try: cmd = Whipper(sys.argv[1:], os.path.basename(sys.argv[0]), None) ret = cmd.do() except SystemError as e: sys.stderr.write('whipper: error: %s\n' % e) if (isinstance(e, common.EjectError) and cmd.options.eject in ('failure', 'always')): eject_device(e.device) return 255 except RuntimeError as e: print(e) return 1 except KeyboardInterrupt: return 2 except ImportError as e: raise except task.TaskException as e: if isinstance(e.exception, ImportError): raise ImportError(e.exception) elif isinstance(e.exception, common.MissingDependencyException): sys.stderr.write('whipper: error: missing dependency "%s"\n' % e.exception.dependency) return 255 if isinstance(e.exception, common.EmptyError): logger.debug("EmptyError: %r", str(e.exception)) sys.stderr.write('whipper: error: Could not create encoded file.\n' ) # noqa: E501 return 255 # in python3 we can instead do `raise e.exception` as that would show # the exception's original context sys.stderr.write(e.exceptionMessage) return 255 return ret if ret else 0
def main(): # set user agent musicbrainzngs.set_useragent("whipper", whipper.__version__, "https://github.com/JoeLametta/whipper") # register plugins with pkg_resources distributions, _ = pkg_resources.working_set.find_plugins( pkg_resources.Environment([directory.data_path('plugins')])) map(pkg_resources.working_set.add, distributions) try: cmd = Whipper(sys.argv[1:], os.path.basename(sys.argv[0]), None) ret = cmd.do() except SystemError, e: sys.stderr.write('whipper: error: %s\n' % e) if (type(e) is common.EjectError and cmd.options.eject in ('failure', 'always')): eject_device(e.device) return 255
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 main(): server = config.Config().get_musicbrainz_server() https_enabled = server['scheme'] == 'https' try: musicbrainzngs.set_hostname(server['netloc'], https_enabled) # Parameter 'use_https' is missing in versions of musicbrainzngs < 0.7 except TypeError: logger.warning("Parameter 'use_https' is missing in versions of " "musicbrainzngs < 0.7. This means whipper will only " "be able to communicate with the configured " "MusicBrainz server ('%s') over plain HTTP. If a " "custom server which speaks HTTPS only has been " "declared, a suitable version of the " "musicbrainzngs module will be needed " "to make it work in whipper.", server['netloc']) musicbrainzngs.set_hostname(server['netloc']) # Find whipper's plugins paths (local paths have higher priority) plugins_p = [directory.data_path('plugins')] # local path (in $HOME) if hasattr(sys, 'real_prefix'): # no getsitepackages() in virtualenv plugins_p.append( get_python_lib(plat_specific=False, standard_lib=False, prefix='/usr/local') + '/whipper/plugins') plugins_p.append(get_python_lib(plat_specific=False, standard_lib=False) + '/whipper/plugins') else: plugins_p += [x + '/whipper/plugins' for x in site.getsitepackages()] # register plugins with pkg_resources distributions, _ = pkg_resources.working_set.find_plugins( pkg_resources.Environment(plugins_p) ) list(map(pkg_resources.working_set.add, distributions)) try: cmd = Whipper(sys.argv[1:], os.path.basename(sys.argv[0]), None) ret = cmd.do() except SystemError as e: logger.critical("SystemError: %s", e) if (isinstance(e, common.EjectError) and cmd.options.eject in ('failure', 'always')): # XXX: Pylint, instance of 'SystemError' has no 'device' member eject_device(e.device) return 255 except RuntimeError as e: print(e) return 1 except KeyboardInterrupt: return 2 except ImportError: raise except task.TaskException as e: if isinstance(e.exception, ImportError): raise ImportError(e.exception) elif isinstance(e.exception, common.MissingDependencyException): logger.critical('missing dependency "%s"', e.exception.dependency) return 255 if isinstance(e.exception, common.EmptyError): logger.debug("EmptyError: %s", e.exception) logger.critical('could not create encoded file') return 255 # in python3 we can instead do `raise e.exception` as that would show # the exception's original context logger.critical(e.exceptionMessage) return 255 return ret if ret else 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) 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)
class _CD(BaseCommand): """ @type program: L{program.Program} @ivar eject: whether to eject the drive after completing """ eject = True @staticmethod def add_arguments(parser): # FIXME: have a cache of these pickles somewhere parser.add_argument('-T', '--toc-pickle', action="store", dest="toc_pickle", help="pickle to use for reading and " "writing the TOC") parser.add_argument('-R', '--release-id', action="store", dest="release_id", help="MusicBrainz release id to match to " "(if there are multiple)") parser.add_argument('-p', '--prompt', action="store_true", dest="prompt", help="Prompt if there are multiple " "matching releases") parser.add_argument('-c', '--country', action="store", dest="country", help="Filter releases by country") 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 # 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, )) 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' try: import cdio _, self.program.result.vendor, self.program.result.model, \ self.program.result.release = \ cdio.Device(self.device).get_hwinfo() except ImportError: raise ImportError("Pycdio module import failed.\n" "This is a hard dependency: if not " "available please install it") self.doCommand() if self.options.eject in ('success', 'always'): utils.eject_device(self.device)
sys.exit() musicbrainzngs.set_hostname(server) # register plugins with pkg_resources distributions, _ = pkg_resources.working_set.find_plugins( pkg_resources.Environment([directory.data_path('plugins')]) ) map(pkg_resources.working_set.add, distributions) try: cmd = Whipper(sys.argv[1:], os.path.basename(sys.argv[0]), None) ret = cmd.do() except SystemError, e: sys.stderr.write('whipper: error: %s\n' % e) if (type(e) is common.EjectError and cmd.options.eject in ('failure', 'always')): eject_device(e.device) return 255 except RuntimeError, e: print(e) return 1 except KeyboardInterrupt: return 2 except ImportError, e: raise except task.TaskException, e: if isinstance(e.exception, ImportError): raise ImportError(e.exception) elif isinstance(e.exception, common.MissingDependencyException): sys.stderr.write('whipper: error: missing dependency "%s"\n' % e.exception.dependency) return 255