From fb657d41dbe606a5cdd2173f9bdd6cf1ca1bcc9a Mon Sep 17 00:00:00 2001 From: Luigi311 Date: Thu, 28 Sep 2023 09:47:34 -0600 Subject: [PATCH 1/4] Update apis Signed-off-by: Luigi311 --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 2f36597..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.4 +aiohttp==3.8.5 From 3a0e60c772006e4aa1351907848d3e3bf906694b Mon Sep 17 00:00:00 2001 From: Luigi311 Date: Thu, 28 Sep 2023 10:00:07 -0600 Subject: [PATCH 2/4] Add max_threads Signed-off-by: Luigi311 --- .env.sample | 6 ++++++ src/functions.py | 5 ++--- src/plex.py | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.env.sample b/.env.sample index 2f231ea..2953a0e 100644 --- a/.env.sample +++ b/.env.sample @@ -18,6 +18,12 @@ SLEEP_DURATION = "3600" ## Log file where all output will be written to 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/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/plex.py b/src/plex.py index 0bcdf7b..715daae 100644 --- a/src/plex.py +++ b/src/plex.py @@ -174,7 +174,7 @@ def get_user_library_watched(user, user_plex, library): args.append([get_user_library_watched_show, show]) for show_guids, episode_guids in future_thread_executor( - args, workers=min(os.cpu_count(), 4) + args, threads=4 ): if show_guids and episode_guids: # append show, season, episode From 2a59f38faf36b3367c56b540b65af2ef46e759c7 Mon Sep 17 00:00:00 2001 From: Luigi311 Date: Thu, 28 Sep 2023 10:45:02 -0600 Subject: [PATCH 3/4] Add docker compose to types Signed-off-by: Luigi311 --- .github/ISSUE_TEMPLATE/bug_report.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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** From bf5d87507904ef90c9085a57ed38f07906851e5e Mon Sep 17 00:00:00 2001 From: Luigi311 Date: Thu, 28 Sep 2023 19:41:53 -0600 Subject: [PATCH 4/4] Print server info Signed-off-by: Luigi311 --- src/black_white.py | 40 +--------------------------------------- src/jellyfin.py | 23 +++++++++++++++++++++-- src/main.py | 3 +++ src/plex.py | 9 +++++---- 4 files changed, 30 insertions(+), 45 deletions(-) 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/jellyfin.py b/src/jellyfin.py index 2dbd7f3..50555f9 100644 --- a/src/jellyfin.py +++ b/src/jellyfin.py @@ -74,7 +74,7 @@ class Jellyfin: 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 @@ class Jellyfin: 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 @@ class Jellyfin: 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 715daae..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, threads=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 @@ class Plex: 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()