From 43233a528f34d44062be1b879c7c5e31bc23b40a Mon Sep 17 00:00:00 2001 From: ManifestFailure Date: Wed, 25 Oct 2023 18:10:36 +0800 Subject: [PATCH] Changed jellyfin API call Changed the jellyfin API call to get the admin user id to use for all subsequent requests. --- subgen/subgen.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/subgen/subgen.py b/subgen/subgen.py index 90ea874..3d71562 100644 --- a/subgen/subgen.py +++ b/subgen/subgen.py @@ -60,6 +60,7 @@ def convert_to_bool(in_bool): model_location = os.getenv('MODEL_PATH', '.') if transcribe_device == "gpu": transcribe_device = "cuda" +jellyfin_userid = "" app = Flask(__name__) model = stable_whisper.load_faster_whisper(whisper_model, download_root=model_location, device=transcribe_device, cpu_threads=whisper_threads, num_workers=concurrent_transcriptions) @@ -244,9 +245,17 @@ def get_jellyfin_file_name(item_id: str, jellyfin_url: str, jellyfin_token: str) "Authorization": f"MediaBrowser Token={jellyfin_token}", } - # This is super hacky to pull the first userid from this file to use to make the next call, API appears to fail using only Items/{item_id} - userid = json.loads(requests.get(f"{jellyfin_url}/Users", headers=headers).content)[0]['Id'] - response = requests.get(f"{jellyfin_url}/Users/{userid}/Items/{item_id}", headers=headers) + # Cheap way to get the admin user id, and save it for later use. + if not jellyfin_userid: + users_request = json.loads(requests.get(f"{jellyfin_url}/Users", headers=headers).content) + for user in users_request: + if user['Policy']['IsAdministrator']: + jellyfin_userid = user['Id'] + break + if not jellyfin_userid: + raise Exception("Unable to find administrator user in Jellyfin") + + response = requests.get(f"{jellyfin_url}/Users/{jellyfin_userid}/Items/{item_id}", headers=headers) if response.status_code == 200: json_data = json.loads(response.content)