Timeout issues (#103)

* Add timeout support for jellyfin requests

Signed-off-by: Luigi311 <git@luigi311.com>
pull/109/head
Luigi311 2023-09-25 01:59:16 -06:00 committed by GitHub
parent 237e82eceb
commit ac7f389563
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 6 deletions

View File

@ -18,6 +18,9 @@ SLEEP_DURATION = "3600"
## Log file where all output will be written to
LOGFILE = "log.log"
## Timeout for requests for jellyfin
REQUEST_TIMEOUT = 300
## Map usernames between servers in the event that they are different, order does not matter
## Comma separated for multiple options
#USER_MAPPING = { "testuser2": "testuser3", "testuser1":"testuser4" }

View File

@ -63,6 +63,9 @@ SLEEP_DURATION = "3600"
## Log file where all output will be written to
LOGFILE = "log.log"
## Timeout for requests for jellyfin
REQUEST_TIMEOUT = 300
## Map usernames between servers in the event that they are different, order does not matter
## Comma separated for multiple options
USER_MAPPING = { "testuser2": "testuser3", "testuser1":"testuser4" }

View File

@ -1,5 +1,6 @@
import asyncio, aiohttp, traceback
import asyncio, aiohttp, traceback, os
from math import floor
from dotenv import load_dotenv
from src.functions import logger, search_mapping, contains_nested
from src.library import (
@ -10,6 +11,8 @@ from src.watched import (
combine_watched_dicts,
)
load_dotenv(override=True)
def get_movie_guids(movie):
if "ProviderIds" in movie:
@ -70,6 +73,12 @@ class Jellyfin:
def __init__(self, baseurl, token):
self.baseurl = baseurl
self.token = token
self.timeout = aiohttp.ClientTimeout(
total = int(os.getenv("REQUEST_TIMEOUT", 300)),
connect=None,
sock_connect=None,
sock_read=None,
)
if not self.baseurl:
raise Exception("Jellyfin baseurl not set")
@ -130,7 +139,7 @@ class Jellyfin:
users = {}
query_string = "/Users"
async with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession(timeout=self.timeout) as session:
response = await self.query(query_string, "get", session)
# If response is not empty
@ -156,7 +165,7 @@ class Jellyfin:
0,
)
async with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession(timeout=self.timeout) as session:
# Movies
if library_type == "Movie":
user_watched[user_name][library_title] = []
@ -404,7 +413,7 @@ class Jellyfin:
tasks_watched = []
tasks_libraries = []
async with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession(timeout=self.timeout) as session:
libraries = await self.query(f"/Users/{user_id}/Views", "get", session)
for library in libraries["Items"]:
library_id = library["Id"]
@ -545,7 +554,7 @@ class Jellyfin:
f"Jellyfin: mark list\nShows: {videos_shows_ids}\nEpisodes: {videos_episodes_ids}\nMovies: {videos_movies_ids}",
1,
)
async with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession(timeout=self.timeout) as session:
if videos_movies_ids:
jellyfin_search = await self.query(
f"/Users/{user_id}/Items"
@ -829,7 +838,7 @@ class Jellyfin:
):
try:
tasks = []
async with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession(timeout=self.timeout) as session:
for user, libraries in watched_list.items():
logger(f"Jellyfin: Updating for entry {user}, {libraries}", 1)
user_other = None