lidarr_empty_folders.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. # Lidarr has trouble moving Music without a pre-existing artist folder.
  2. #
  3. # */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
  4. # Or run it in a k8s cronjob. See lidarr-empty-folders.yaml
  5. # kubectl -n plex create configmap lidarr-empty-folders --from-file=lidarr_empty_folders.py
  6. import requests
  7. from requests.adapters import HTTPAdapter, Retry
  8. import os
  9. import sys
  10. if len(sys.argv) != 4:
  11. print("One or more args are undefined")
  12. sys.exit(1)
  13. lidarr_server, lidarr_api_key, music_folder = sys.argv[1:4]
  14. retries = Retry(total=10,
  15. backoff_factor=1,
  16. status_forcelist=[ 500, 502, 503, 504 ])
  17. s = requests.Session()
  18. s.mount('http://', HTTPAdapter(max_retries=retries))
  19. resp = s.get(
  20. f"{lidarr_server}/api/v1/artist",
  21. headers={"Authorization": f"Bearer {lidarr_api_key}"}
  22. )
  23. artists = resp.json()
  24. for artist in artists:
  25. artist_name = artist.get("artistName")
  26. artist_path = music_folder + artist_name
  27. if ('/' not in artist_name) and (not os.path.exists(artist_path)):
  28. print("Creating ", artist_path)
  29. os.mkdir(artist_path)