X-Git-Url: http://git.kaliko.me/?a=blobdiff_plain;f=sima%2Flib%2Fplugin.py;h=cea4448346749c582e91944623712978ff5f595b;hb=c660efb577c11bde6229d37550bf197fa6bae3e4;hp=ac21b2f6117b2752ba88a855bafd8bb0ede842a4;hpb=1cc879f39941fc302f9a841a532c9f749797cca4;p=mpd-sima.git diff --git a/sima/lib/plugin.py b/sima/lib/plugin.py index ac21b2f..cea4448 100644 --- a/sima/lib/plugin.py +++ b/sima/lib/plugin.py @@ -1,13 +1,59 @@ # -*- coding: utf-8 -*- class Plugin(): + """ + First non-empty line of the docstring is used as description + Rest of the docstring at your convenience. + + The plugin Name MUST be the same as the module (file name), case + insensitive: for instance plugin.py → Plugin + It eases plugins discovery and simplifies the code to handle them, + IMHO, it's a fair trade-off. + """ + + @classmethod + def info(cls): + """self documenting class method + """ + doc = 'Undocumented plugin! Fill "{}" docstring'.format(cls.__name__) + if cls.__doc__: + doc = cls.__doc__.strip(' \n').splitlines()[0] + return {'name': cls.__name__, + 'doc': doc, + } + def __init__(self, daemon): + self.log = daemon.log self.__daemon = daemon - #self.history = daemon.player.history + self.player = daemon.player + self.plugin_conf = None + self.__get_config() - @property - def name(self): - return self.__class__.__name__.lower() + def __str__(self): + return self.__class__.__name__ + + def __get_config(self): + """Get plugin's specific configuration from global applications's config + """ + conf = self.__daemon.config + for sec in conf.sections(): + if sec.lower() == self.__class__.__name__.lower(): + self.plugin_conf = dict(conf.items(sec)) + #if self.plugin_conf: + # self.log.debug('Got config for {0}: {1}'.format(self, + # self.plugin_conf)) + + def callback_player(self): + """ + Called on player changes, stopped, paused, skipped + """ + pass + + def callback_player_database(self): + """ + Called on player music library changes + """ + pass def callback_playlist(self): """ @@ -19,18 +65,18 @@ class Plugin(): def callback_next_song(self): """Not returning data, - Could be use to scrobble + Could be use to scrobble, maintain an history… """ pass - def callback_need_song(self): + def callback_need_track(self): """Returns a list of Track objects to add """ pass - def callback_player_stop(self): - """Not returning data, - Could be use to ensure player never stops + def callback_need_track_fb(self): + """Called when callback_next_song failled to find tracks to queue + Returns a list of Track objects to add """ pass