Added JELLYFIN_REQUEST_TIMEOUT env var
This commit is contained in:
@@ -115,9 +115,9 @@ sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(
|
|||||||
client_secret=app.config['SPOTIFY_CLIENT_SECRET']
|
client_secret=app.config['SPOTIFY_CLIENT_SECRET']
|
||||||
))
|
))
|
||||||
|
|
||||||
app.logger.info(f"setting up jellyfin client")
|
app.logger.info(f"setting up jellyfin client, BaseUrl = {app.config['JELLYFIN_SERVER_URL']}, timeout = {app.config['JELLYFIN_REQUEST_TIMEOUT']}")
|
||||||
|
|
||||||
jellyfin = JellyfinClient(app.config['JELLYFIN_SERVER_URL'])
|
jellyfin = JellyfinClient(app.config['JELLYFIN_SERVER_URL'], app.config['JELLYFIN_REQUEST_TIMEOUT'])
|
||||||
jellyfin_admin_token, jellyfin_admin_id, jellyfin_admin_name, jellyfin_admin_is_admin = jellyfin.login_with_password(
|
jellyfin_admin_token, jellyfin_admin_id, jellyfin_admin_name, jellyfin_admin_is_admin = jellyfin.login_with_password(
|
||||||
app.config['JELLYFIN_ADMIN_USER'],
|
app.config['JELLYFIN_ADMIN_USER'],
|
||||||
app.config['JELLYFIN_ADMIN_PASSWORD'], device_id= device_id
|
app.config['JELLYFIN_ADMIN_PASSWORD'], device_id= device_id
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class Config:
|
|||||||
JELLYFIN_SERVER_URL = os.getenv('JELLYFIN_SERVER_URL')
|
JELLYFIN_SERVER_URL = os.getenv('JELLYFIN_SERVER_URL')
|
||||||
JELLYFIN_ADMIN_USER = os.getenv('JELLYFIN_ADMIN_USER')
|
JELLYFIN_ADMIN_USER = os.getenv('JELLYFIN_ADMIN_USER')
|
||||||
JELLYFIN_ADMIN_PASSWORD = os.getenv('JELLYFIN_ADMIN_PASSWORD')
|
JELLYFIN_ADMIN_PASSWORD = os.getenv('JELLYFIN_ADMIN_PASSWORD')
|
||||||
|
JELLYFIN_REQUEST_TIMEOUT = int(os.getenv('JELLYFIN_REQUEST_TIMEOUT','10'))
|
||||||
SPOTIFY_CLIENT_ID = os.getenv('SPOTIFY_CLIENT_ID')
|
SPOTIFY_CLIENT_ID = os.getenv('SPOTIFY_CLIENT_ID')
|
||||||
SPOTIFY_CLIENT_SECRET = os.getenv('SPOTIFY_CLIENT_SECRET')
|
SPOTIFY_CLIENT_SECRET = os.getenv('SPOTIFY_CLIENT_SECRET')
|
||||||
JELLYPLIST_DB_HOST = os.getenv('JELLYPLIST_DB_HOST')
|
JELLYPLIST_DB_HOST = os.getenv('JELLYPLIST_DB_HOST')
|
||||||
|
|||||||
@@ -23,12 +23,13 @@ def _clean_query(query):
|
|||||||
return cleaned_query
|
return cleaned_query
|
||||||
|
|
||||||
class JellyfinClient:
|
class JellyfinClient:
|
||||||
def __init__(self, base_url):
|
def __init__(self, base_url, timeout = 10):
|
||||||
"""
|
"""
|
||||||
Initialize the Jellyfin client with the base URL of the server.
|
Initialize the Jellyfin client with the base URL of the server.
|
||||||
:param base_url: The base URL of the Jellyfin server (e.g., 'http://localhost:8096')
|
:param base_url: The base URL of the Jellyfin server (e.g., 'http://localhost:8096')
|
||||||
"""
|
"""
|
||||||
self.base_url = base_url
|
self.base_url = base_url
|
||||||
|
self.timeout = timeout
|
||||||
|
|
||||||
def _get_headers(self, session_token: str):
|
def _get_headers(self, session_token: str):
|
||||||
"""
|
"""
|
||||||
@@ -165,7 +166,7 @@ class JellyfinClient:
|
|||||||
'Fields': 'OpenAccess' # Fields we want
|
'Fields': 'OpenAccess' # Fields we want
|
||||||
}
|
}
|
||||||
|
|
||||||
response = requests.get(playlists_url, headers=self._get_headers(session_token=session_token), params=params , timeout = 10)
|
response = requests.get(playlists_url, headers=self._get_headers(session_token=session_token), params=params , timeout = self.timeout)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
return response.json()['Items']
|
return response.json()['Items']
|
||||||
@@ -177,7 +178,7 @@ class JellyfinClient:
|
|||||||
params = {
|
params = {
|
||||||
|
|
||||||
}
|
}
|
||||||
response = requests.get(url, headers=self._get_headers(session_token=session_token), params=params , timeout = 10)
|
response = requests.get(url, headers=self._get_headers(session_token=session_token), params=params , timeout = self.timeout)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
return response.json()
|
return response.json()
|
||||||
else:
|
else:
|
||||||
@@ -194,7 +195,7 @@ class JellyfinClient:
|
|||||||
"RegenerateTrickplay": "false",
|
"RegenerateTrickplay": "false",
|
||||||
"ReplaceAllMetadata": "false"
|
"ReplaceAllMetadata": "false"
|
||||||
}
|
}
|
||||||
response = requests.post(url, headers=self._get_headers(session_token=session_token), params=params , timeout = 10)
|
response = requests.post(url, headers=self._get_headers(session_token=session_token), params=params , timeout = self.timeout)
|
||||||
if response.status_code == 204:
|
if response.status_code == 204:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
@@ -374,7 +375,7 @@ class JellyfinClient:
|
|||||||
headers = self._get_headers(session_token=session_token)
|
headers = self._get_headers(session_token=session_token)
|
||||||
|
|
||||||
# Send the request to Jellyfin API
|
# Send the request to Jellyfin API
|
||||||
response = requests.post(url, headers=headers, json=data,timeout = 10)
|
response = requests.post(url, headers=headers, json=data,timeout = self.timeout)
|
||||||
|
|
||||||
# Check for success
|
# Check for success
|
||||||
if response.status_code == 204:
|
if response.status_code == 204:
|
||||||
@@ -388,7 +389,7 @@ class JellyfinClient:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
me_url = f'{self.base_url}/Users/Me'
|
me_url = f'{self.base_url}/Users/Me'
|
||||||
response = requests.get(me_url, headers=self._get_headers(session_token=session_token), timeout = 10)
|
response = requests.get(me_url, headers=self._get_headers(session_token=session_token), timeout = self.timeout)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|||||||
Reference in New Issue
Block a user