wip: api endpoint to list all available audio files
Some checks failed
Build RPi Pico firmware image / Build-Firmware (push) Successful in 4m38s
Check code formatting / Check-C-Format (push) Successful in 8s
Check code formatting / Check-Python-Flake8 (push) Failing after 9s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 5s
Run unit tests on host / Run-Unit-Tests (push) Successful in 8s
Run pytests / Check-Pytest (push) Successful in 11s
Some checks failed
Build RPi Pico firmware image / Build-Firmware (push) Successful in 4m38s
Check code formatting / Check-C-Format (push) Successful in 8s
Check code formatting / Check-Python-Flake8 (push) Failing after 9s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 5s
Run unit tests on host / Run-Unit-Tests (push) Successful in 8s
Run pytests / Check-Pytest (push) Successful in 11s
Iterative approach. Currently only lists mp3 files.
This commit is contained in:
@@ -4,6 +4,7 @@ Copyright (c) 2024-2025 Stefan Kratochwil <Kratochwil-LA@gmx.de>
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
from microdot import Microdot
|
from microdot import Microdot
|
||||||
|
|
||||||
@@ -78,3 +79,24 @@ async def last_tag_uid_get(request):
|
|||||||
@webapp.route('/api/v1/playlists', methods=['GET'])
|
@webapp.route('/api/v1/playlists', methods=['GET'])
|
||||||
async def playlists_get(request):
|
async def playlists_get(request):
|
||||||
return sorted(playlist_db.getPlaylistTags())
|
return sorted(playlist_db.getPlaylistTags())
|
||||||
|
|
||||||
|
|
||||||
|
@webapp.route('/api/v1/audiofiles', methods=['GET'])
|
||||||
|
async def audiofiles_get(request):
|
||||||
|
audiofiles = set()
|
||||||
|
dirstack = [b'/sd']
|
||||||
|
|
||||||
|
while dirstack:
|
||||||
|
current_dir = dirstack.pop()
|
||||||
|
print(dirstack, current_dir)
|
||||||
|
for entry in os.ilistdir(current_dir):
|
||||||
|
name = entry[0]
|
||||||
|
type_ = entry[1]
|
||||||
|
current_path = current_dir + '/' + name
|
||||||
|
if type_ == 0x4000:
|
||||||
|
dirstack.append(current_path)
|
||||||
|
elif type_ == 0x8000:
|
||||||
|
if name.lower().endswith('.mp3'):
|
||||||
|
audiofiles.add(current_path)
|
||||||
|
|
||||||
|
return sorted(audiofiles)
|
||||||
|
|||||||
Reference in New Issue
Block a user