commit
3cd73e54a1
|
|
@ -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" }
|
||||
|
|
|
|||
|
|
@ -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**
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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 = {}
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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 @@ 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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue