|
@@ -1,10 +1,12 @@
|
|
from __future__ import print_function
|
|
from __future__ import print_function
|
|
from gevent import monkey
|
|
from gevent import monkey
|
|
monkey.patch_all(subprocess=True)
|
|
monkey.patch_all(subprocess=True)
|
|
|
|
+import os
|
|
|
|
|
|
import logging
|
|
import logging
|
|
|
|
+FORMAT = '%(asctime)s|%(levelname)s[%(name)s:%(lineno)d] %(message)s'
|
|
logging.basicConfig(level=logging.INFO,
|
|
logging.basicConfig(level=logging.INFO,
|
|
- format='%(asctime)s %(message)s',
|
|
|
|
|
|
+ format=FORMAT,
|
|
datefmt='%H:%M:%S')
|
|
datefmt='%H:%M:%S')
|
|
import signal
|
|
import signal
|
|
|
|
|
|
@@ -13,9 +15,13 @@ from gevent.queue import Queue
|
|
from gevent.wsgi import WSGIServer
|
|
from gevent.wsgi import WSGIServer
|
|
from mpd import MPDClient
|
|
from mpd import MPDClient
|
|
|
|
|
|
-from eventutils import ParentedLet, CeleryTask, Timer
|
|
|
|
-from task import create as create_continous
|
|
|
|
|
|
+from eventutils import ParentedLet, Timer
|
|
import rpc
|
|
import rpc
|
|
|
|
+from audiogen import generate
|
|
|
|
+
|
|
|
|
+CONTINOUS_AUDIODESC = dict(kind='mpd', howmany=1)
|
|
|
|
+MPD_HOST = os.getenv('MPD_HOST', 'localhost')
|
|
|
|
+MPD_PORT = int(os.getenv('MPD_PORT', '6600'))
|
|
|
|
|
|
|
|
|
|
class MpcWatcher(ParentedLet):
|
|
class MpcWatcher(ParentedLet):
|
|
@@ -24,13 +30,12 @@ class MpcWatcher(ParentedLet):
|
|
if client is None:
|
|
if client is None:
|
|
self.client = MPDClient()
|
|
self.client = MPDClient()
|
|
# TODO: use config values
|
|
# TODO: use config values
|
|
- self.client.connect("localhost", 6600)
|
|
|
|
|
|
+ self.client.connect(MPD_HOST, MPD_PORT)
|
|
else:
|
|
else:
|
|
self.client = client # assume it is already connected
|
|
self.client = client # assume it is already connected
|
|
|
|
|
|
def do_business(self):
|
|
def do_business(self):
|
|
while True:
|
|
while True:
|
|
- # status = check_output(['mpc', 'idle']).decode('utf-8').strip()
|
|
|
|
status = self.client.idle()[0]
|
|
status = self.client.idle()[0]
|
|
logging.info(status)
|
|
logging.info(status)
|
|
yield ('mpc', status)
|
|
yield ('mpc', status)
|
|
@@ -50,8 +55,9 @@ class Player(gevent.Greenlet):
|
|
if(len(songs) >= self.min_playlist_length):
|
|
if(len(songs) >= self.min_playlist_length):
|
|
return
|
|
return
|
|
logging.info('need to add new songs')
|
|
logging.info('need to add new songs')
|
|
- CeleryTask(create_continous, self.q).start()
|
|
|
|
- CeleryTask(create_continous, self.q).start()
|
|
|
|
|
|
+ picker = gevent.Greenlet(generate, CONTINOUS_AUDIODESC)
|
|
|
|
+ picker.link_value(lambda g: mpd_client.add(next(g.value).strip()))
|
|
|
|
+ picker.start()
|
|
|
|
|
|
def _run(self):
|
|
def _run(self):
|
|
MpcWatcher(self.q, client=None).start()
|
|
MpcWatcher(self.q, client=None).start()
|
|
@@ -67,8 +73,8 @@ class Player(gevent.Greenlet):
|
|
logging.info('CLOCK')
|
|
logging.info('CLOCK')
|
|
if kind == 'timer' or (kind == 'mpc' and args[0] == 'playlist'):
|
|
if kind == 'timer' or (kind == 'mpc' and args[0] == 'playlist'):
|
|
gevent.Greenlet.spawn(self.check_playlist)
|
|
gevent.Greenlet.spawn(self.check_playlist)
|
|
- elif kind == 'celery':
|
|
|
|
- logging.info("celery: %s" % str(args))
|
|
|
|
|
|
+ elif value['tracker'] == 'mpd_generate':
|
|
|
|
+ logging.info("generated! %s" % tuple(args[0]))
|
|
else:
|
|
else:
|
|
logging.warning("Unknown message: %s" % str(value))
|
|
logging.warning("Unknown message: %s" % str(value))
|
|
logging.info(str(value))
|
|
logging.info(str(value))
|