Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout issues #103

Merged
merged 4 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
21 changes: 15 additions & 6 deletions src/jellyfin.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -10,6 +11,8 @@
combine_watched_dicts,
)

load_dotenv(override=True)


def get_movie_guids(movie):
if "ProviderIds" in movie:
Expand Down Expand Up @@ -70,6 +73,12 @@
def __init__(self, baseurl, token):
self.baseurl = baseurl
self.token = token
self.timeout = aiohttp.ClientTimeout(
total = int(os.getenv("REQUEST_TIMEOUT", 300))
connect=None,
Fixed Show fixed Hide fixed
sock_connect=None,
sock_read=None,
)

if not self.baseurl:
raise Exception("Jellyfin baseurl not set")
Expand Down Expand Up @@ -130,7 +139,7 @@
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
Expand All @@ -156,7 +165,7 @@
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] = []
Expand Down Expand Up @@ -404,7 +413,7 @@
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"]
Expand Down Expand Up @@ -545,7 +554,7 @@
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"
Expand Down Expand Up @@ -829,7 +838,7 @@
):
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
Expand Down