feat: Implement playlist synchronization result writeback functionality.
This commit is contained in:
@@ -65,4 +65,48 @@ def scan_local_playlists(base_path: str) -> list[dict]:
|
||||
|
||||
playlists.sort(key=lambda item: item["name"].lower())
|
||||
logger.info(f"Found {len(playlists)} playlists under {absolute_path}.")
|
||||
return playlists
|
||||
return playlists
|
||||
def write_local_playlist(playlist_path: str, tracks: List[str]) -> bool:
|
||||
"""
|
||||
Write a list of tracks to a local playlist file.
|
||||
|
||||
Args:
|
||||
playlist_path (str): The path to the playlist file.
|
||||
tracks (list): A list of songs to write to the playlist.
|
||||
|
||||
Returns:
|
||||
bool: True if successful, False otherwise.
|
||||
"""
|
||||
try:
|
||||
with open(playlist_path, 'w', encoding="utf-8") as file:
|
||||
file.write("#EXTM3U\n")
|
||||
for track in tracks:
|
||||
file.write(f"{track}\n")
|
||||
logger.info(f"Written {len(tracks)} songs to the playlist: {playlist_path}")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred while writing the playlist {playlist_path}: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def delete_local_playlist(playlist_path: str) -> bool:
|
||||
"""
|
||||
Delete a local playlist file.
|
||||
|
||||
Args:
|
||||
playlist_path (str): The path to the playlist file.
|
||||
|
||||
Returns:
|
||||
bool: True if successful, False otherwise.
|
||||
"""
|
||||
try:
|
||||
if os.path.exists(playlist_path):
|
||||
os.remove(playlist_path)
|
||||
logger.info(f"Deleted playlist: {playlist_path}")
|
||||
return True
|
||||
else:
|
||||
logger.warning(f"Playlist not found for deletion: {playlist_path}")
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred while deleting the playlist {playlist_path}: {e}")
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user