Files
PlexPlaylistSync/app/utils/local_playlist.py
T
Koha9 93cc72d612 load local playlist.
cache plex tracks.
2025-07-23 22:38:51 +09:00

34 lines
1.1 KiB
Python

from typing import List
from app.utils.logger import logger
def load_local_playlist(playlist_path: str) -> List[str]:
"""
Load a local playlist from a m3u or m3u8 file.
Skip # comments and empty lines.
Args:
playlist_path (str): The path to the playlist file.
Returns:
list: A list of songs in the playlist.
"""
try:
result = []
with open(playlist_path, 'r', encoding="utf-8") as file:
for line in file:
line = line.strip()
if not line:
# Skip empty lines
continue
if line.startswith('#'):
# Skip comments
continue
result.append(line)
logger.info(f"Loaded {len(result)} songs from the playlist: {playlist_path}")
return result
except FileNotFoundError:
logger.error(f"Error: The file {playlist_path} does not exist.")
return []
except Exception as e:
logger.error(f"An error occurred while loading the playlist: {e}")
return []