Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions stopes/ui/seamlisten/backend/app/fileviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pathlib import Path

import torchaudio
from fastapi import APIRouter
from fastapi import APIRouter, Body
from fastapi.exceptions import HTTPException
from fastapi.responses import JSONResponse, Response

Expand All @@ -21,7 +21,7 @@

from .query_types import AnnotationQuery, AudioQuery, DefaultQuery, LineQuery

torchaudio.set_audio_backend("sox_io")
torchaudio.set_audio_backend("soundfile")

router = APIRouter(tags=["fileviewer"])

Expand Down Expand Up @@ -161,3 +161,32 @@ async def general_query(query: DefaultQuery) -> Response:
a line with audio file, start and end timestamps
""",
)


@router.post("/fetchFolders/")
def gather_folder_contents(folder_path: str = Body(...), max_depth: int = Body(5)):
def gather_contents_recursive(folder_path, current_depth):
if current_depth > max_depth:
return {
"folder": str(folder_path),
"subfolders": None,
"audio_files": None,
"unexplored": True,
}
subfolders = []
audio_files = []

for entry in folder_path.iterdir():
if entry.is_dir():
subfolders.append(gather_contents_recursive(entry, current_depth + 1))
elif entry.suffix in {".wav", ".ms"}:
audio_files.append(entry.name)

return {
"folder": str(folder_path),
"subfolders": subfolders if subfolders else None,
"audio_files": audio_files if audio_files else None,
"unexplored": False,
}

return gather_contents_recursive(Path(folder_path), 1)
2 changes: 1 addition & 1 deletion stopes/ui/seamlisten/backend/dev.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PORT=8000
PORT=8080
DEV_MODE=True
Loading