Skip to content

Commit

Permalink
✨ (api) getnext track api
Browse files Browse the repository at this point in the history
  • Loading branch information
hairmare committed Jun 3, 2020
1 parent fbee74c commit 91b28f0
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion klangbecken.py
Expand Up @@ -484,7 +484,8 @@ def __init__(self,
Rule(playlist_url, methods=('POST',), endpoint='upload'),
Rule(file_url, methods=('PUT',), endpoint='update'),
Rule(file_url, methods=('DELETE',), endpoint='delete'),
Rule('/playnext/', methods=('POST',), endpoint='play_next')
Rule('/playnext/', methods=('POST',), endpoint='play_next'),
Rule('/playnext/', methods=('GET',), endpoint='get_next')
))

def __call__(self, environ, start_response):
Expand Down Expand Up @@ -653,6 +654,26 @@ def on_play_next(self, request):

return JSONResponse({'status': 'OK'})

def on_get_next(self, request):
resp = {'status': 'OK', 'next': False}

with open(os.path.join(self.data_dir, 'prio.m3u'), 'r') as f:
if f.mode == 'r':
contents = f.read().strip()
if contents:
_, ext = os.path.splitext(contents)
changes = mutagen_tag_analyzer(
'prio.m3u',
None,
ext,
open(os.path.join(self.data_dir, contents), 'rb')
)
for change in changes:
if isinstance(change, MetadataChange):
resp[change.key] = change.value
resp['next'] = True
return JSONResponse(resp)


class JSONResponse(Response):
"""
Expand Down

0 comments on commit 91b28f0

Please sign in to comment.