now works
This commit is contained in:
parent
5cb14ef425
commit
51afbf5627
2 changed files with 30 additions and 15 deletions
|
|
@ -4,10 +4,10 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print("⚠️ Du måste skapa en config_local.py med dina API-nycklar.")
|
print("⚠️ Du måste skapa en config_local.py med dina API-nycklar.")
|
||||||
|
|
||||||
ROOT_FOLDER = "/media/music2"
|
ROOT_FOLDER_PATH = "/data/media/music2"
|
||||||
QUALITY_PROFILE_ID = 1
|
QUALITY_PROFILE_ID = 1
|
||||||
|
|
||||||
MIN_PLAYS = 15
|
MIN_PLAYS = 3
|
||||||
RECENT_MONTHS = 3
|
RECENT_MONTHS = 3
|
||||||
MAX_SIMILAR_PER_ART = 20
|
MAX_SIMILAR_PER_ART = 20
|
||||||
SIMILAR_MATCH_MIN = 0.5
|
SIMILAR_MATCH_MIN = 0.5
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
from config import *
|
from config import *
|
||||||
import requests
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
# 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}"
|
||||||
|
|
@ -27,39 +28,53 @@ import requests
|
||||||
# post_res = requests.post(add_url, headers=headers, json=payload)
|
# post_res = requests.post(add_url, headers=headers, json=payload)
|
||||||
# return post_res.ok
|
# return post_res.ok
|
||||||
|
|
||||||
|
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}
|
headers = {"X-Api-Key": LIDARR_API_KEY, "Content-Type": "application/json"}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = requests.get(lookup_url, headers=headers)
|
res = requests.get(lookup_url, headers=headers)
|
||||||
res.raise_for_status()
|
res.raise_for_status()
|
||||||
data = res.json()
|
artists = res.json()
|
||||||
|
|
||||||
if not data:
|
if not artists:
|
||||||
print(f"[LIDARR DEBUG] Ingen artist hittades för MBID {mbid}")
|
print(f"[LIDARR DEBUG] Ingen artist hittades för MBID {mbid}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
artist = data[0]
|
artist = artists[0]
|
||||||
print(f"[LIDARR DEBUG] Artist hittad: {artist['artistName']} (MBID: {mbid})")
|
print(f"[LIDARR DEBUG] Artist hittad: {artist['artistName']} (MBID: {mbid})")
|
||||||
|
|
||||||
payload = {
|
# Bygg payload från lookup-objektet
|
||||||
"foreignArtistId": mbid,
|
payload = artist.copy()
|
||||||
|
payload.update({
|
||||||
"monitored": True,
|
"monitored": True,
|
||||||
"qualityProfileId": 1,
|
"qualityProfileId": QUALITY_PROFILE_ID,
|
||||||
"metadataProfileId": 1,
|
"metadataProfileId": 1,
|
||||||
"rootFolderPath": ROOT_FOLDER_PATH,
|
"rootFolderPath": ROOT_FOLDER_PATH,
|
||||||
"addOptions": {
|
"addOptions": {
|
||||||
|
"monitor": "all", # Bevakning av alla album
|
||||||
"searchForMissingAlbums": True
|
"searchForMissingAlbums": True
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
add_url = f"{LIDARR_URL}/api/v1/artist"
|
add_url = f"{LIDARR_URL}/api/v1/artist"
|
||||||
res = requests.post(add_url, headers=headers, json=payload)
|
print(f"[LIDARR DEBUG] Payload: {json.dumps(payload, indent=2)}")
|
||||||
res.raise_for_status()
|
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']}")
|
print(f"[LIDARR DEBUG] Lyckades lägga till: {artist['artistName']}")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except Exception as e:
|
except requests.exceptions.HTTPError as http_err:
|
||||||
print(f"[LIDARR ERROR] Kunde inte lägga till MBID {mbid}: {e}")
|
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
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[LIDARR ERROR] Annat fel vid tillägg av MBID {mbid}: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue