Add GENERATE_GUIDS enviornment
Signed-off-by: Luigi311 <git@luigi311.com>
This commit is contained in:
@@ -24,6 +24,11 @@ MARK_FILE = "mark.log"
|
||||
## Timeout for requests for jellyfin
|
||||
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 = 32
|
||||
|
||||
|
||||
35
src/plex.py
35
src/plex.py
@@ -1,4 +1,5 @@
|
||||
import re, requests, traceback
|
||||
import os, requests, traceback
|
||||
from dotenv import load_dotenv
|
||||
from typing import Dict, Union, FrozenSet
|
||||
|
||||
from urllib3.poolmanager import PoolManager
|
||||
@@ -16,6 +17,7 @@ from src.functions import (
|
||||
future_thread_executor,
|
||||
contains_nested,
|
||||
log_marked,
|
||||
str_to_bool,
|
||||
)
|
||||
from src.library import (
|
||||
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
|
||||
class HostNameIgnoringAdapter(RequestsHTTPAdapter):
|
||||
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]:
|
||||
# If GENERATE_GUIDS is set to False, then return an empty dict
|
||||
if not generate_guids:
|
||||
return {}
|
||||
|
||||
guids: Dict[str, str] = dict(
|
||||
guid.id.split("://")
|
||||
for guid in item.guids
|
||||
@@ -198,9 +209,11 @@ def find_video(plex_search, video_ids, videos=None):
|
||||
|
||||
return True, episode_videos
|
||||
|
||||
if not generate_guids:
|
||||
return False, []
|
||||
else:
|
||||
for guid in plex_search.guids:
|
||||
guid_source = re.search(r"(.*)://", guid.id).group(1).lower()
|
||||
guid_id = re.search(r"://(.*)", guid.id).group(1)
|
||||
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 guid_source in video_ids.keys():
|
||||
@@ -209,9 +222,9 @@ def find_video(plex_search, video_ids, videos=None):
|
||||
if videos:
|
||||
for show, seasons in videos.items():
|
||||
show = {k: v for k, v in show}
|
||||
if guid_source in show.keys():
|
||||
if guid_id == show[guid_source]:
|
||||
for season in seasons.values():
|
||||
if guid_source in show["ids"].keys():
|
||||
if guid_id in show["ids"][guid_source]:
|
||||
for season in seasons:
|
||||
for episode in season:
|
||||
episode_videos.append(episode)
|
||||
|
||||
@@ -238,16 +251,18 @@ def get_video_status(plex_search, video_ids, videos):
|
||||
):
|
||||
return video["status"]
|
||||
|
||||
if not generate_guids:
|
||||
return None
|
||||
else:
|
||||
for guid in plex_search.guids:
|
||||
guid_source = re.search(r"(.*)://", guid.id).group(1).lower()
|
||||
guid_id = re.search(r"://(.*)", guid.id).group(1)
|
||||
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 guid_source in video_ids.keys():
|
||||
if guid_id in video_ids[guid_source]:
|
||||
for video in videos:
|
||||
if guid_source in video.keys():
|
||||
if guid_id == video[guid_source]:
|
||||
if guid_source in video["ids"].keys():
|
||||
if guid_id in video["ids"][guid_source]:
|
||||
return video["status"]
|
||||
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user