lidarr_empty_folders.py 761 B

1234567891011121314151617181920212223
  1. # */1 * * * * /usr/bin/run-one /usr/bin/python3 /path/to/lidarr_empty_folders.py <lidarr IP>:8686 <API key> /path/to/Music/ 2>&1 | /usr/bin/logger -t lidarr_empty_folders
  2. import requests
  3. import os
  4. import sys
  5. if len(sys.argv) != 4:
  6. print("One or more args are undefined")
  7. sys.exit(1)
  8. lidarr_server, lidarr_api_key, music_folder = sys.argv[1:4]
  9. resp = requests.get(
  10. f"http://{lidarr_server}/api/v1/artist",
  11. headers={"Authorization": f"Bearer {lidarr_api_key}"}
  12. )
  13. artists = resp.json()
  14. for artist in artists:
  15. artist_name = artist.get("artistName")
  16. artist_path = music_folder + artist_name
  17. if ('/' not in artist_name) and (not os.path.exists(artist_path)):
  18. print("Creating ", artist_path)
  19. os.mkdir(artist_path)