add "metadata" to song while adding them

This gives more useful logs (songs now have an "origin"), and paves way to #7
This commit is contained in:
boyska 2016-08-23 18:23:49 +02:00
parent e64880b445
commit 2bde308720
No known key found for this signature in database
GPG key ID: 7395DCAE58289CA9
2 changed files with 16 additions and 5 deletions

View file

@ -152,7 +152,13 @@ class Monitor(ParentedLet):
'should play %s' % str(g.value)))
audiogen.link_exception(lambda g: self.log.exception(
'Failure in audiogen {}: {}'.format(audiospec, audiogen.exception)))
audiogen.link_value(lambda g: self.send_to_parent('add', g.value))
audiogen.link_value(lambda g:
self.send_to_parent('add',
dict(uris=g.value,
audiospec=audiospec,
aid=audiospec.eid
))
)
def _run(self):
self.source.start()

View file

@ -70,14 +70,19 @@ class Player(gevent.Greenlet):
def enqueue(self, songs):
mpd_client = self._get_mpd()
for song in songs:
self.log.info('Adding {} to playlist'.format(song))
assert type(songs) is dict
assert 'uris' in songs
spec = songs['audiospec']
for uri in songs['uris']:
assert type(uri) is str
self.log.info('Adding {} to playlist (from {}={})'.
format(uri, songs['aid'], spec))
insert_pos = 0 if len(mpd_client.playlistid()) == 0 else \
int(mpd_client.currentsong().get('pos', 0)) + 1
try:
mpd_client.addid(song, insert_pos)
mpd_client.addid(uri, insert_pos)
except CommandError:
self.log.exception("Cannot insert song {}".format(song))
self.log.exception("Cannot insert song {}".format(uri))
def _run(self):
mw = MpcWatcher(self.q, self.conf, client=None)