diff --git a/software/src/app.py b/software/src/app.py index c83c236..ee565b5 100644 --- a/software/src/app.py +++ b/software/src/app.py @@ -193,3 +193,6 @@ class PlayerApp: def get_nfc(self): return self.nfc + + def get_playlist_db(self): + return self.playlist_db diff --git a/software/src/utils/playlistdb.py b/software/src/utils/playlistdb.py index a8c866c..649be86 100644 --- a/software/src/utils/playlistdb.py +++ b/software/src/utils/playlistdb.py @@ -251,6 +251,16 @@ class BTreeDB(IPlaylistDB): if flush: self._flush() + def getPlaylistTags(self): + """ + Get a keys-only dict of all defined playlists. Playlists currently do not have names, but are identified by + their tag. + """ + playlist_tags = set() + for item in self.db: + playlist_tags.add(item.split(b'/')[0]) + return playlist_tags + def getPlaylistForTag(self, tag: bytes): """ Lookup the playlist for 'tag' and return the Playlist object. Return None if no playlist exists for the given diff --git a/software/src/webserver.py b/software/src/webserver.py index ca4d658..6e3b4cf 100644 --- a/software/src/webserver.py +++ b/software/src/webserver.py @@ -12,14 +12,15 @@ server = None config = None app = None nfc = None - +playlist_db = None def start_webserver(config_, app_): - global server, config, app, nfc + global server, config, app, nfc, playlist_db server = asyncio.create_task(webapp.start_server(port=80)) config = config_ app = app_ nfc = app.get_nfc() + playlist_db = app.get_playlist_db() @webapp.before_request @@ -72,3 +73,8 @@ async def config_put(request): async def last_tag_uid_get(request): tag, _ = nfc.get_last_uid() return {'tag': tag} + + +@webapp.route('/api/v1/playlists', methods=['GET']) +async def playlists_get(request): + return sorted(playlist_db.getPlaylistTags())