load local playlist.
cache plex tracks.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
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 []
|
||||
Reference in New Issue
Block a user