moved some hard-coded stuff to config
This commit is contained in:
parent
40a0e680dd
commit
615a732c2b
2 changed files with 69 additions and 109 deletions
26
config.py
26
config.py
|
|
@ -1,15 +1,35 @@
|
||||||
# config.py
|
# # config.py
|
||||||
|
# try:
|
||||||
|
# from config_local import *
|
||||||
|
# except ImportError:
|
||||||
|
# print("⚠️ Du måste skapa en config_local.py med dina API-nycklar.")
|
||||||
|
|
||||||
|
# ROOT_FOLDER_PATH = "/data/media/music2"
|
||||||
|
# QUALITY_PROFILE_ID = 1
|
||||||
|
|
||||||
|
# MIN_PLAYS = 10
|
||||||
|
# RECENT_MONTHS = 3
|
||||||
|
# MAX_SIMILAR_PER_ART = 20
|
||||||
|
# SIMILAR_MATCH_MIN = 0.5
|
||||||
|
# CACHE_TTL_HOURS = 24
|
||||||
|
# DEBUG_PRINT = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from config_local import *
|
from config_local import *
|
||||||
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_PATH = "/data/media/music2"
|
ROOT_FOLDER_PATH = "/data/media/music2"
|
||||||
QUALITY_PROFILE_ID = 1
|
QUALITY_PROFILE_ID = 4
|
||||||
|
|
||||||
MIN_PLAYS = 10
|
MONITORED = True
|
||||||
|
MONITOR_NEW_ITEMS = "all"
|
||||||
|
SEARCH_FOR_MISSING_ALBUMS = True
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
CACHE_TTL_HOURS = 24
|
CACHE_TTL_HOURS = 24
|
||||||
DEBUG_PRINT = True
|
DEBUG_PRINT = True
|
||||||
|
|
|
||||||
|
|
@ -1,111 +1,51 @@
|
||||||
from config import *
|
|
||||||
import requests
|
import requests
|
||||||
import json
|
from config import (
|
||||||
# import requests
|
LIDARR_URL,
|
||||||
# import json
|
LIDARR_API_KEY,
|
||||||
# from config import *
|
ROOT_FOLDER_PATH,
|
||||||
|
QUALITY_PROFILE_ID,
|
||||||
|
MONITORED,
|
||||||
|
MONITOR_NEW_ITEMS,
|
||||||
|
SEARCH_FOR_MISSING_ALBUMS,
|
||||||
|
DEBUG_PRINT,
|
||||||
|
)
|
||||||
|
|
||||||
# def lidarr_api_add_artist(mbid):
|
def lidarr_add_artist(artist):
|
||||||
# lookup_url = f"{LIDARR_URL}/api/v1/artist/lookup?term=mbid:{mbid}"
|
|
||||||
# headers = {"X-Api-Key": LIDARR_API_KEY, "Content-Type": "application/json"}
|
|
||||||
|
|
||||||
# try:
|
|
||||||
# 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
|
|
||||||
|
|
||||||
from config import *
|
|
||||||
import requests
|
|
||||||
import json
|
|
||||||
|
|
||||||
def lidarr_api_add_artist(mbid, verbose=False):
|
|
||||||
lookup_url = f"{LIDARR_URL}/api/v1/artist/lookup?term=mbid:{mbid}"
|
|
||||||
headers = {"X-Api-Key": LIDARR_API_KEY}
|
|
||||||
|
|
||||||
try:
|
|
||||||
res = requests.get(lookup_url, headers=headers)
|
|
||||||
res.raise_for_status()
|
|
||||||
data = res.json()
|
|
||||||
|
|
||||||
if not data:
|
|
||||||
if verbose:
|
|
||||||
print(f"[LIDARR] Ingen artist hittades för MBID {mbid}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
artist = data[0]
|
|
||||||
payload = {
|
payload = {
|
||||||
"foreignArtistId": mbid,
|
|
||||||
"artistName": artist["artistName"],
|
"artistName": artist["artistName"],
|
||||||
"monitored": True,
|
"foreignArtistId": artist["foreignArtistId"],
|
||||||
|
"rootFolderPath": ROOT_FOLDER_PATH,
|
||||||
"qualityProfileId": QUALITY_PROFILE_ID,
|
"qualityProfileId": QUALITY_PROFILE_ID,
|
||||||
"metadataProfileId": 1,
|
"metadataProfileId": 1,
|
||||||
"rootFolderPath": ROOT_FOLDER_PATH,
|
"monitored": MONITORED,
|
||||||
|
"monitorNewItems": MONITOR_NEW_ITEMS,
|
||||||
"addOptions": {
|
"addOptions": {
|
||||||
"monitor": "all",
|
"monitor": MONITOR_NEW_ITEMS,
|
||||||
"searchForMissingAlbums": True
|
"searchForMissingAlbums": SEARCH_FOR_MISSING_ALBUMS
|
||||||
}
|
},
|
||||||
|
"artistType": artist.get("artistType", "Group"),
|
||||||
|
"disambiguation": artist.get("disambiguation", ""),
|
||||||
|
"overview": artist.get("overview", ""),
|
||||||
|
"images": artist.get("images", []),
|
||||||
|
"links": artist.get("links", []),
|
||||||
|
"folder": artist["folder"]
|
||||||
}
|
}
|
||||||
|
|
||||||
if verbose:
|
if DEBUG_PRINT:
|
||||||
print(f"[LIDARR] Försöker lägga till: {artist['artistName']}")
|
print(f"[LIDARR DEBUG] Artist hittad: {artist['artistName']} (MBID: {artist['foreignArtistId']})")
|
||||||
|
print(f"[LIDARR DEBUG] Payload: {payload}")
|
||||||
|
|
||||||
add_url = f"{LIDARR_URL}/api/v1/artist"
|
try:
|
||||||
res = requests.post(add_url, headers=headers, json=payload)
|
response = requests.post(
|
||||||
|
f"{LIDARR_URL}/api/v1/artist",
|
||||||
if res.status_code == 400:
|
headers={"X-Api-Key": LIDARR_API_KEY},
|
||||||
errors = res.json()
|
json=payload
|
||||||
for err in errors:
|
)
|
||||||
if err.get("errorCode") == "ArtistExistsValidator":
|
response.raise_for_status()
|
||||||
print(f"[LIDARR] {artist['artistName']} finns redan.")
|
return response.json()
|
||||||
return False
|
except requests.exceptions.HTTPError as e:
|
||||||
if err.get("errorCode") == "RootFolderExistsValidator":
|
print(f"[LIDARR ERROR] HTTP-fel vid tillägg av MBID {artist['foreignArtistId']}: {e}")
|
||||||
print(f"[LIDARR] Fel: Angiven rotmapp finns inte: {ROOT_FOLDER_PATH}")
|
if e.response is not None:
|
||||||
return False
|
print(f"[LIDARR ERROR] Svar från servern: {e.response.json()}")
|
||||||
print(f"[LIDARR] Fel: {res.text}")
|
return None
|
||||||
return False
|
|
||||||
|
|
||||||
res.raise_for_status()
|
|
||||||
|
|
||||||
print(f"[LIDARR] ✅ Tillagd: {artist['artistName']}")
|
|
||||||
return True
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"[LIDARR] ❌ Fel vid MBID {mbid}: {e}")
|
|
||||||
return False
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue