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
* itsdangerous
* passlib
* configparser
* pyOpenSSL
* waitress
* pytz

View File

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

View File

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

View File

@ -66,6 +66,8 @@ if not success:
log.error("Could not authenticate after 3 tries.")
exit()
# Temporary fixes below.
def switchToIds():
try:
@ -101,6 +103,22 @@ def switchToIds():
# Temporary, switches emails.json over from using Usernames to User IDs.
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"):
validator = PasswordValidator(
config["password_validation"]["min_length"],