small changes preparing for Overlays

pull/309/head
meisnate12 3 years ago
parent 05871098c9
commit 10beb29813

@ -131,13 +131,25 @@ all_details = [
"url_background", "tmdb_background", "tvdb_background", "file_background", "url_background", "tmdb_background", "tvdb_background", "file_background",
"name_mapping", "label", "show_filtered", "show_missing", "save_missing" "name_mapping", "label", "show_filtered", "show_missing", "save_missing"
] ]
collectionless_details = [ summary_details = [
"sort_title", "content_rating", "summary", "tmdb_summary", "tmdb_description", "tmdb_biography", "tvdb_summary",
"summary", "tmdb_summary", "tmdb_description", "tmdb_biography", "tvdb_description", "trakt_description", "letterboxd_description"
"collection_order", "plex_collectionless", ]
"url_poster", "tmdb_poster", "tmdb_profile", "file_poster", poster_details = [
"url_background", "file_background", "url_poster", "tmdb_poster", "tmdb_profile", "tvdb_poster", "file_poster"
"name_mapping", "label", "label_sync_mode", "test" ]
background_details = [
"url_background", "tmdb_background", "tvdb_background", "file_background"
]
boolean_details = [
"show_filtered",
"show_missing",
"save_missing"
]
string_details = [
"sort_title",
"content_rating",
"name_mapping"
] ]
ignored_details = [ ignored_details = [
"smart_filter", "smart_filter",
@ -148,13 +160,13 @@ ignored_details = [
"sync_mode", "sync_mode",
"template", "template",
"test", "test",
"tmdb_person" "tmdb_person",
] "build_collection"
boolean_details = [
"show_filtered",
"show_missing",
"save_missing"
] ]
collectionless_details = [
"collection_order", "plex_collectionless",
"label", "label_sync_mode", "test"
] + poster_details + background_details + summary_details + string_details
all_filters = [ all_filters = [
"actor", "actor.not", "actor", "actor.not",
"audio_language", "audio_language.not", "audio_language", "audio_language.not",
@ -439,7 +451,7 @@ class CollectionBuilder:
if "build_collection" in methods: if "build_collection" in methods:
logger.info("") logger.info("")
logger.info("Validating Method: build_collection") logger.info("Validating Method: build_collection")
if not self.data[methods["build_collection"]]: if self.data[methods["build_collection"]] is None:
logger.warning(f"Collection Warning: build_collection attribute is blank defaulting to true") logger.warning(f"Collection Warning: build_collection attribute is blank defaulting to true")
else: else:
logger.debug(f"Value: {self.data[methods['build_collection']]}") logger.debug(f"Value: {self.data[methods['build_collection']]}")
@ -627,8 +639,8 @@ class CollectionBuilder:
self.item_details[method_name] = str(method_data).lower() self.item_details[method_name] = str(method_data).lower()
elif method_name in boolean_details: elif method_name in boolean_details:
self.details[method_name] = util.get_bool(method_name, method_data) self.details[method_name] = util.get_bool(method_name, method_data)
elif method_name in all_details: elif method_name in string_details:
self.details[method_name] = method_data self.details[method_name] = str(method_data)
elif method_name == "radarr_add": elif method_name == "radarr_add":
self.add_to_radarr = util.get_bool(method_name, method_data) self.add_to_radarr = util.get_bool(method_name, method_data)
elif method_name == "radarr_folder": elif method_name == "radarr_folder":
@ -1651,6 +1663,8 @@ class CollectionBuilder:
logger.error(e) logger.error(e)
for item in items: for item in items:
poster, background = self.library.update_item_from_assets(item)
self.library.upload_images(item, poster=poster, background=background)
self.library.edit_tags("label", item, add_tags=add_tags, remove_tags=remove_tags, sync_tags=sync_tags) self.library.edit_tags("label", item, add_tags=add_tags, remove_tags=remove_tags, sync_tags=sync_tags)
advance_edits = {} advance_edits = {}
for method_name, method_data in self.item_details.items(): for method_name, method_data in self.item_details.items():
@ -1745,7 +1759,7 @@ class CollectionBuilder:
if "name_mapping" in self.details: if "name_mapping" in self.details:
if self.details["name_mapping"]: name_mapping = self.details["name_mapping"] if self.details["name_mapping"]: name_mapping = self.details["name_mapping"]
else: logger.error("Collection Error: name_mapping attribute is blank") else: logger.error("Collection Error: name_mapping attribute is blank")
poster_image, background_image = self.library.update_item_from_assets(self.obj, collection_mode=True, upload=False, name=name_mapping) poster_image, background_image = self.library.find_collection_assets(self.obj, name=name_mapping)
if poster_image: if poster_image:
self.posters["asset_directory"] = poster_image self.posters["asset_directory"] = poster_image
if background_image: if background_image:
@ -1767,7 +1781,7 @@ class CollectionBuilder:
elif "tmdb_poster" in self.posters: poster = Image("tmdb_poster", self.posters["tmdb_poster"]) elif "tmdb_poster" in self.posters: poster = Image("tmdb_poster", self.posters["tmdb_poster"])
elif "tmdb_profile" in self.posters: poster = Image("tmdb_poster", self.posters["tmdb_profile"]) elif "tmdb_profile" in self.posters: poster = Image("tmdb_poster", self.posters["tmdb_profile"])
elif "tvdb_poster" in self.posters: poster = Image("tvdb_poster", self.posters["tvdb_poster"]) elif "tvdb_poster" in self.posters: poster = Image("tvdb_poster", self.posters["tvdb_poster"])
elif "asset_directory" in self.posters: poster = Image("asset_directory", self.posters["asset_directory"], is_url=False) elif "asset_directory" in self.posters: poster = self.posters["asset_directory"]
elif "tmdb_person" in self.posters: poster = Image("tmdb_person", self.posters["tmdb_person"]) elif "tmdb_person" in self.posters: poster = Image("tmdb_person", self.posters["tmdb_person"])
elif "tmdb_collection_details" in self.posters: poster = Image("tmdb_collection_details", self.posters["tmdb_collection_details"]) elif "tmdb_collection_details" in self.posters: poster = Image("tmdb_collection_details", self.posters["tmdb_collection_details"])
elif "tmdb_actor_details" in self.posters: poster = Image("tmdb_actor_details", self.posters["tmdb_actor_details"]) elif "tmdb_actor_details" in self.posters: poster = Image("tmdb_actor_details", self.posters["tmdb_actor_details"])
@ -1786,7 +1800,7 @@ class CollectionBuilder:
elif "file_background" in self.backgrounds: background = Image("file_background", self.backgrounds["file_background"], is_poster=False, is_url=False) elif "file_background" in self.backgrounds: background = Image("file_background", self.backgrounds["file_background"], is_poster=False, is_url=False)
elif "tmdb_background" in self.backgrounds: background = Image("tmdb_background", self.backgrounds["tmdb_background"], is_poster=False) elif "tmdb_background" in self.backgrounds: background = Image("tmdb_background", self.backgrounds["tmdb_background"], is_poster=False)
elif "tvdb_background" in self.backgrounds: background = Image("tvdb_background", self.backgrounds["tvdb_background"], is_poster=False) elif "tvdb_background" in self.backgrounds: background = Image("tvdb_background", self.backgrounds["tvdb_background"], is_poster=False)
elif "asset_directory" in self.backgrounds: background = Image("asset_directory", self.backgrounds["asset_directory"], is_poster=False, is_url=False) elif "asset_directory" in self.backgrounds: background = self.backgrounds["asset_directory"]
elif "tmdb_collection_details" in self.backgrounds: background = Image("tmdb_collection_details", self.backgrounds["tmdb_collection_details"], is_poster=False) elif "tmdb_collection_details" in self.backgrounds: background = Image("tmdb_collection_details", self.backgrounds["tmdb_collection_details"], is_poster=False)
elif "tmdb_movie_details" in self.backgrounds: background = Image("tmdb_movie_details", self.backgrounds["tmdb_movie_details"], is_poster=False) elif "tmdb_movie_details" in self.backgrounds: background = Image("tmdb_movie_details", self.backgrounds["tmdb_movie_details"], is_poster=False)
elif "tvdb_movie_details" in self.backgrounds: background = Image("tvdb_movie_details", self.backgrounds["tvdb_movie_details"], is_poster=False) elif "tvdb_movie_details" in self.backgrounds: background = Image("tvdb_movie_details", self.backgrounds["tvdb_movie_details"], is_poster=False)

@ -23,14 +23,12 @@ from ruamel import yaml
logger = logging.getLogger("Plex Meta Manager") logger = logging.getLogger("Plex Meta Manager")
sync_modes = {"append": "Only Add Items to the Collection", "sync": "Add & Remove Items from the Collection"} sync_modes = {"append": "Only Add Items to the Collection", "sync": "Add & Remove Items from the Collection"}
radarr_versions = {"v2": "For Radarr 0.2", "v3": "For Radarr 3.0"}
radarr_availabilities = { radarr_availabilities = {
"announced": "For Announced", "announced": "For Announced",
"cinemas": "For In Cinemas", "cinemas": "For In Cinemas",
"released": "For Released", "released": "For Released",
"db": "For PreDB" "db": "For PreDB"
} }
sonarr_versions = {"v2": "For Sonarr 0.2", "v3": "For Sonarr 3.0"}
sonarr_monitors = { sonarr_monitors = {
"all": "Monitor all episodes except specials", "all": "Monitor all episodes except specials",
"future": "Monitor episodes that have not aired yet", "future": "Monitor episodes that have not aired yet",
@ -58,6 +56,7 @@ class Config:
else: raise Failed(f"Config Error: config not found at {os.path.abspath(default_dir)}") else: raise Failed(f"Config Error: config not found at {os.path.abspath(default_dir)}")
logger.info(f"Using {self.config_path} as config") logger.info(f"Using {self.config_path} as config")
self.default_dir = default_dir
self.test_mode = is_test self.test_mode = is_test
self.run_start_time = time_scheduled self.run_start_time = time_scheduled
self.run_hour = datetime.strptime(time_scheduled, "%H:%M").hour self.run_hour = datetime.strptime(time_scheduled, "%H:%M").hour

@ -10,6 +10,7 @@ from plexapi.server import PlexServer
from retrying import retry from retrying import retry
from ruamel import yaml from ruamel import yaml
from urllib import parse from urllib import parse
from xml.etree.ElementTree import ParseError
logger = logging.getLogger("Plex Meta Manager") logger = logging.getLogger("Plex Meta Manager")
@ -260,7 +261,7 @@ class Plex:
raise Failed("Plex Error: Plex token is invalid") raise Failed("Plex Error: Plex token is invalid")
except ValueError as e: except ValueError as e:
raise Failed(f"Plex Error: {e}") raise Failed(f"Plex Error: {e}")
except requests.exceptions.ConnectionError: except (requests.exceptions.ConnectionError, ParseError):
util.print_stacktrace() util.print_stacktrace()
raise Failed("Plex Error: Plex url is invalid") raise Failed("Plex Error: Plex url is invalid")
self.Plex = next((s for s in self.PlexServer.library.sections() if s.title == params["name"]), None) self.Plex = next((s for s in self.PlexServer.library.sections() if s.title == params["name"]), None)
@ -697,16 +698,19 @@ class Plex:
updated = False updated = False
key = builder.filter_translation[attr] if attr in builder.filter_translation else attr key = builder.filter_translation[attr] if attr in builder.filter_translation else attr
if add_tags or remove_tags or sync_tags: if add_tags or remove_tags or sync_tags:
_add_tags = [f"{t[:1].upper()}{t[1:]}" for t in add_tags] if add_tags else None
_remove_tags = [f"{t[:1].upper()}{t[1:]}" for t in remove_tags] if remove_tags else None
_sync_tags = [t.lower() for t in sync_tags] if sync_tags else None
item_tags = [item_tag.tag for item_tag in getattr(obj, key)] item_tags = [item_tag.tag for item_tag in getattr(obj, key)]
input_tags = [] input_tags = []
if add_tags: if _add_tags:
input_tags.extend(add_tags) input_tags.extend(_add_tags)
if sync_tags: if _sync_tags:
input_tags.extend(sync_tags) input_tags.extend(_sync_tags)
if sync_tags or remove_tags: if _sync_tags or _remove_tags:
remove_method = getattr(obj, f"remove{attr.capitalize()}") remove_method = getattr(obj, f"remove{attr.capitalize()}")
for tag in item_tags: for tag in item_tags:
if (sync_tags and tag not in sync_tags) or (remove_tags and tag in remove_tags): if (_sync_tags and tag.lower() not in _sync_tags) or (_remove_tags and tag in _remove_tags):
updated = True updated = True
self.query_data(remove_method, tag) self.query_data(remove_method, tag)
logger.info(f"Detail: {attr.capitalize()} {tag} removed") logger.info(f"Detail: {attr.capitalize()} {tag} removed")
@ -719,60 +723,75 @@ class Plex:
logger.info(f"Detail: {attr.capitalize()} {tag} added") logger.info(f"Detail: {attr.capitalize()} {tag} added")
return updated return updated
def update_item_from_assets(self, item, collection_mode=False, upload=True, dirs=None, name=None): def update_item_from_assets(self, item):
if dirs is None:
dirs = self.asset_directory
if not name and collection_mode:
name = item.title
elif not name:
name = os.path.basename(os.path.dirname(item.locations[0]) if self.is_movie else item.locations[0]) name = os.path.basename(os.path.dirname(item.locations[0]) if self.is_movie else item.locations[0])
for ad in dirs: for ad in self.asset_directory:
poster = None poster = None
background = None background = None
poster_image = None item_dir = None
background_image = None
if self.asset_folders: if self.asset_folders:
if not os.path.isdir(os.path.join(ad, name)): if os.path.isdir(os.path.join(ad, name)):
item_dir = os.path.join(ad, name)
else:
matches = glob.glob(os.path.join(ad, "*", name))
if len(matches) > 0:
item_dir = os.path.abspath(matches[0])
if item_dir is None:
continue continue
poster_filter = os.path.join(ad, name, "poster.*") poster_filter = os.path.join(item_dir, "poster.*")
background_filter = os.path.join(ad, name, "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"{name}.*")
background_filter = os.path.join(ad, f"{name}_background.*") background_filter = os.path.join(ad, f"{name}_background.*")
matches = glob.glob(poster_filter) matches = glob.glob(poster_filter)
if len(matches) > 0: if len(matches) > 0:
poster_image = os.path.abspath(matches[0]) poster = Image("asset_directory", os.path.abspath(matches[0]), prefix=f"{item.title}'s ", is_url=False)
if upload:
poster = Image("asset_directory", poster_image, prefix=f"{item.title}'s ", is_url=False)
matches = glob.glob(background_filter) matches = glob.glob(background_filter)
if len(matches) > 0: if len(matches) > 0:
background_image = os.path.abspath(matches[0]) background = Image("asset_directory", os.path.abspath(matches[0]), prefix=f"{item.title}'s ", is_poster=False, is_url=False)
if upload: if self.is_show:
background = Image("asset_directory", background_image, prefix=f"{item.title}'s ", is_poster=False, is_url=False)
if poster or background:
self.upload_images(item, poster=poster, background=background)
if collection_mode:
for ite in self.query(item.items):
self.update_item_from_assets(ite, dirs=[os.path.join(ad, name)])
if not upload:
return poster_image, background_image
if self.is_show and not collection_mode:
for season in self.query(item.seasons): for season in self.query(item.seasons):
if self.asset_folders: if item_dir:
season_filter = os.path.join(ad, name, 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"{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_path = os.path.abspath(matches[0]) season_poster = Image("asset_directory", os.path.abspath(matches[0]), prefix=f"{item.title} Season {season.seasonNumber}'s ", is_url=False)
self.upload_images(season, poster=Image("asset_directory", season_path, prefix=f"{item.title} Season {season.seasonNumber}'s ", is_url=False)) self.upload_images(season, poster=season_poster)
for episode in self.query(season.episodes): for episode in self.query(season.episodes):
if self.asset_folders: if item_dir:
episode_filter = os.path.join(ad, name, 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"{name}_{episode.seasonEpisode.upper()}.*")
matches = glob.glob(episode_filter) matches = glob.glob(episode_filter)
if len(matches) > 0: if len(matches) > 0:
episode_path = os.path.abspath(matches[0]) episode_poster = Image("asset_directory", os.path.abspath(matches[0]), prefix=f"{item.title} {episode.seasonEpisode.upper()}'s ", is_url=False)
self.upload_images(episode, poster=Image("asset_directory", episode_path, prefix=f"{item.title} {episode.seasonEpisode.upper()}'s ", is_url=False)) self.upload_images(episode, poster=episode_poster)
if poster or background:
return poster, background
return None, None
def find_collection_assets(self, item, name=None):
if name is None:
name = item.title
for ad in self.asset_directory:
poster = None
background = None
if self.asset_folders:
if not os.path.isdir(os.path.join(ad, name)):
continue
poster_filter = os.path.join(ad, name, "poster.*")
background_filter = os.path.join(ad, name, "background.*")
else:
poster_filter = os.path.join(ad, f"{name}.*")
background_filter = os.path.join(ad, f"{name}_background.*")
matches = glob.glob(poster_filter)
if len(matches) > 0:
poster = Image("asset_directory", os.path.abspath(matches[0]), prefix=f"{item.title}'s ", is_url=False)
matches = glob.glob(background_filter)
if len(matches) > 0:
background = Image("asset_directory", os.path.abspath(matches[0]), prefix=f"{item.title}'s ", is_poster=False, is_url=False)
if poster or background:
return poster, background
return None, None return None, None

@ -189,9 +189,11 @@ def update_libraries(config):
util.separator(f"All {'Movies' if library.is_movie else 'Shows'} Assets Check for {library.name} Library", space=False, border=False) util.separator(f"All {'Movies' if library.is_movie else 'Shows'} Assets Check for {library.name} Library", space=False, border=False)
logger.info("") logger.info("")
for col in unmanaged_collections: for col in unmanaged_collections:
library.update_item_from_assets(col, collection_mode=True) poster, background = library.find_collection_assets(col)
library.upload_images(col, poster=poster, background=background)
for item in library.get_all(): for item in library.get_all():
library.update_item_from_assets(item) poster, background = library.update_item_from_assets(item)
library.upload_images(item, poster=poster, background=background)
logger.removeHandler(library_handler) logger.removeHandler(library_handler)
@ -298,6 +300,9 @@ def mass_metadata(config, library):
omdb_item = config.OMDb.get_omdb(imdb_id) omdb_item = config.OMDb.get_omdb(imdb_id)
except Failed as e: except Failed as e:
logger.info(util.adjust_space(str(e))) logger.info(util.adjust_space(str(e)))
except Exception:
logger.error(f"IMDb ID: {imdb_id}")
raise
else: else:
logger.info(util.adjust_space(f"{item.title[:25]:<25} | No IMDb ID for Guid: {item.guid}")) logger.info(util.adjust_space(f"{item.title[:25]:<25} | No IMDb ID for Guid: {item.guid}"))
@ -453,7 +458,6 @@ def run_collection(config, library, metadata, requested_collections):
logger.info("") logger.info("")
builder.update_details() builder.update_details()
if len(builder.item_details) > 0:
logger.info("") logger.info("")
util.separator(f"Updating Details of the Items in {mapping_name} Collection", space=False, border=False) util.separator(f"Updating Details of the Items in {mapping_name} Collection", space=False, border=False)
logger.info("") logger.info("")

Loading…
Cancel
Save