def write(self): """Write the track's metadata to the associated file. """ for file in self.files: f = MediaFile(syspath(file.path)) # TODO save values to mediafile f.title = self.title f.artist = self.artist.name f.album = self.release.name f.genre = self.genre f.composer = self.composer # f.grouping = # parse time format # TODO: add these to beets.util #time_format = "%Y-%m-%d %H:%M:%S" #date = datetime.datetime.fromtimestamp(time.mktime(time.strptime(self.date, time_format))) #f.year = date.year #f.month = date.month #f.day = date.day #f.date = self.date f.track = self.track f.tracktotal = self.release.tracktotal f.disc = self.disc f.disctotal = self.release.disctotal # f.lyrics = #f.comments = #f.bpm = #f.comp = #f.albumartist = #f.albumtype = # f.art = #f.mb_trackid = #f.mb_albumid = #f.mb_artistid = #f.mb_albumartistid = f.save()
def main(args=None): """Run the main command-line interface for beets.""" # {{{ read the config file config = ConfigParser.SafeConfigParser() if CONFIG_PATH_VAR in os.environ: configpath = os.path.expanduser(os.environ[CONFIG_PATH_VAR]) else: configpath = DEFAULT_CONFIG_FILE if configpath: configpath = util.syspath(configpath) if os.path.exists(configpath): config.readfp(open(util.syspath(configpath))) # }}} end read config file # {{{ Construct the root parser. from musicdir.ui.commands import default_commands commands = list(default_commands) # commands += plugins.commands() parser = SubcommandsOptionParser(subcommands=commands) parser.add_option('-l', '--library', dest='libpath', help='library database file to use') parser.add_option('-d', '--directory', dest='directory', help="destination music directory") parser.add_option('-p', '--pathformat', dest='path_format', help="destination path format string") parser.add_option('-v', '--verbose', dest='verbose', action='store_true', help='print debugging information') # }}} end Construct the root parser # Parse the command-line! options, subcommand, suboptions, subargs = parser.parse_args(args) # {{{ Open library file. libpath = options.libpath or \ config_val(config, 'musicdir', 'library', DEFAULT_LIBRARY) directory = options.directory or \ config_val(config, 'musicdir', 'directory', DEFAULT_DIRECTORY) legacy_path_format = config_val(config, 'musicdir', 'path_format', None) if options.path_format: # If given, -p overrides all path format settings path_formats = {'default': options.path_format} else: if legacy_path_format: # Old path formats override the default values. path_formats = {'default': legacy_path_format} else: # If no legacy path format, use the defaults instead. path_formats = DEFAULT_PATH_FORMATS if config.has_section('paths'): path_formats.update(config.items('paths')) lib = library.Library(os.path.expanduser(libpath), directory, path_formats) # }}} end Open the library file # {{{ Configure the logger. log = logging.getLogger('musicdir') if options.verbose: log.setLevel(logging.DEBUG) else: log.setLevel(logging.INFO) # }}} end Configure the logger. # {{{ Invoke the subcommand. try: subcommand.func(lib, config, suboptions, subargs) except UserError, exc: message = exc.args[0] if exc.args else None subcommand.parser.error(message)
def main(args=None): """Run the main command-line interface for beets.""" # {{{ read the config file config = ConfigParser.SafeConfigParser() if CONFIG_PATH_VAR in os.environ: configpath = os.path.expanduser(os.environ[CONFIG_PATH_VAR]) else: configpath = DEFAULT_CONFIG_FILE if configpath: configpath = util.syspath(configpath) if os.path.exists(configpath): config.readfp(open(util.syspath(configpath))) # }}} end read config file # {{{ Construct the root parser. from musicdir.ui.commands import default_commands commands = list(default_commands) # commands += plugins.commands() parser = SubcommandsOptionParser(subcommands=commands) parser.add_option('-l', '--library', dest='libpath', help='library database file to use') parser.add_option('-d', '--directory', dest='directory', help="destination music directory") parser.add_option('-p', '--pathformat', dest='path_format', help="destination path format string") parser.add_option('-v', '--verbose', dest='verbose', action='store_true', help='print debugging information') # }}} end Construct the root parser # Parse the command-line! options, subcommand, suboptions, subargs = parser.parse_args(args) # {{{ Open library file. libpath = options.libpath or \ config_val(config, 'musicdir', 'library', DEFAULT_LIBRARY) directory = options.directory or \ config_val(config, 'musicdir', 'directory', DEFAULT_DIRECTORY) legacy_path_format = config_val(config, 'musicdir', 'path_format', None) if options.path_format: # If given, -p overrides all path format settings path_formats = {'default': options.path_format} else: if legacy_path_format: # Old path formats override the default values. path_formats = {'default': legacy_path_format} else: # If no legacy path format, use the defaults instead. path_formats = DEFAULT_PATH_FORMATS if config.has_section('paths'): path_formats.update(config.items('paths')) lib = library.Library(os.path.expanduser(libpath), directory, path_formats ) # }}} end Open the library file # {{{ Configure the logger. log = logging.getLogger('musicdir') if options.verbose: log.setLevel(logging.DEBUG) else: log.setLevel(logging.INFO) # }}} end Configure the logger. # {{{ Invoke the subcommand. try: subcommand.func(lib, config, suboptions, subargs) except UserError, exc: message = exc.args[0] if exc.args else None subcommand.parser.error(message)