X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=sima%2Fcore.py;h=87501e83b7d8bc60a616c252229f401d3bfc571e;hb=f0550def23bc07bba4cfaa55d9e724f9fe7776a9;hp=ad21db6f16da571b46d7f8b7ac68253c04421f7c;hpb=e09e76d41b2f041de935e9e884009e3187005ab9;p=mpd-sima.git diff --git a/sima/core.py b/sima/core.py index ad21db6..87501e8 100644 --- a/sima/core.py +++ b/sima/core.py @@ -6,6 +6,7 @@ __version__ = '0.12.0.b' __author__ = 'kaliko jack' __url__ = 'git://git.kaliko.me/sima.git' +import random import sys import time @@ -15,18 +16,21 @@ from logging import getLogger from .client import PlayerClient from .client import PlayerError, PlayerUnHandledError from .lib.simadb import SimaDB +from .lib.daemon import Daemon -class Sima(object): +class Sima(Daemon): """Main class, plugin and player management """ - def __init__(self, conf, dbfile): + def __init__(self, conf): + ## Set daemon + Daemon.__init__(self, conf.get('daemon', 'pidfile')) self.enabled = True self.config = conf - self.sdb = SimaDB(db_path=dbfile) + self.sdb = SimaDB(db_path=conf.get('sima', 'db_file')) self.log = getLogger('sima') self.plugins = list() - self.player = self._get_player() # Player client + self.player = self.__get_player() # Player client try: self.player.connect() except (PlayerError, PlayerUnHandledError) as err: @@ -34,7 +38,7 @@ class Sima(object): self.shutdown() self.short_history = deque(maxlen=60) - def _get_player(self): + def __get_player(self): """Instanciate the player""" host = self.config.get('MPD', 'host') port = self.config.get('MPD', 'port') @@ -73,12 +77,12 @@ class Sima(object): if pl_callback: to_add.extend(pl_callback) if not to_add: - self.log.warning('Queue plugins returned anything!') + self.log.warning('Queue plugins returned nothing!') for plugin in self.plugins: - self.log.info('calling fb for {}'.format(plugin)) pl_callback = getattr(plugin, 'callback_need_track_fb')() if pl_callback: to_add.extend(pl_callback) + random.shuffle(to_add) for track in to_add: self.player.add(track)