Skip to content

Commit

Permalink
Add GENERATE_GUIDS enviornment
Browse files Browse the repository at this point in the history
Signed-off-by: Luigi311 <[email protected]>
  • Loading branch information
luigi311 committed Jan 10, 2024
1 parent fb87b23 commit 5508c3a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 12 additions & 5 deletions src/plex.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,13 +17,17 @@
future_thread_executor,
contains_nested,
log_marked,
str_to_bool,
)
from src.library import (
check_skip_logic,
generate_library_guids_dict,
)


load_dotenv(override=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):
Expand All @@ -36,6 +41,10 @@ def init_poolmanager(self, connections, maxsize, block=..., **pool_kwargs):


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 str_to_bool(os.getenv("GENERATE_GUIDS", "True")):
return {}

guids: Dict[str, str] = dict(
guid.id.split("://")
for guid in item.guids
Expand Down Expand Up @@ -199,8 +208,7 @@ def find_video(plex_search, video_ids, videos=None):
return True, episode_videos

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():
Expand Down Expand Up @@ -237,8 +245,7 @@ def get_video_status(plex_search, video_ids, videos):
return video["status"]

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():
Expand Down

0 comments on commit 5508c3a

Please sign in to comment.