parent
19a1e3de1b
commit
b97bf3271d
2 changed files with 33 additions and 9 deletions
|
@ -27,6 +27,7 @@ def get_conf(prefix="LARIGIRA_"):
|
||||||
conf["SECRET_KEY"] = "Please replace me!"
|
conf["SECRET_KEY"] = "Please replace me!"
|
||||||
conf["MPD_WAIT_START"] = True
|
conf["MPD_WAIT_START"] = True
|
||||||
conf["MPD_WAIT_START_RETRYSECS"] = 5
|
conf["MPD_WAIT_START_RETRYSECS"] = 5
|
||||||
|
conf["MPD_ENFORCE_ALWAYS_PLAYING"] = False
|
||||||
conf["CHECK_SECS"] = 20 # period for checking playlist length
|
conf["CHECK_SECS"] = 20 # period for checking playlist length
|
||||||
conf["EVENT_TICK_SECS"] = 30 # period for scheduling events
|
conf["EVENT_TICK_SECS"] = 30 # period for scheduling events
|
||||||
conf["DEBUG"] = False
|
conf["DEBUG"] = False
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import signal
|
import signal
|
||||||
|
|
||||||
|
import mpd
|
||||||
from pkg_resources import iter_entry_points
|
from pkg_resources import iter_entry_points
|
||||||
|
|
||||||
import gevent
|
import gevent
|
||||||
from gevent.queue import Queue
|
from gevent.queue import Queue
|
||||||
import mpd
|
|
||||||
|
|
||||||
|
from .audiogen import audiogenerate
|
||||||
|
from .entrypoints_utils import get_avail_entrypoints
|
||||||
from .event import Monitor
|
from .event import Monitor
|
||||||
from .eventutils import ParentedLet, Timer
|
from .eventutils import ParentedLet, Timer
|
||||||
from .audiogen import audiogenerate
|
|
||||||
from .unused import UnusedCleaner
|
from .unused import UnusedCleaner
|
||||||
from .entrypoints_utils import get_avail_entrypoints
|
|
||||||
|
|
||||||
|
|
||||||
def get_mpd_client(conf):
|
def get_mpd_client(conf):
|
||||||
|
@ -51,7 +53,9 @@ class MPDWatcher(ParentedLet):
|
||||||
FileNotFoundError,
|
FileNotFoundError,
|
||||||
) as exc:
|
) as exc:
|
||||||
self.log.warning(
|
self.log.warning(
|
||||||
"Connection to MPD failed (%s: %s)", exc.__class__.__name__, exc
|
"Connection to MPD failed (%s: %s)",
|
||||||
|
exc.__class__.__name__,
|
||||||
|
exc,
|
||||||
)
|
)
|
||||||
self.client = None
|
self.client = None
|
||||||
first_after_connection = True
|
first_after_connection = True
|
||||||
|
@ -83,9 +87,15 @@ class Player:
|
||||||
mpd_client = mpd.MPDClient(use_unicode=True)
|
mpd_client = mpd.MPDClient(use_unicode=True)
|
||||||
try:
|
try:
|
||||||
mpd_client.connect(self.conf["MPD_HOST"], self.conf["MPD_PORT"])
|
mpd_client.connect(self.conf["MPD_HOST"], self.conf["MPD_PORT"])
|
||||||
except (mpd.ConnectionError, ConnectionRefusedError, FileNotFoundError) as exc:
|
except (
|
||||||
|
mpd.ConnectionError,
|
||||||
|
ConnectionRefusedError,
|
||||||
|
FileNotFoundError,
|
||||||
|
) as exc:
|
||||||
self.log.warning(
|
self.log.warning(
|
||||||
"Connection to MPD failed (%s: %s)", exc.__class__.__name__, exc
|
"Connection to MPD failed (%s: %s)",
|
||||||
|
exc.__class__.__name__,
|
||||||
|
exc,
|
||||||
)
|
)
|
||||||
raise gevent.GreenletExit()
|
raise gevent.GreenletExit()
|
||||||
return mpd_client
|
return mpd_client
|
||||||
|
@ -146,7 +156,9 @@ class Player:
|
||||||
try:
|
try:
|
||||||
ret = ef(songs=songs, context=ctx, conf=self.conf)
|
ret = ef(songs=songs, context=ctx, conf=self.conf)
|
||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
self.log.warn("Filter %s skipped: %s" % (entrypoint.name, exc))
|
self.log.warn(
|
||||||
|
"Filter %s skipped: %s" % (entrypoint.name, exc)
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
if ret is None: # bad behavior!
|
if ret is None: # bad behavior!
|
||||||
continue
|
continue
|
||||||
|
@ -159,7 +171,9 @@ class Player:
|
||||||
return ret, reason
|
return ret, reason
|
||||||
else:
|
else:
|
||||||
if reason:
|
if reason:
|
||||||
self.log.debug('filter %s says ok: %s', entrypoint.name, reason)
|
self.log.debug(
|
||||||
|
"filter %s says ok: %s", entrypoint.name, reason
|
||||||
|
)
|
||||||
return True, "Passed through %s" % ",".join(availfilters)
|
return True, "Passed through %s" % ",".join(availfilters)
|
||||||
|
|
||||||
def enqueue(self, songs):
|
def enqueue(self, songs):
|
||||||
|
@ -200,6 +214,11 @@ class Player:
|
||||||
self.log.exception("Cannot insert song %s", uri)
|
self.log.exception("Cannot insert song %s", uri)
|
||||||
self.tmpcleaner.watch(uri.strip())
|
self.tmpcleaner.watch(uri.strip())
|
||||||
|
|
||||||
|
def play(self):
|
||||||
|
"""make sure that MPD is playing"""
|
||||||
|
mpd_client = self._get_mpd()
|
||||||
|
mpd_client.play()
|
||||||
|
|
||||||
|
|
||||||
class Controller(gevent.Greenlet):
|
class Controller(gevent.Greenlet):
|
||||||
def __init__(self, conf):
|
def __init__(self, conf):
|
||||||
|
@ -234,6 +253,8 @@ class Controller(gevent.Greenlet):
|
||||||
kind == "mpc" and args[0] in ("player", "playlist", "connect")
|
kind == "mpc" and args[0] in ("player", "playlist", "connect")
|
||||||
):
|
):
|
||||||
gevent.Greenlet.spawn(self.player.check_playlist)
|
gevent.Greenlet.spawn(self.player.check_playlist)
|
||||||
|
if self.conf["MPD_ENFORCE_ALWAYS_PLAYING"]:
|
||||||
|
gevent.Greenlet.spawn(self.player.play)
|
||||||
try:
|
try:
|
||||||
self.player.tmpcleaner.check_playlist()
|
self.player.tmpcleaner.check_playlist()
|
||||||
except:
|
except:
|
||||||
|
@ -251,7 +272,9 @@ class Controller(gevent.Greenlet):
|
||||||
self.log.exception(
|
self.log.exception(
|
||||||
"Error while adding to queue; " "bad audiogen output?"
|
"Error while adding to queue; " "bad audiogen output?"
|
||||||
)
|
)
|
||||||
elif (kind == "signal" and args[0] == signal.SIGALRM) or kind == "refresh":
|
elif (
|
||||||
|
kind == "signal" and args[0] == signal.SIGALRM
|
||||||
|
) or kind == "refresh":
|
||||||
# it's a tick!
|
# it's a tick!
|
||||||
self.log.debug("Reload")
|
self.log.debug("Reload")
|
||||||
self.monitor.q.put(dict(kind="forcetick"))
|
self.monitor.q.put(dict(kind="forcetick"))
|
||||||
|
|
Loading…
Reference in a new issue