Add GENERATE_GUIDS enviornment

Signed-off-by: Luigi311 <git@luigi311.com>
This commit is contained in:
Luigi311
2024-01-10 02:59:33 -07:00
parent fe65716706
commit f5835e1e72
2 changed files with 47 additions and 27 deletions

View File

@@ -24,6 +24,11 @@ MARK_FILE = "mark.log"
## Timeout for requests for jellyfin ## Timeout for requests for jellyfin
REQUEST_TIMEOUT = 300 REQUEST_TIMEOUT = 300
## Generate guids
## Generating guids is a slow process, so this is a way to speed up the process
## by using the location only, useful when using same files on multiple servers
GENERATE_GUIDS = "True"
## Max threads for processing ## Max threads for processing
MAX_THREADS = 32 MAX_THREADS = 32

View File

@@ -1,4 +1,5 @@
import re, requests, traceback import os, requests, traceback
from dotenv import load_dotenv
from typing import Dict, Union, FrozenSet from typing import Dict, Union, FrozenSet
from urllib3.poolmanager import PoolManager from urllib3.poolmanager import PoolManager
@@ -16,6 +17,7 @@ from src.functions import (
future_thread_executor, future_thread_executor,
contains_nested, contains_nested,
log_marked, log_marked,
str_to_bool,
) )
from src.library import ( from src.library import (
check_skip_logic, check_skip_logic,
@@ -23,6 +25,11 @@ from src.library import (
) )
load_dotenv(override=True)
generate_guids = str_to_bool(os.getenv("GENERATE_GUIDS", "True"))
# 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(RequestsHTTPAdapter): class HostNameIgnoringAdapter(RequestsHTTPAdapter):
def init_poolmanager(self, connections, maxsize, block=..., **pool_kwargs): def init_poolmanager(self, connections, maxsize, block=..., **pool_kwargs):
@@ -36,6 +43,10 @@ class HostNameIgnoringAdapter(RequestsHTTPAdapter):
def extract_guids_from_item(item: Union[Movie, Show, Episode]) -> Dict[str, str]: def extract_guids_from_item(item: Union[Movie, Show, Episode]) -> Dict[str, str]:
# If GENERATE_GUIDS is set to False, then return an empty dict
if not generate_guids:
return {}
guids: Dict[str, str] = dict( guids: Dict[str, str] = dict(
guid.id.split("://") guid.id.split("://")
for guid in item.guids for guid in item.guids
@@ -198,24 +209,26 @@ def find_video(plex_search, video_ids, videos=None):
return True, episode_videos return True, episode_videos
for guid in plex_search.guids: if not generate_guids:
guid_source = re.search(r"(.*)://", guid.id).group(1).lower() return False, []
guid_id = re.search(r"://(.*)", guid.id).group(1) else:
for guid in plex_search.guids:
guid_source, guid_id = guid.id.split("://")
# If show provider source and show provider id are in videos_shows_ids exactly, then the show is in the list # If show provider source and show provider id are in videos_shows_ids exactly, then the show is in the list
if guid_source in video_ids.keys(): if guid_source in video_ids.keys():
if guid_id in video_ids[guid_source]: if guid_id in video_ids[guid_source]:
episode_videos = [] episode_videos = []
if videos: if videos:
for show, seasons in videos.items(): for show, seasons in videos.items():
show = {k: v for k, v in show} show = {k: v for k, v in show}
if guid_source in show.keys(): if guid_source in show["ids"].keys():
if guid_id == show[guid_source]: if guid_id in show["ids"][guid_source]:
for season in seasons.values(): for season in seasons:
for episode in season: for episode in season:
episode_videos.append(episode) episode_videos.append(episode)
return True, episode_videos return True, episode_videos
return False, [] return False, []
except Exception: except Exception:
@@ -238,17 +251,19 @@ def get_video_status(plex_search, video_ids, videos):
): ):
return video["status"] return video["status"]
for guid in plex_search.guids: if not generate_guids:
guid_source = re.search(r"(.*)://", guid.id).group(1).lower() return None
guid_id = re.search(r"://(.*)", guid.id).group(1) else:
for guid in plex_search.guids:
guid_source, guid_id = guid.id.split("://")
# If show provider source and show provider id are in videos_shows_ids exactly, then the show is in the list # If show provider source and show provider id are in videos_shows_ids exactly, then the show is in the list
if guid_source in video_ids.keys(): if guid_source in video_ids.keys():
if guid_id in video_ids[guid_source]: if guid_id in video_ids[guid_source]:
for video in videos: for video in videos:
if guid_source in video.keys(): if guid_source in video["ids"].keys():
if guid_id == video[guid_source]: if guid_id in video["ids"][guid_source]:
return video["status"] return video["status"]
return None return None
except Exception: except Exception: