class MPDStatsPlugin(plugins.BeetsPlugin): item_types = { 'play_count': types.INTEGER, 'skip_count': types.INTEGER, 'last_played': library.DateType(), 'rating': types.FLOAT, } def __init__(self): super(MPDStatsPlugin, self).__init__() self.config.add({ 'music_directory': config['directory'].as_filename(), 'rating': True, 'rating_mix': 0.75, }) config['mpd'].add({ 'host': u'localhost', 'port': 6600, 'password': u'', }) def commands(self): cmd = ui.Subcommand('mpdstats', help='run a MPD client to gather play statistics') cmd.parser.add_option( '--host', dest='host', type='string', help='set the hostname of the server to connect to') cmd.parser.add_option( '--port', dest='port', type='int', help='set the port of the MPD server to connect to') cmd.parser.add_option( '--password', dest='password', type='string', help='set the password of the MPD server to connect to') def func(lib, opts, args): self.config.set_args(opts) # Overrides for MPD settings. if opts.host: config['mpd']['host'] = opts.host.decode('utf8') if opts.port: config['mpd']['host'] = int(opts.port) if opts.password: config['mpd']['password'] = opts.password.decode('utf8') try: MPDStats(lib).run() except KeyboardInterrupt: pass cmd.func = func return [cmd]
def _types(self): if not self.config.exists(): return {} mytypes = {} for key, value in self.config.items(): if value.get() == 'int': mytypes[key] = types.INTEGER elif value.get() == 'float': mytypes[key] = types.FLOAT elif value.get() == 'bool': mytypes[key] = types.BOOLEAN elif value.get() == 'date': mytypes[key] = library.DateType() else: raise ConfigValueError( "unknown type '{}' for the '{}' field".format(value, key)) return mytypes