Advertisement
Guest User

Unmonitor compilations

a guest
Mar 14th, 2025
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.27 KB | Music | 0 0
  1. import requests
  2. import json
  3.  
  4. # Set the base URL for your Lidarr instance and the API key
  5. LIDARR_URL = "http://localhost:8686"  # Change this if your Lidarr instance is hosted elsewhere
  6. API_KEY = "put your api key here"  # Replace this with your actual Lidarr API key
  7.  
  8. def unmonitor_album(artist_id):
  9.     try:
  10.         artist_details = requests.get(f"{LIDARR_URL}/api/v1/artist/{artist_id}?apikey={API_KEY}").json()
  11.         artist_name = artist_details.get("artistName")
  12.  
  13.         albums = requests.get(f"{LIDARR_URL}/api/v1/album?artistId={artist_id}&apikey={API_KEY}").json()
  14.  
  15.         for album in albums:
  16.             ids_to_unmonitor = []
  17.             if album.get("albumType") in ("Album", "EP") and any(secondary_type in album.get("secondaryTypes") for secondary_type in ["Compilation", "Live", "Remix"]) and album.get("monitored"):
  18.                 album_title = album.get("title")
  19.                 album_id = album.get("id")
  20.                
  21.                 ids_to_unmonitor.append(album_id)
  22.                
  23.                 try:
  24.                     # Prepare data to unmonitor
  25.                     payload = {"albumIds": ids_to_unmonitor, "monitored": False}
  26.                     headers = {"content-type": "application/json"}
  27.                     response = requests.put(f"{LIDARR_URL}/api/v1/album/monitor?apikey={API_KEY}", headers=headers, data=json.dumps(payload).encode("utf-8"))
  28.                     response.raise_for_status()  # Raise an error if the status code is not 200
  29.                     print(f"{artist_name}'s {album_title} with ID {album_id} has been unmonitored.")
  30.                 except requests.exceptions.RequestException as e:
  31.                     print(f"Error unmonitoring {album_title} with ID {album_id}: {e}")
  32.  
  33.     except requests.exceptions.RequestException as e:
  34.         print(f"Error for artist ID {artist_id}: {e}")
  35.        
  36. # Fetch all artist IDs from Lidarr
  37. artists = requests.get(f"{LIDARR_URL}/api/v1/artist?apikey={API_KEY}").json()
  38.  
  39. # Iterate through each artist and get the newest album release date for their albums of type "Album"
  40. print("Fetching albums for all artists...")
  41.  
  42. for artist in artists:
  43.     artist_id = artist.get("id")
  44.     print(f"Processing artist ID: {artist_id}")
  45.     unmonitor_album(artist_id)
  46.  
  47. print("Process completed.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement