Add playlist overview homepage
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
from typing import List
|
||||
from app.utils.logger import logger
|
||||
|
||||
@@ -31,4 +32,37 @@ def load_local_playlist(playlist_path: str) -> List[str]:
|
||||
return []
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred while loading the playlist: {e}")
|
||||
return []
|
||||
return []
|
||||
|
||||
|
||||
def scan_local_playlists(base_path: str) -> list[dict]:
|
||||
"""Scan a directory for playlist files and return their basic info.
|
||||
|
||||
Args:
|
||||
base_path: Directory that contains playlist files.
|
||||
|
||||
Returns:
|
||||
A list of dictionaries with ``name`` and ``track_count`` keys.
|
||||
"""
|
||||
|
||||
playlists: list[dict] = []
|
||||
if not base_path:
|
||||
logger.warning("No base path provided for local playlists scan.")
|
||||
return playlists
|
||||
|
||||
absolute_path = os.path.abspath(base_path)
|
||||
if not os.path.isdir(absolute_path):
|
||||
logger.warning(f"Playlist path does not exist or is not a directory: {absolute_path}")
|
||||
return playlists
|
||||
|
||||
for entry in os.scandir(absolute_path):
|
||||
if not entry.is_file():
|
||||
continue
|
||||
if not entry.name.lower().endswith((".m3u", ".m3u8")):
|
||||
continue
|
||||
tracks = load_local_playlist(entry.path)
|
||||
playlists.append({"name": entry.name, "track_count": len(tracks)})
|
||||
|
||||
playlists.sort(key=lambda item: item["name"].lower())
|
||||
logger.info(f"Found {len(playlists)} playlists under {absolute_path}.")
|
||||
return playlists
|
||||
Reference in New Issue
Block a user