updated with less debugging
This commit is contained in:
parent
51afbf5627
commit
833b0d37b6
1 changed files with 76 additions and 45 deletions
|
|
@ -1,80 +1,111 @@
|
||||||
from config import *
|
from config import *
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
# import requests
|
||||||
|
# import json
|
||||||
|
# from config import *
|
||||||
|
|
||||||
# def lidarr_api_add_artist(mbid):
|
# def lidarr_api_add_artist(mbid):
|
||||||
# lookup_url = f"{LIDARR_URL}/api/v1/artist/lookup?term=mbid:{mbid}"
|
# lookup_url = f"{LIDARR_URL}/api/v1/artist/lookup?term=mbid:{mbid}"
|
||||||
# headers = {"X-Api-Key": LIDARR_API_KEY, "Content-Type": "application/json"}
|
# headers = {"X-Api-Key": LIDARR_API_KEY, "Content-Type": "application/json"}
|
||||||
|
|
||||||
# res = requests.get(lookup_url, headers=headers)
|
# try:
|
||||||
# if not res.ok or not res.json():
|
# res = requests.get(lookup_url, headers=headers)
|
||||||
|
# res.raise_for_status()
|
||||||
|
# artists = res.json()
|
||||||
|
|
||||||
|
# if not artists:
|
||||||
|
# print(f"[LIDARR DEBUG] Ingen artist hittades för MBID {mbid}")
|
||||||
|
# return False
|
||||||
|
|
||||||
|
# artist = artists[0]
|
||||||
|
# print(f"[LIDARR DEBUG] Artist hittad: {artist['artistName']} (MBID: {mbid})")
|
||||||
|
|
||||||
|
# # Bygg payload från lookup-objektet
|
||||||
|
# payload = artist.copy()
|
||||||
|
# payload.update({
|
||||||
|
# "monitored": True,
|
||||||
|
# "qualityProfileId": QUALITY_PROFILE_ID,
|
||||||
|
# "metadataProfileId": 1,
|
||||||
|
# "rootFolderPath": ROOT_FOLDER_PATH,
|
||||||
|
# "addOptions": {
|
||||||
|
# "monitor": "all", # Bevakning av alla album
|
||||||
|
# "searchForMissingAlbums": True
|
||||||
|
# }
|
||||||
|
# })
|
||||||
|
|
||||||
|
# add_url = f"{LIDARR_URL}/api/v1/artist"
|
||||||
|
# print(f"[LIDARR DEBUG] Payload: {json.dumps(payload, indent=2)}")
|
||||||
|
# post_res = requests.post(add_url, headers=headers, json=payload)
|
||||||
|
# post_res.raise_for_status()
|
||||||
|
|
||||||
|
# print(f"[LIDARR DEBUG] Lyckades lägga till: {artist['artistName']}")
|
||||||
|
# return True
|
||||||
|
|
||||||
|
# except requests.exceptions.HTTPError as http_err:
|
||||||
|
# print(f"[LIDARR ERROR] HTTP-fel vid tillägg av MBID {mbid}: {http_err}")
|
||||||
|
# if http_err.response is not None:
|
||||||
|
# print(f"[LIDARR ERROR] Svar från servern: {http_err.response.text}")
|
||||||
|
# return False
|
||||||
|
# except Exception as e:
|
||||||
|
# print(f"[LIDARR ERROR] Annat fel vid tillägg av MBID {mbid}: {e}")
|
||||||
# return False
|
# return False
|
||||||
|
|
||||||
# artist = res.json()[0]
|
from config import *
|
||||||
# payload = {
|
|
||||||
# "foreignArtistId": artist['foreignArtistId'],
|
|
||||||
# "artistName": artist['artistName'],
|
|
||||||
# "monitored": True,
|
|
||||||
# "qualityProfileId": QUALITY_PROFILE_ID,
|
|
||||||
# "metadataProfileId": 1,
|
|
||||||
# "rootFolderPath": ROOT_FOLDER,
|
|
||||||
# "addOptions": {
|
|
||||||
# "monitor": "all",
|
|
||||||
# "searchForMissingAlbums": True
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
|
|
||||||
# add_url = f"{LIDARR_URL}/api/v1/artist"
|
|
||||||
# post_res = requests.post(add_url, headers=headers, json=payload)
|
|
||||||
# return post_res.ok
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
from config import *
|
|
||||||
|
|
||||||
def lidarr_api_add_artist(mbid):
|
def lidarr_api_add_artist(mbid, verbose=False):
|
||||||
lookup_url = f"{LIDARR_URL}/api/v1/artist/lookup?term=mbid:{mbid}"
|
lookup_url = f"{LIDARR_URL}/api/v1/artist/lookup?term=mbid:{mbid}"
|
||||||
headers = {"X-Api-Key": LIDARR_API_KEY, "Content-Type": "application/json"}
|
headers = {"X-Api-Key": LIDARR_API_KEY}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = requests.get(lookup_url, headers=headers)
|
res = requests.get(lookup_url, headers=headers)
|
||||||
res.raise_for_status()
|
res.raise_for_status()
|
||||||
artists = res.json()
|
data = res.json()
|
||||||
|
|
||||||
if not artists:
|
if not data:
|
||||||
print(f"[LIDARR DEBUG] Ingen artist hittades för MBID {mbid}")
|
if verbose:
|
||||||
|
print(f"[LIDARR] Ingen artist hittades för MBID {mbid}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
artist = artists[0]
|
artist = data[0]
|
||||||
print(f"[LIDARR DEBUG] Artist hittad: {artist['artistName']} (MBID: {mbid})")
|
payload = {
|
||||||
|
"foreignArtistId": mbid,
|
||||||
# Bygg payload från lookup-objektet
|
"artistName": artist["artistName"],
|
||||||
payload = artist.copy()
|
|
||||||
payload.update({
|
|
||||||
"monitored": True,
|
"monitored": True,
|
||||||
"qualityProfileId": QUALITY_PROFILE_ID,
|
"qualityProfileId": QUALITY_PROFILE_ID,
|
||||||
"metadataProfileId": 1,
|
"metadataProfileId": 1,
|
||||||
"rootFolderPath": ROOT_FOLDER_PATH,
|
"rootFolderPath": ROOT_FOLDER_PATH,
|
||||||
"addOptions": {
|
"addOptions": {
|
||||||
"monitor": "all", # Bevakning av alla album
|
"monitor": "all",
|
||||||
"searchForMissingAlbums": True
|
"searchForMissingAlbums": True
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
print(f"[LIDARR] Försöker lägga till: {artist['artistName']}")
|
||||||
|
|
||||||
add_url = f"{LIDARR_URL}/api/v1/artist"
|
add_url = f"{LIDARR_URL}/api/v1/artist"
|
||||||
print(f"[LIDARR DEBUG] Payload: {json.dumps(payload, indent=2)}")
|
res = requests.post(add_url, headers=headers, json=payload)
|
||||||
post_res = requests.post(add_url, headers=headers, json=payload)
|
|
||||||
post_res.raise_for_status()
|
|
||||||
|
|
||||||
print(f"[LIDARR DEBUG] Lyckades lägga till: {artist['artistName']}")
|
if res.status_code == 400:
|
||||||
|
errors = res.json()
|
||||||
|
for err in errors:
|
||||||
|
if err.get("errorCode") == "ArtistExistsValidator":
|
||||||
|
print(f"[LIDARR] {artist['artistName']} finns redan.")
|
||||||
|
return False
|
||||||
|
if err.get("errorCode") == "RootFolderExistsValidator":
|
||||||
|
print(f"[LIDARR] Fel: Angiven rotmapp finns inte: {ROOT_FOLDER_PATH}")
|
||||||
|
return False
|
||||||
|
print(f"[LIDARR] Fel: {res.text}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
res.raise_for_status()
|
||||||
|
|
||||||
|
print(f"[LIDARR] ✅ Tillagd: {artist['artistName']}")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except requests.exceptions.HTTPError as http_err:
|
|
||||||
print(f"[LIDARR ERROR] HTTP-fel vid tillägg av MBID {mbid}: {http_err}")
|
|
||||||
if http_err.response is not None:
|
|
||||||
print(f"[LIDARR ERROR] Svar från servern: {http_err.response.text}")
|
|
||||||
return False
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[LIDARR ERROR] Annat fel vid tillägg av MBID {mbid}: {e}")
|
print(f"[LIDARR] ❌ Fel vid MBID {mbid}: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue