fix glob error

pull/351/head
meisnate12 3 years ago
parent 6920e39d32
commit d20df5f258

@ -733,8 +733,6 @@ class Plex:
_item_tags = [] _item_tags = []
_add = [f"{t[:1].upper()}{t[1:]}" for t in _add_tags + _sync_tags if t.lower() not in _item_tags] _add = [f"{t[:1].upper()}{t[1:]}" for t in _add_tags + _sync_tags if t.lower() not in _item_tags]
_remove = [t for t in _item_tags if (_sync_tags and t not in _sync_tags) or t in _remove_tags] _remove = [t for t in _item_tags if (_sync_tags and t not in _sync_tags) or t in _remove_tags]
logger.debug(_add)
logger.debug(_remove)
if _add: if _add:
updated = True updated = True
self.query_data(getattr(obj, f"add{attr.capitalize()}"), _add) self.query_data(getattr(obj, f"add{attr.capitalize()}"), _add)
@ -747,6 +745,7 @@ class Plex:
def update_item_from_assets(self, item, overlay=None, create=False): def update_item_from_assets(self, item, overlay=None, create=False):
name = os.path.basename(os.path.dirname(str(item.locations[0])) if self.is_movie else str(item.locations[0])) name = os.path.basename(os.path.dirname(str(item.locations[0])) if self.is_movie else str(item.locations[0]))
glob_name = name.translate({ord("["): "[[]", ord("]"): "[]]"}) if "[" in name else name
logger.debug(name) logger.debug(name)
found_folder = False found_folder = False
poster = None poster = None
@ -757,7 +756,7 @@ class Plex:
if os.path.isdir(os.path.join(ad, name)): if os.path.isdir(os.path.join(ad, name)):
item_dir = os.path.join(ad, name) item_dir = os.path.join(ad, name)
else: else:
matches = glob.glob(os.path.join(ad, "*", name)) matches = glob.glob(os.path.join(ad, "*", glob_name))
if len(matches) > 0: if len(matches) > 0:
item_dir = os.path.abspath(matches[0]) item_dir = os.path.abspath(matches[0])
if item_dir is None: if item_dir is None:
@ -766,8 +765,8 @@ class Plex:
poster_filter = os.path.join(item_dir, "poster.*") poster_filter = os.path.join(item_dir, "poster.*")
background_filter = os.path.join(item_dir, "background.*") background_filter = os.path.join(item_dir, "background.*")
else: else:
poster_filter = os.path.join(ad, f"{name}.*") poster_filter = os.path.join(ad, f"{glob_name}.*")
background_filter = os.path.join(ad, f"{name}_background.*") background_filter = os.path.join(ad, f"{glob_name}_background.*")
matches = glob.glob(poster_filter) matches = glob.glob(poster_filter)
if len(matches) > 0: if len(matches) > 0:
poster = ImageData("asset_directory", os.path.abspath(matches[0]), prefix=f"{item.title}'s ", is_url=False) poster = ImageData("asset_directory", os.path.abspath(matches[0]), prefix=f"{item.title}'s ", is_url=False)
@ -781,7 +780,7 @@ class Plex:
if item_dir: if item_dir:
season_filter = os.path.join(item_dir, f"Season{'0' if season.seasonNumber < 10 else ''}{season.seasonNumber}.*") season_filter = os.path.join(item_dir, f"Season{'0' if season.seasonNumber < 10 else ''}{season.seasonNumber}.*")
else: else:
season_filter = os.path.join(ad, f"{name}_Season{'0' if season.seasonNumber < 10 else ''}{season.seasonNumber}.*") season_filter = os.path.join(ad, f"{glob_name}_Season{'0' if season.seasonNumber < 10 else ''}{season.seasonNumber}.*")
matches = glob.glob(season_filter) matches = glob.glob(season_filter)
if len(matches) > 0: if len(matches) > 0:
season_poster = ImageData("asset_directory", os.path.abspath(matches[0]), prefix=f"{item.title} Season {season.seasonNumber}'s ", is_url=False) season_poster = ImageData("asset_directory", os.path.abspath(matches[0]), prefix=f"{item.title} Season {season.seasonNumber}'s ", is_url=False)
@ -790,7 +789,7 @@ class Plex:
if item_dir: if item_dir:
episode_filter = os.path.join(item_dir, f"{episode.seasonEpisode.upper()}.*") episode_filter = os.path.join(item_dir, f"{episode.seasonEpisode.upper()}.*")
else: else:
episode_filter = os.path.join(ad, f"{name}_{episode.seasonEpisode.upper()}.*") episode_filter = os.path.join(ad, f"{glob_name}_{episode.seasonEpisode.upper()}.*")
matches = glob.glob(episode_filter) matches = glob.glob(episode_filter)
if len(matches) > 0: if len(matches) > 0:
episode_poster = ImageData("asset_directory", os.path.abspath(matches[0]), prefix=f"{item.title} {episode.seasonEpisode.upper()}'s ", is_url=False) episode_poster = ImageData("asset_directory", os.path.abspath(matches[0]), prefix=f"{item.title} {episode.seasonEpisode.upper()}'s ", is_url=False)
@ -808,17 +807,18 @@ class Plex:
def find_collection_assets(self, item, name=None, create=False): def find_collection_assets(self, item, name=None, create=False):
if name is None: if name is None:
name = item.title name = item.title
glob_name = name.translate({ord("["): "[[]", ord("]"): "[]]"}) if "[" in name else name
for ad in self.asset_directory: for ad in self.asset_directory:
poster = None poster = None
background = None background = None
if self.asset_folders: if self.asset_folders:
if not os.path.isdir(os.path.join(ad, name)): if not os.path.isdir(os.path.join(ad, name)):
continue continue
poster_filter = os.path.join(ad, name, "poster.*") poster_filter = os.path.join(ad, glob_name, "poster.*")
background_filter = os.path.join(ad, name, "background.*") background_filter = os.path.join(ad, glob_name, "background.*")
else: else:
poster_filter = os.path.join(ad, f"{name}.*") poster_filter = os.path.join(ad, f"{glob_name}.*")
background_filter = os.path.join(ad, f"{name}_background.*") background_filter = os.path.join(ad, f"{glob_name}_background.*")
matches = glob.glob(poster_filter) matches = glob.glob(poster_filter)
if len(matches) > 0: if len(matches) > 0:
poster = ImageData("asset_directory", os.path.abspath(matches[0]), prefix=f"{item.title}'s ", is_url=False) poster = ImageData("asset_directory", os.path.abspath(matches[0]), prefix=f"{item.title}'s ", is_url=False)

Loading…
Cancel
Save