#!/usr/bin/env python # The Ripoff command-line interface, implemented with Russ Cox' # iterator interface (in arg_parser.py). import sys, os import ripoff from ripoff import cdrom from arg_parser import ArgParser # Dummy class to hold all the option values. This is also where # we set the default value for each option value. class Options: def __init__ (self): self.verbose = 1 self.device = cdrom.get_default_device() self.output_base = None self.tracks = None self.use_pipes = 1 self.keep_tmp = 0 self.rip_only = 0 self.playback = 0 self.eject = 0 self.artist = None self.album = None self.disc = None self.year = None self.offset = None # Usage and help text. prog = os.path.basename(sys.argv[0]) usage = "usage: %s [options]\n" % prog help = usage + """ options: -h, --help show this help message and exit --version show program's version number and exit -v increase verbosity level --verbose=V set verbosity level to V -q, --quiet run silently (verbosity = 0) -dDEVICE, --device=DEVICE device file to open (default: /dev/cdrom on this platform) -bDIR, --output-base=DIR base output dir (default: /music/ogg) -tTRACKS, --tracks=TRACKS tracks to rip (default: all) (example: 1,2-5,8) -p, --use-pipes, --synchronous use named pipes for intermediate output (uses less temporary disk space, works great if encoding is faster than ripping) [default] -f, --use-files, --asynchronous use real files for intermediate output (uses more temporary disk space, but should be more reliable if ripping is faster than encoding, and will free up your CD-ROM drive sooner) -k, --keep-tmp put temporary (.wav) files in output dir, and don't delete them when done with them (implies -f) -R, --rip-only just do digital audio extraction -- no encoding (implies -k, -f) -P, --playback play encoded audio files as encoding proceeds -e, --eject eject CD when finished -AARTIST, --artist=ARTIST use ARTIST for tagging and file naming (overrides CDDB/CDindex) -LALBUM, --album=ALBUM use ALBUM for tagging and file naming -DDISC, --disc=DISC set disc number to DISC (for multi-disc sets) -yYEAR, --year=YEAR use YEAR for tagging --offset=OFFSET add OFFSET to track numbers for tagging and file naming """ # Create the option holder, the option iterator, and iterate # over the command-line. options = Options() parser = ArgParser(usage) for opt in parser: if opt in ("-h", "--help"): print help sys.exit() elif opt == "--version": print "ripoff %s" % ripoff.__version__ sys.exit() elif opt == "-v": options.verbose += 1 elif opt == "--verbose": # XXX error-handling? options.verbose = int(parser.nextarg()) elif opt in ("-q", "--quiet"): options.verbose = 0 elif opt in ("-d", "--device"): options.device = parser.nextarg() elif opt in ("-b", "--output-base"): options.output_base = parser.nextarg() elif opt in ("t", "--tracks"): options.tracks = parser.nextarg() elif opt in ("-p", "--use-pipes", "--synchronous"): options.use_pipes = 1 elif opt in ("-f", "--use-files", "--asynchronous"): options.use_files = 0 elif opt in ("-k", "--keep-tmp"): options.keep_tmp = 1 elif opt in ("-R", "--rip-only"): options.rip_only = 1 elif opt in ("-P", "--playback"): options.playback = 1 elif opt in ("-e", "--eject"): options.eject = 1 elif opt in ("-A", "--artist"): options.artist = parser.nextarg() elif opt in ("-L", "--album"): options.album = parser.nextarg() elif opt in ("-D", "--disc"): options.album = int(parser.nextarg()) elif opt in ("-y", "--year"): options.year = parser.nextarg() elif opt == "--offset": options.track_offset = int(parser.nextarg()) else: parser.error("unknown option: " + opt) if parser.argv: parser.error("too many arguments") # Print the option values. from pprint import pprint print "options:" pprint(vars(options))