Check for response status 200 on jellyfin query
This commit is contained in:
@@ -38,17 +38,24 @@ class Jellyfin:
|
|||||||
async with session.get(
|
async with session.get(
|
||||||
self.baseurl + query, headers=headers
|
self.baseurl + query, headers=headers
|
||||||
) as response:
|
) as response:
|
||||||
|
if response.status != 200:
|
||||||
|
raise Exception(
|
||||||
|
f"Query failed with status {response.status} {response.reason}"
|
||||||
|
)
|
||||||
results = await response.json()
|
results = await response.json()
|
||||||
|
|
||||||
elif query_type == "post":
|
elif query_type == "post":
|
||||||
async with session.post(
|
async with session.post(
|
||||||
self.baseurl + query, headers=headers
|
self.baseurl + query, headers=headers
|
||||||
) as response:
|
) as response:
|
||||||
|
if response.status != 200:
|
||||||
|
raise Exception(
|
||||||
|
f"Query failed with status {response.status} {response.reason}"
|
||||||
|
)
|
||||||
results = await response.json()
|
results = await response.json()
|
||||||
|
|
||||||
if type(results) is str:
|
if not isinstance(results, list) and not isinstance(results, dict):
|
||||||
logger(f"Jellyfin: Query {query_type} {query} {results}", 2)
|
raise Exception("Query result is not of type list or dict")
|
||||||
raise Exception(results)
|
|
||||||
|
|
||||||
# append identifiers to results
|
# append identifiers to results
|
||||||
if identifiers:
|
if identifiers:
|
||||||
@@ -57,7 +64,7 @@ class Jellyfin:
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger(f"Jellyfin: Query failed {e}", 2)
|
logger(f"Jellyfin: Query {query_type} {query}\nResults {results}\n{e}", 2)
|
||||||
raise Exception(e)
|
raise Exception(e)
|
||||||
|
|
||||||
async def get_users(self):
|
async def get_users(self):
|
||||||
@@ -393,12 +400,7 @@ class Jellyfin:
|
|||||||
|
|
||||||
# If there are multiple types in library raise error
|
# If there are multiple types in library raise error
|
||||||
if types is None or len(types) < 1:
|
if types is None or len(types) < 1:
|
||||||
all_types = set(
|
all_types = set([x["Type"] for x in watched["Items"]])
|
||||||
[
|
|
||||||
x["Type"]
|
|
||||||
for x in watched["Items"]
|
|
||||||
]
|
|
||||||
)
|
|
||||||
logger(
|
logger(
|
||||||
f"Jellyfin: Skipping Library {library_title} found types: {types}, all types: {all_types}",
|
f"Jellyfin: Skipping Library {library_title} found types: {types}, all types: {all_types}",
|
||||||
1,
|
1,
|
||||||
|
|||||||
37
src/main.py
37
src/main.py
@@ -18,7 +18,6 @@ load_dotenv(override=True)
|
|||||||
def setup_users(
|
def setup_users(
|
||||||
server_1, server_2, blacklist_users, whitelist_users, user_mapping=None
|
server_1, server_2, blacklist_users, whitelist_users, user_mapping=None
|
||||||
):
|
):
|
||||||
|
|
||||||
# generate list of users from server 1 and server 2
|
# generate list of users from server 1 and server 2
|
||||||
server_1_type = server_1[0]
|
server_1_type = server_1[0]
|
||||||
server_1_connection = server_1[1]
|
server_1_connection = server_1[1]
|
||||||
@@ -266,27 +265,45 @@ def update_server_watched(
|
|||||||
|
|
||||||
def should_sync_server(server_1_type, server_2_type):
|
def should_sync_server(server_1_type, server_2_type):
|
||||||
sync_from_plex_to_jellyfin = str_to_bool(
|
sync_from_plex_to_jellyfin = str_to_bool(
|
||||||
os.getenv("SYNC_FROM_PLEX_TO_JELLYFIN", "True"))
|
os.getenv("SYNC_FROM_PLEX_TO_JELLYFIN", "True")
|
||||||
|
)
|
||||||
sync_from_jelly_to_plex = str_to_bool(
|
sync_from_jelly_to_plex = str_to_bool(
|
||||||
os.getenv("SYNC_FROM_JELLYFIN_TO_PLEX", "True"))
|
os.getenv("SYNC_FROM_JELLYFIN_TO_PLEX", "True")
|
||||||
sync_from_plex_to_plex = str_to_bool(
|
)
|
||||||
os.getenv("SYNC_FROM_PLEX_TO_PLEX", "True"))
|
sync_from_plex_to_plex = str_to_bool(os.getenv("SYNC_FROM_PLEX_TO_PLEX", "True"))
|
||||||
sync_from_jelly_to_jellyfin = str_to_bool(
|
sync_from_jelly_to_jellyfin = str_to_bool(
|
||||||
os.getenv("SYNC_FROM_JELLYFIN_TO_JELLYFIN", "True"))
|
os.getenv("SYNC_FROM_JELLYFIN_TO_JELLYFIN", "True")
|
||||||
|
)
|
||||||
|
|
||||||
if server_1_type == "plex" and server_2_type == "plex" and not sync_from_plex_to_plex:
|
if (
|
||||||
|
server_1_type == "plex"
|
||||||
|
and server_2_type == "plex"
|
||||||
|
and not sync_from_plex_to_plex
|
||||||
|
):
|
||||||
logger("Sync between plex and plex is disabled", 1)
|
logger("Sync between plex and plex is disabled", 1)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if server_1_type == "plex" and server_2_type == "jellyfin" and not sync_from_jelly_to_plex:
|
if (
|
||||||
|
server_1_type == "plex"
|
||||||
|
and server_2_type == "jellyfin"
|
||||||
|
and not sync_from_jelly_to_plex
|
||||||
|
):
|
||||||
logger("Sync from jellyfin to plex disabled", 1)
|
logger("Sync from jellyfin to plex disabled", 1)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if server_1_type == "jellyfin" and server_2_type == "jellyfin" and not sync_from_jelly_to_jellyfin:
|
if (
|
||||||
|
server_1_type == "jellyfin"
|
||||||
|
and server_2_type == "jellyfin"
|
||||||
|
and not sync_from_jelly_to_jellyfin
|
||||||
|
):
|
||||||
logger("Sync between jellyfin and jellyfin is disabled", 1)
|
logger("Sync between jellyfin and jellyfin is disabled", 1)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if server_1_type == "jellyfin" and server_2_type == "plex" and not sync_from_plex_to_jellyfin:
|
if (
|
||||||
|
server_1_type == "jellyfin"
|
||||||
|
and server_2_type == "plex"
|
||||||
|
and not sync_from_plex_to_jellyfin
|
||||||
|
):
|
||||||
logger("Sync from plex to jellyfin is disabled", 1)
|
logger("Sync from plex to jellyfin is disabled", 1)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from src.functions import (
|
|||||||
future_thread_executor,
|
future_thread_executor,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Bypass hostname validation for ssl. Taken from https://github.com/pkkid/python-plexapi/issues/143#issuecomment-775485186
|
# Bypass hostname validation for ssl. Taken from https://github.com/pkkid/python-plexapi/issues/143#issuecomment-775485186
|
||||||
class HostNameIgnoringAdapter(requests.adapters.HTTPAdapter):
|
class HostNameIgnoringAdapter(requests.adapters.HTTPAdapter):
|
||||||
def init_poolmanager(self, connections, maxsize, block=..., **pool_kwargs):
|
def init_poolmanager(self, connections, maxsize, block=..., **pool_kwargs):
|
||||||
@@ -235,7 +236,10 @@ def update_user_watched(user, user_plex, library, videos, dryrun):
|
|||||||
).group(1)
|
).group(1)
|
||||||
|
|
||||||
# If episode provider source and episode provider id are in videos_episodes_ids exactly, then the episode is in the list
|
# If episode provider source and episode provider id are in videos_episodes_ids exactly, then the episode is in the list
|
||||||
if episode_guid_source in videos_episodes_ids.keys():
|
if (
|
||||||
|
episode_guid_source
|
||||||
|
in videos_episodes_ids.keys()
|
||||||
|
):
|
||||||
if (
|
if (
|
||||||
episode_guid_id
|
episode_guid_id
|
||||||
in videos_episodes_ids[episode_guid_source]
|
in videos_episodes_ids[episode_guid_source]
|
||||||
|
|||||||
Reference in New Issue
Block a user