4
1
Fork 1

Update DirectoryGetter

This commit is contained in:
trueold89 2024-05-04 04:08:21 +03:00
parent 4f7b6de5a6
commit aeafc2db41
Signed by: trueold89
GPG Key ID: C122E85DD49E6B30
2 changed files with 18 additions and 5 deletions

View File

@ -15,7 +15,7 @@ class DirectoryGetter(object):
"""
@abstractmethod
def CheckAvailability(self) -> bool:
def validation(self) -> bool:
"""
Checks if the directory parsing method is available
:return: boolean check result
@ -26,12 +26,14 @@ class Jellyfin(DirectoryGetter):
def __init__(self, url: str, api_key: str) -> None:
self.url = url
self.api_key = api_key
if self.url[-1] == "/":
self.url = self.url[:-1]
if not (self.validation()):
raise Exception("Error connecting to JellyfinAPI")
def CheckAvailability(self) -> bool:
def validation(self) -> bool:
if self.__get("Library/VirtualFolders").status_code == 200:
return True
else:
raise Exception("Error connecting to JellyfinAPI")
def __get(self, api_path: str) -> Response:
request = req_get(f"{self.url}/{api_path}?api_key={self.api_key}")
@ -40,7 +42,7 @@ class Jellyfin(DirectoryGetter):
case 200:
return request
case 401:
raise Exception("Error 401: Authorization error, check api key")
raise Exception("Error 401: Authorization error, check API key")
case 403:
raise Exception("Error 403: Forbidden")
case 404:

View File

@ -1 +1,12 @@
# -*- coding: utf-8 -*-
from enum import Enum
class DirParserTypes(Enum):
Jellyfin = "Jellyfin"
class LogTypes(Enum):
LOG = "Log"
ERROR = "Error"
WARN = "Warning"