]> kaliko git repositories - mpd-sima.git/blob - sima/lib/plugin.py
Some more clean-up
[mpd-sima.git] / sima / lib / plugin.py
1 # -*- coding: utf-8 -*-
2 # Copyright (c) 2013-2015 Jack Kaliko <kaliko@azylum.org>
3 #
4 #  This file is part of sima
5 #
6 #  sima is free software: you can redistribute it and/or modify
7 #  it under the terms of the GNU General Public License as published by
8 #  the Free Software Foundation, either version 3 of the License, or
9 #  (at your option) any later version.
10 #
11 #  sima is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #  GNU General Public License for more details.
15 #
16 #  You should have received a copy of the GNU General Public License
17 #  along with sima.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 #
20 """
21 Plugin object to derive from
22 """
23
24 class Plugin:
25     """
26     First non-empty line of the docstring is used as description
27     Rest of the docstring at your convenience.
28
29     The lowercased plugin Name MUST be the same as the module (file name),
30     for instance Plugin → plugin.py
31     It eases plugins discovery and simplifies the code to handle them,
32     IMHO, it's a fair trade-off.
33     """
34
35     @classmethod
36     def info(cls):
37         """self documenting class method
38         """
39         doc = 'Undocumented plugin! Fill "{}" docstring'.format(cls.__name__)
40         if cls.__doc__:
41             doc = cls.__doc__.strip(' \n').splitlines()[0]
42         return {'name': cls.__name__,
43                 'doc': doc,
44                 }
45
46     def __init__(self, daemon):
47         self.log = daemon.log
48         self.__daemon = daemon
49         self.player = daemon.player
50         self.plugin_conf = None
51         self.__get_config()
52
53     def __str__(self):
54         return self.__class__.__name__
55
56     def __get_config(self):
57         """Get plugin's specific configuration from global applications's config
58         """
59         conf = self.__daemon.config
60         for sec in conf.sections():
61             if sec == self.__class__.__name__.lower():
62                 self.plugin_conf = conf[sec]
63         #if self.plugin_conf:
64         #    self.log.debug('Got config for {0}: {1}'.format(self,
65         #                                                    self.plugin_conf))
66
67     def start(self):
68         """
69         Called when the daemon().run() is called and
70         right after the player has connected successfully.
71         """
72         pass
73
74     def callback_player(self):
75         """
76         Called on player changes, stopped, paused, skipped
77         """
78         pass
79
80     def callback_player_database(self):
81         """
82         Called on player music library changes
83         """
84         pass
85
86     def callback_playlist(self):
87         """
88         Called on playlist changes
89         Not returning data
90         """
91         pass
92
93     def callback_next_song(self):
94         """
95         Could be use to scrobble, maintain an history…
96         Not returning data,
97         """
98         pass
99
100     def callback_need_track(self):
101         """
102         Returns a list of Track objects to add
103         """
104         pass
105
106     def callback_need_track_fb(self):
107         """
108         Called when callback_need_track failled to find tracks to queue
109         Returns a list of Track objects to add
110         """
111         pass
112
113     def shutdown(self):
114         """Called on application shutdown"""
115         pass
116
117
118 # VIM MODLINE
119 # vim: ai ts=4 sw=4 sts=4 expandtab