From b1ed46c64e689e0f22f1e94018a17f5c129d82a3 Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Wed, 31 Jan 2024 08:43:29 -0500 Subject: initial commit --- jellystack_lib.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 jellystack_lib.py (limited to 'jellystack_lib.py') diff --git a/jellystack_lib.py b/jellystack_lib.py new file mode 100644 index 0000000..194cfe2 --- /dev/null +++ b/jellystack_lib.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 +# File: jellystack_lib.py +# Location: /mnt/public/Support/Programs/jellyfin/scripts/ +# Author: bgstack15 +# Startdate: 2024-01-20-7 13:59 +# SPDX-License-Identifier: GPL-3.0-only +# Title: jellyfin stackrpms library +# Project: jellystack +# Purpose: Useful functions that use python3 jellyfin apiclient +# History: +# 2024-01 started for listing/rescanning libraries +# Usage: +# in jellystack.py +# client.auth.login("vm4:8096","admin","0EXAMPLE0f93EXAMPLEXAMPLE534e0f6") +# Reference: +# from firefox devtools: +# curl 'https://albion320.no-ip.biz:500/Items/14895ee3d991844aee62d94dd46dfb7a/Refresh?Recursive=true&ImageRefreshMode=Default&MetadataRefreshMode=Default&ReplaceAllImages=false&ReplaceAllMetadata=false' -X POST -H 'X-Emby-Authorization: MediaBrowser Client="Jellyfin Web", Device="Firefox", DeviceId="TW96aWxsYS81LjAgKFgxMTsgTGlEXAMPLEg2XzY0OyBydjo5MS4wKSBHZWNEXAMPLEEwMDEwMSBGaXJlZm94LzkxLjB8MTYzODk3NjExMzkwMA11", Version="10.8.10", Token="0f6f671c4eEXAMPLEc219aEXAMPLE7b3" -H 'Content-Length: 0' +# Improve: +# Dependencies: +# req-devuan: jellyfin-apiclient-python + +from jellyfin_apiclient_python import JellyfinClient +import json, os + +def get_authenticated_client(url = "http://vm4:8096", username = "admin", password = "None"): + client = JellyfinClient() + # this one works basically, but somehow my previous attempt did not. + client.config.app('cli','0.0.1','any-ssh-node','a56decad32c0aefd696a7d3565ac1d0') + client.config.data["auth.ssl"] = False + client.auth.connect_to_address(url) + client.auth.login(url,username,password) + credentials = client.auth.credentials.get_credentials() + server = credentials["Servers"][0] + server["username"] = 'username' + json.dumps(server) + #json.loads(credentials) + #client.authenticate({"Servers": [credentials]}, discover=False) + return client + +def get_media_folders(client): + results = client.jellyfin.get_media_folders()["Items"] + libraries = [{"Name":i["Name"],"Id":i["Id"]} for i in results] + return libraries + +def libraries_to_csv(libraries): + for i in libraries: + print(f"\"{i['Name']}\" {i['Id']}") + +def get_library_names_only(libraries): + return [i["Name"] for i in libraries] + +def refresh_library(library, libraries, client): + # find id of given library + _use_id = "" + for i in libraries: + if i["Id"] == library: + _use_id = library + break + elif i["Name"] == library: + _use_id = i["Id"] + break + # if not found, fail out + if _use_id == "": + raise f"Unable to find which library, given {library}" + print(f"Will try to refresh library {_use_id}") + client.http.request( + { + "type": "POST", + "url": f"{client.config.data['auth.server']}/Items/{_use_id}/Refresh?Recursive=true&ImageRefreshMode=Default&MetadataRefreshMode=Default&ReplaceAllImages=false&ReplaceAllMetadata=false" + } + ) -- cgit