Timeout issues (#103)
* Add timeout support for jellyfin requests Signed-off-by: Luigi311 <git@luigi311.com>
This commit is contained in:
@@ -21,9 +21,6 @@ LOGFILE = "log.log"
|
|||||||
## Timeout for requests for jellyfin
|
## Timeout for requests for jellyfin
|
||||||
REQUEST_TIMEOUT = 300
|
REQUEST_TIMEOUT = 300
|
||||||
|
|
||||||
## Max threads for processing
|
|
||||||
MAX_THREADS = 32
|
|
||||||
|
|
||||||
## Map usernames between servers in the event that they are different, order does not matter
|
## Map usernames between servers in the event that they are different, order does not matter
|
||||||
## Comma separated for multiple options
|
## Comma separated for multiple options
|
||||||
#USER_MAPPING = { "testuser2": "testuser3", "testuser1":"testuser4" }
|
#USER_MAPPING = { "testuser2": "testuser3", "testuser1":"testuser4" }
|
||||||
|
|||||||
@@ -63,6 +63,9 @@ SLEEP_DURATION = "3600"
|
|||||||
## Log file where all output will be written to
|
## Log file where all output will be written to
|
||||||
LOGFILE = "log.log"
|
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
|
## Map usernames between servers in the event that they are different, order does not matter
|
||||||
## Comma separated for multiple options
|
## Comma separated for multiple options
|
||||||
USER_MAPPING = { "testuser2": "testuser3", "testuser1":"testuser4" }
|
USER_MAPPING = { "testuser2": "testuser3", "testuser1":"testuser4" }
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import asyncio, aiohttp, traceback
|
import asyncio, aiohttp, traceback, os
|
||||||
from math import floor
|
from math import floor
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
from src.functions import logger, search_mapping, contains_nested
|
from src.functions import logger, search_mapping, contains_nested
|
||||||
from src.library import (
|
from src.library import (
|
||||||
@@ -10,6 +11,8 @@ from src.watched import (
|
|||||||
combine_watched_dicts,
|
combine_watched_dicts,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
load_dotenv(override=True)
|
||||||
|
|
||||||
|
|
||||||
def get_movie_guids(movie):
|
def get_movie_guids(movie):
|
||||||
if "ProviderIds" in movie:
|
if "ProviderIds" in movie:
|
||||||
@@ -70,6 +73,12 @@ class Jellyfin:
|
|||||||
def __init__(self, baseurl, token):
|
def __init__(self, baseurl, token):
|
||||||
self.baseurl = baseurl
|
self.baseurl = baseurl
|
||||||
self.token = token
|
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:
|
if not self.baseurl:
|
||||||
raise Exception("Jellyfin baseurl not set")
|
raise Exception("Jellyfin baseurl not set")
|
||||||
@@ -130,7 +139,7 @@ class Jellyfin:
|
|||||||
users = {}
|
users = {}
|
||||||
|
|
||||||
query_string = "/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)
|
response = await self.query(query_string, "get", session)
|
||||||
|
|
||||||
# If response is not empty
|
# If response is not empty
|
||||||
@@ -156,7 +165,7 @@ class Jellyfin:
|
|||||||
0,
|
0,
|
||||||
)
|
)
|
||||||
|
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession(timeout=self.timeout) as session:
|
||||||
# Movies
|
# Movies
|
||||||
if library_type == "Movie":
|
if library_type == "Movie":
|
||||||
user_watched[user_name][library_title] = []
|
user_watched[user_name][library_title] = []
|
||||||
@@ -404,7 +413,7 @@ class Jellyfin:
|
|||||||
tasks_watched = []
|
tasks_watched = []
|
||||||
|
|
||||||
tasks_libraries = []
|
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)
|
libraries = await self.query(f"/Users/{user_id}/Views", "get", session)
|
||||||
for library in libraries["Items"]:
|
for library in libraries["Items"]:
|
||||||
library_id = library["Id"]
|
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}",
|
f"Jellyfin: mark list\nShows: {videos_shows_ids}\nEpisodes: {videos_episodes_ids}\nMovies: {videos_movies_ids}",
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession(timeout=self.timeout) as session:
|
||||||
if videos_movies_ids:
|
if videos_movies_ids:
|
||||||
jellyfin_search = await self.query(
|
jellyfin_search = await self.query(
|
||||||
f"/Users/{user_id}/Items"
|
f"/Users/{user_id}/Items"
|
||||||
@@ -829,7 +838,7 @@ class Jellyfin:
|
|||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
tasks = []
|
tasks = []
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession(timeout=self.timeout) as session:
|
||||||
for user, libraries in watched_list.items():
|
for user, libraries in watched_list.items():
|
||||||
logger(f"Jellyfin: Updating for entry {user}, {libraries}", 1)
|
logger(f"Jellyfin: Updating for entry {user}, {libraries}", 1)
|
||||||
user_other = None
|
user_other = None
|
||||||
|
|||||||
Reference in New Issue
Block a user