#328 added create_asset_folders to settings

This commit is contained in:
meisnate12 2021-08-02 15:00:15 -04:00
parent ed8d7696d7
commit 2663cbe487
4 changed files with 16 additions and 6 deletions

View file

@ -149,6 +149,7 @@ class CollectionBuilder:
"show_missing": self.library.show_missing,
"save_missing": self.library.save_missing,
"released_missing_only": self.library.released_missing_only,
"create_asset_folders": self.library.create_asset_folders,
"item_assets": False
}
self.item_details = {}

View file

@ -183,7 +183,8 @@ class Config:
"show_filtered": check_for_attribute(self.data, "show_filtered", parent="settings", var_type="bool", default=False),
"show_missing": check_for_attribute(self.data, "show_missing", parent="settings", var_type="bool", default=True),
"save_missing": check_for_attribute(self.data, "save_missing", parent="settings", var_type="bool", default=True),
"released_missing_only": check_for_attribute(self.data, "released_missing_only", parent="settings", var_type="bool", default=False)
"released_missing_only": check_for_attribute(self.data, "released_missing_only", parent="settings", var_type="bool", default=False),
"create_asset_folders": check_for_attribute(self.data, "create_asset_folders", parent="settings", var_type="bool", default=False)
}
if self.general["cache"]:
util.separator()
@ -349,6 +350,7 @@ class Config:
params["show_missing"] = check_for_attribute(lib, "show_missing", parent="settings", var_type="bool", default=self.general["show_missing"], do_print=False, save=False)
params["save_missing"] = check_for_attribute(lib, "save_missing", parent="settings", var_type="bool", default=self.general["save_missing"], do_print=False, save=False)
params["released_missing_only"] = check_for_attribute(lib, "released_missing_only", parent="settings", var_type="bool", default=self.general["released_missing_only"], do_print=False, save=False)
params["create_asset_folders"] = check_for_attribute(lib, "create_asset_folders", parent="settings", var_type="bool", default=self.general["create_asset_folders"], do_print=False, save=False)
if lib and "mass_genre_update" in lib and lib["mass_genre_update"]:
params["mass_genre_update"] = check_for_attribute(lib, "mass_genre_update", test_list=mass_update_options, default_is_none=True, save=False)

View file

@ -280,6 +280,7 @@ class Plex:
self.show_missing = params["show_missing"]
self.save_missing = params["save_missing"]
self.released_missing_only = params["released_missing_only"]
self.create_asset_folders = params["create_asset_folders"]
self.mass_genre_update = params["mass_genre_update"]
self.mass_audience_rating_update = params["mass_audience_rating_update"]
self.mass_critic_rating_update = params["mass_critic_rating_update"]
@ -746,7 +747,7 @@ class Plex:
logger.info(f"Detail: {attr.capitalize()} {_remove} removed")
return updated
def update_item_from_assets(self, item, overlay=None):
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]))
logger.debug(name)
found_folder = False
@ -798,12 +799,15 @@ class Plex:
self.upload_images(episode, poster=episode_poster)
if not poster and overlay:
self.upload_images(item, overlay=overlay)
if not overlay and self.asset_folders and not found_folder:
if create and self.asset_folders and not found_folder:
os.makedirs(os.path.join(self.asset_directory[0], name), exist_ok=True)
logger.info(f"Asset Directory Created: {os.path.join(self.asset_directory[0], name)}")
elif not overlay and self.asset_folders and not found_folder:
logger.error(f"Asset Warning: No asset folder found called '{name}'")
elif not poster and not background:
logger.error(f"Asset Warning: No poster or background found in an assets folder for '{name}'")
def find_collection_assets(self, item, name=None):
def find_collection_assets(self, item, name=None, create=False):
if name is None:
name = item.title
for ad in self.asset_directory:
@ -825,4 +829,7 @@ class Plex:
background = ImageData("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
if create and self.asset_folders and not os.path.isdir(os.path.join(self.asset_directory[0], name)):
os.makedirs(os.path.join(self.asset_directory[0], name), exist_ok=True)
logger.info(f"Asset Directory Created: {os.path.join(self.asset_directory[0], name)}")
return None, None

View file

@ -189,10 +189,10 @@ 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)
logger.info("")
for col in unmanaged_collections:
poster, background = library.find_collection_assets(col)
poster, background = library.find_collection_assets(col, create=library.create_asset_folders)
library.upload_images(col, poster=poster, background=background)
for item in library.get_all():
library.update_item_from_assets(item)
library.update_item_from_assets(item, create=library.create_asset_folders)
logger.removeHandler(library_handler)