Skip to content

Commit

Permalink
#328 added create_asset_folders to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
meisnate12 committed Aug 2, 2021
1 parent ed8d769 commit 2663cbe
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions modules/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def __init__(self, config, library, metadata, name, data):
"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 = {}
Expand Down
4 changes: 3 additions & 1 deletion modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ def check_for_attribute(data, attribute, parent=None, test_list=None, default=No
"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()
Expand Down Expand Up @@ -349,6 +350,7 @@ def check_for_attribute(data, attribute, parent=None, test_list=None, default=No
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)
Expand Down
13 changes: 10 additions & 3 deletions modules/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ def __init__(self, config, params):
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"]
Expand Down Expand Up @@ -746,7 +747,7 @@ def edit_tags(self, attr, obj, add_tags=None, remove_tags=None, sync_tags=None):
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
Expand Down Expand Up @@ -798,12 +799,15 @@ def update_item_from_assets(self, item, overlay=None):
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:
Expand All @@ -825,4 +829,7 @@ def find_collection_assets(self, item, name=None):
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
4 changes: 2 additions & 2 deletions plex_meta_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 2663cbe

Please sign in to comment.