10.6.0 compatability, cleanup, removed dep

Automatically fixes '*ProviderId' in user templates for versions of
Jellyfin >= 10.6.0. Removed unnecessary configparser dependency, the one
actually used is part of python. jf_api now has an info attribute.
This commit is contained in:
Harvey Tindall 2020-06-27 15:38:51 +01:00
parent 24045034c8
commit 4809331502
4 changed files with 27 additions and 5 deletions

View File

@ -31,7 +31,6 @@ A basic account management system for [Jellyfin](https://github.com/jellyfin/jel
* requests * requests
* itsdangerous * itsdangerous
* passlib * passlib
* configparser
* pyOpenSSL * pyOpenSSL
* waitress * waitress
* pytz * pytz

View File

@ -79,6 +79,7 @@ class Jellyfin:
"User-Agent": self.useragent, "User-Agent": self.useragent,
"X-Emby-Authorization": self.auth, "X-Emby-Authorization": self.auth,
} }
self.info = requests.get(self.server + "/System/Info/Public").json()
def getUsers(self, username: str = "all", userId: str = "all", public: bool = True): def getUsers(self, username: str = "all", userId: str = "all", public: bool = True):
""" """
@ -114,16 +115,16 @@ class Jellyfin:
else: else:
try: try:
self.authenticate(self.username, self.password) self.authenticate(self.username, self.password)
return self.getUsers(username, id, public) return self.getUsers(username, userId, public)
except self.AuthenticationError: except self.AuthenticationError:
raise self.AuthenticationRequiredError raise self.AuthenticationRequiredError
else: else:
response = self.userCache response = self.userCache
else: else:
raise self.AuthenticationRequiredError raise self.AuthenticationRequiredError
if username == "all" and id == "all": if username == "all" and userId == "all":
return response return response
elif id == "all": elif userId == "all":
match = False match = False
for user in response: for user in response:
if user["Name"] == username: if user["Name"] == username:
@ -134,7 +135,7 @@ class Jellyfin:
else: else:
match = False match = False
for user in response: for user in response:
if user["Id"] == id: if user["Id"] == userId:
match = True match = True
return user return user
if not match: if not match:
@ -165,6 +166,9 @@ class Jellyfin:
self.auth += f"Version={self.version}" self.auth += f"Version={self.version}"
self.auth += f", Token={self.accessToken}" self.auth += f", Token={self.accessToken}"
self.header["X-Emby-Authorization"] = self.auth self.header["X-Emby-Authorization"] = self.auth
self.info = requests.get(
self.server + "/System/Info", headers=self.header
).json()
return True return True
else: else:
raise self.AuthenticationError raise self.AuthenticationError

View File

@ -1,6 +1,7 @@
specials = ['[', '@', '_', '!', '#', '$', '%', '^', '&', '*', '(', ')', specials = ['[', '@', '_', '!', '#', '$', '%', '^', '&', '*', '(', ')',
'<', '>', '?', '/', '\\', '|', '}', '{', '~', ':', ']'] '<', '>', '?', '/', '\\', '|', '}', '{', '~', ':', ']']
class PasswordValidator: class PasswordValidator:
def __init__(self, min_length, upper, lower, number, special): def __init__(self, min_length, upper, lower, number, special):
self.criteria = { self.criteria = {

View File

@ -66,6 +66,8 @@ if not success:
log.error("Could not authenticate after 3 tries.") log.error("Could not authenticate after 3 tries.")
exit() exit()
# Temporary fixes below.
def switchToIds(): def switchToIds():
try: try:
@ -101,6 +103,22 @@ def switchToIds():
# Temporary, switches emails.json over from using Usernames to User IDs. # Temporary, switches emails.json over from using Usernames to User IDs.
switchToIds() switchToIds()
from packaging import version
if (
version.parse(jf.info["Version"]) >= version.parse("10.6.0")
and bool(data_store.user_template) is not False
):
log.info("Updating user_template for Jellyfin >= 10.6.0")
data_store.user_template[
"AuthenticationProviderId"
] = "Jellyfin.Server.Implementations.Users.DefaultAuthenticationProvider"
data_store.user_template[
"PasswordResetProviderId"
] = "Jellyfin.Server.Implementations.Users.DefaultPasswordResetProvider"
if config.getboolean("password_validation", "enabled"): if config.getboolean("password_validation", "enabled"):
validator = PasswordValidator( validator = PasswordValidator(
config["password_validation"]["min_length"], config["password_validation"]["min_length"],