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:
parent
e64880b445
commit
2bde308720
2 changed files with 16 additions and 5 deletions
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue