Implement album deletion feature after metadata migration
- Added a new command-line argument `--delete` to allow users to delete single albums after successful metadata migration. - Integrated the `unmonitor_and_delete_album` function to handle the deletion process for albums that meet the migration criteria. - Enhanced the `migrate_plex_metadata` function to support exclusion of smart playlists during migration. - Updated logging to provide detailed feedback on the deletion process and migration results.
This commit is contained in:
49
src-cleanup/lidarr_delete.py
Normal file
49
src-cleanup/lidarr_delete.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""Lidarr album deletion functions"""
|
||||
|
||||
import logging
|
||||
from typing import Dict
|
||||
|
||||
import requests
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def unmonitor_and_delete_album(
|
||||
base_url: str, headers: Dict[str, str], album_id: int
|
||||
) -> bool:
|
||||
"""Unmonitor and delete an album from Lidarr. Returns success status."""
|
||||
try:
|
||||
# First unmonitor the album
|
||||
logger.debug(f"Unmonitoring album {album_id}...")
|
||||
album_resp = requests.get(
|
||||
f"{base_url.rstrip('/')}/api/v1/album/{album_id}",
|
||||
headers=headers,
|
||||
timeout=30,
|
||||
)
|
||||
album_resp.raise_for_status()
|
||||
album_data = album_resp.json()
|
||||
|
||||
album_data["monitored"] = False
|
||||
|
||||
update_resp = requests.put(
|
||||
f"{base_url.rstrip('/')}/api/v1/album/{album_id}",
|
||||
headers=headers,
|
||||
json=album_data,
|
||||
timeout=30,
|
||||
)
|
||||
update_resp.raise_for_status()
|
||||
|
||||
# Then delete the album (deleteFiles=true to remove files, addImportListExclusion=false)
|
||||
logger.debug(f"Deleting album {album_id}...")
|
||||
delete_resp = requests.delete(
|
||||
f"{base_url.rstrip('/')}/api/v1/album/{album_id}",
|
||||
headers=headers,
|
||||
params={"deleteFiles": "true", "addImportListExclusion": "false"},
|
||||
timeout=30,
|
||||
)
|
||||
delete_resp.raise_for_status()
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to delete album {album_id}: {e}")
|
||||
return False
|
||||
Reference in New Issue
Block a user