feat: api endpoint to get playlist properties
Some checks failed
Build RPi Pico firmware image / Build-Firmware (push) Successful in 4m36s
Check code formatting / Check-C-Format (push) Successful in 7s
Check code formatting / Check-Python-Flake8 (push) Failing after 9s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 4s
Run unit tests on host / Run-Unit-Tests (push) Successful in 7s
Run pytests / Check-Pytest (push) Successful in 10s

This commit is contained in:
2025-12-20 16:52:37 +01:00
parent 070cf887ab
commit e2ca9e5139

View File

@@ -4,6 +4,7 @@ Copyright (c) 2024-2025 Stefan Kratochwil <Kratochwil-LA@gmx.de>
'''
import asyncio
import json
import os
from microdot import Microdot
@@ -86,27 +87,27 @@ def is_hex(s):
return all(c in hex_chars for c in s)
fsroot = b'/sd'
@webapp.route('/api/v1/playlist/<tag>', methods=['GET'])
async def playlist_get(request, tag):
if not is_hex(tag):
return 'invalid tag', 400
playlist = playlist_db.getPlaylistForTag(tag.encode())
paths = []
if playlist is not None:
for path in playlist.getPaths():
paths.append({'path': path})
# empty paths are okay, tag might be know, but playlist may be empty
return paths
return {
'shuffle': playlist.__dict__.get('shuffle'),
'persist': playlist.__dict__.get('persist'),
'paths': [(p[len(fsroot):] if p.startswith(fsroot) else p).decode()
for p in playlist.getPaths()],
}
@webapp.route('/api/v1/audiofiles', methods=['GET'])
async def audiofiles_get(request):
root = b'/sd'
audiofiles = set()
dirstack = [root]
dirstack = [fsroot]
while dirstack:
current_dir = dirstack.pop()
@@ -118,6 +119,6 @@ async def audiofiles_get(request):
dirstack.append(current_path)
elif type_ == 0x8000:
if name.lower().endswith('.mp3'):
audiofiles.add(current_path[len(root):])
audiofiles.add(current_path[len(fsroot):])
return sorted(audiofiles)