Integrate React frontend with backend API
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
from typing import List
|
||||
from datetime import datetime
|
||||
from app.utils.logger import logger
|
||||
|
||||
def load_local_playlist(playlist_path: str) -> List[str]:
|
||||
@@ -42,7 +43,9 @@ def scan_local_playlists(base_path: str) -> list[dict]:
|
||||
base_path: Directory that contains playlist files.
|
||||
|
||||
Returns:
|
||||
A list of dictionaries with ``name`` and ``track_count`` keys.
|
||||
A list of dictionaries with ``name`` and ``track_count`` keys, and
|
||||
additional metadata (``path`` and ``last_modified``) for richer API
|
||||
responses.
|
||||
"""
|
||||
|
||||
playlists: list[dict] = []
|
||||
@@ -61,7 +64,15 @@ def scan_local_playlists(base_path: str) -> list[dict]:
|
||||
if not entry.name.lower().endswith((".m3u", ".m3u8")):
|
||||
continue
|
||||
tracks = load_local_playlist(entry.path)
|
||||
playlists.append({"name": entry.name, "track_count": len(tracks)})
|
||||
last_modified = datetime.fromtimestamp(entry.stat().st_mtime)
|
||||
playlists.append(
|
||||
{
|
||||
"name": entry.name,
|
||||
"track_count": len(tracks),
|
||||
"path": entry.path,
|
||||
"last_modified": last_modified.isoformat(),
|
||||
}
|
||||
)
|
||||
|
||||
playlists.sort(key=lambda item: item["name"].lower())
|
||||
logger.info(f"Found {len(playlists)} playlists under {absolute_path}.")
|
||||
|
||||
Reference in New Issue
Block a user