diff --git a/.env.sample b/.env.sample index af6e63e..2953a0e 100644 --- a/.env.sample +++ b/.env.sample @@ -21,6 +21,9 @@ LOGFILE = "log.log" ## Timeout for requests for jellyfin 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 ## Comma separated for multiple options #USER_MAPPING = { "testuser2": "testuser3", "testuser1":"testuser4" } diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 298ced2..08d0947 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -24,7 +24,8 @@ A clear and concise description of what you expected to happen. If applicable, add logs to help explain your problem ideally with DEBUG set to true, be sure to remove sensitive information **Type:** -- [ ] Docker +- [ ] Docker Compose +- [ ] Docker - [ ] Native **Additional context** diff --git a/requirements.txt b/requirements.txt index 65308eb..027232b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -PlexAPI==4.13.4 +PlexAPI==4.15.2 requests==2.31.0 python-dotenv==1.0.0 aiohttp==3.8.5 diff --git a/src/black_white.py b/src/black_white.py index 5b44c03..494818a 100644 --- a/src/black_white.py +++ b/src/black_white.py @@ -38,6 +38,7 @@ def setup_black_white_lists( whitelist_users, ) + def setup_x_lists( xlist_library, xlist_library_type, @@ -89,42 +90,3 @@ def setup_x_lists( logger(f"{xlist_type}list Users: {xlist_users}", 1) return xlist_library, xlist_library_type, xlist_users - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/functions.py b/src/functions.py index 2e7529b..49dc67e 100644 --- a/src/functions.py +++ b/src/functions.py @@ -63,12 +63,11 @@ def search_mapping(dictionary: dict, key_value: str): return None -def future_thread_executor(args: list, workers: int = -1): +def future_thread_executor(args: list, threads: int = 32): futures_list = [] results = [] - if workers == -1: - workers = min(32, os.cpu_count() * 2) + workers = min(int(os.getenv("MAX_THREADS", 32)), os.cpu_count() * 2, threads) with ThreadPoolExecutor(max_workers=workers) as executor: for arg in args: diff --git a/src/jellyfin.py b/src/jellyfin.py index 2dbd7f3..50555f9 100644 --- a/src/jellyfin.py +++ b/src/jellyfin.py @@ -74,7 +74,7 @@ def __init__(self, baseurl, token): self.baseurl = baseurl self.token = token self.timeout = aiohttp.ClientTimeout( - total = int(os.getenv("REQUEST_TIMEOUT", 300)), + total=int(os.getenv("REQUEST_TIMEOUT", 300)), connect=None, sock_connect=None, sock_read=None, @@ -88,8 +88,12 @@ def __init__(self, baseurl, token): self.users = asyncio.run(self.get_users()) - async def query(self, query, query_type, session, identifiers=None): + async def query(self, query, query_type, session=None, identifiers=None): try: + if not session: + async with aiohttp.ClientSession(timeout=self.timeout) as session: + return await self.query(query, query_type, session, identifiers) + results = None headers = {"Accept": "application/json", "X-Emby-Token": self.token} authorization = ( @@ -134,6 +138,21 @@ async def query(self, query, query_type, session, identifiers=None): logger(f"Jellyfin: Query {query_type} {query}\nResults {results}\n{e}", 2) raise Exception(e) + def info(self) -> str: + try: + query_string = "/System/Info/Public" + + response = asyncio.run(self.query(query_string, "get")) + + if response: + return f"{response['ServerName']}: {response['Version']}" + else: + return None + + except Exception as e: + logger(f"Jellyfin: Get server name failed {e}", 2) + raise Exception(e) + async def get_users(self): try: users = {} diff --git a/src/main.py b/src/main.py index 715e5d8..562dc46 100644 --- a/src/main.py +++ b/src/main.py @@ -304,6 +304,9 @@ def main_loop(): # Start server_2 at the next server in the list for server_2 in servers[servers.index(server_1) + 1 :]: + logger(f"Server 1: {server_1[0].capitalize()}: {server_1[1].info()}", 0) + logger(f"Server 2: {server_2[0].capitalize()}: {server_2[1].info()}", 0) + # Create users list logger("Creating users list", 1) server_1_users, server_2_users = setup_users( diff --git a/src/plex.py b/src/plex.py index 0bcdf7b..df80adf 100644 --- a/src/plex.py +++ b/src/plex.py @@ -1,4 +1,4 @@ -import re, requests, os, traceback +import re, requests, traceback from urllib3.poolmanager import PoolManager from math import floor @@ -173,9 +173,7 @@ def get_user_library_watched(user, user_plex, library): for show in library_videos.search(inProgress=True): args.append([get_user_library_watched_show, show]) - for show_guids, episode_guids in future_thread_executor( - args, workers=min(os.cpu_count(), 4) - ): + for show_guids, episode_guids in future_thread_executor(args, threads=4): if show_guids and episode_guids: # append show, season, episode if show_guids not in user_watched[user_name][library.title]: @@ -414,6 +412,9 @@ def login(self, baseurl, token): logger(f"Plex: Failed to login, Error: {e}", 2) raise Exception(e) + def info(self) -> str: + return f"{self.plex.friendlyName}: {self.plex.version}" + def get_users(self): try: users = self.plex.myPlexAccount().users()