MPD_ENFORCE_ALWAYS_PLAYING option

refs #16
This commit is contained in:
boyska 2021-03-27 13:20:02 +01:00
parent 19a1e3de1b
commit b97bf3271d
2 changed files with 33 additions and 9 deletions

View file

@ -27,6 +27,7 @@ def get_conf(prefix="LARIGIRA_"):
conf["SECRET_KEY"] = "Please replace me!"
conf["MPD_WAIT_START"] = True
conf["MPD_WAIT_START_RETRYSECS"] = 5
conf["MPD_ENFORCE_ALWAYS_PLAYING"] = False
conf["CHECK_SECS"] = 20 # period for checking playlist length
conf["EVENT_TICK_SECS"] = 30 # period for scheduling events
conf["DEBUG"] = False

View file

@ -1,17 +1,19 @@
from __future__ import print_function
import logging
import signal
import mpd
from pkg_resources import iter_entry_points
import gevent
from gevent.queue import Queue
import mpd
from .audiogen import audiogenerate
from .entrypoints_utils import get_avail_entrypoints
from .event import Monitor
from .eventutils import ParentedLet, Timer
from .audiogen import audiogenerate
from .unused import UnusedCleaner
from .entrypoints_utils import get_avail_entrypoints
def get_mpd_client(conf):
@ -51,7 +53,9 @@ class MPDWatcher(ParentedLet):
FileNotFoundError,
) as exc:
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
first_after_connection = True
@ -83,9 +87,15 @@ class Player:
mpd_client = mpd.MPDClient(use_unicode=True)
try:
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(
"Connection to MPD failed (%s: %s)", exc.__class__.__name__, exc
"Connection to MPD failed (%s: %s)",
exc.__class__.__name__,
exc,
)
raise gevent.GreenletExit()
return mpd_client
@ -146,7 +156,9 @@ class Player:
try:
ret = ef(songs=songs, context=ctx, conf=self.conf)
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
if ret is None: # bad behavior!
continue
@ -159,7 +171,9 @@ class Player:
return ret, reason
else:
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)
def enqueue(self, songs):
@ -200,6 +214,11 @@ class Player:
self.log.exception("Cannot insert song %s", uri)
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):
def __init__(self, conf):
@ -234,6 +253,8 @@ class Controller(gevent.Greenlet):
kind == "mpc" and args[0] in ("player", "playlist", "connect")
):
gevent.Greenlet.spawn(self.player.check_playlist)
if self.conf["MPD_ENFORCE_ALWAYS_PLAYING"]:
gevent.Greenlet.spawn(self.player.play)
try:
self.player.tmpcleaner.check_playlist()
except:
@ -251,7 +272,9 @@ class Controller(gevent.Greenlet):
self.log.exception(
"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!
self.log.debug("Reload")
self.monitor.q.put(dict(kind="forcetick"))