mirror of
https://github.com/meisnate12/Plex-Meta-Manager
synced 2024-11-10 06:54:21 +00:00
#564 Download url assets for collections
This commit is contained in:
parent
f942191251
commit
7076448541
4 changed files with 49 additions and 10 deletions
|
@ -2252,12 +2252,18 @@ class CollectionBuilder:
|
|||
self.library.edit_query(self.obj, edits)
|
||||
logger.info("Details: have been updated")
|
||||
|
||||
poster_image = None
|
||||
background_image = None
|
||||
asset_location = None
|
||||
if self.library.asset_directory:
|
||||
name_mapping = self.name
|
||||
if "name_mapping" in self.details:
|
||||
if self.details["name_mapping"]: name_mapping = self.details["name_mapping"]
|
||||
else: logger.error(f"{self.Type} Error: name_mapping attribute is blank")
|
||||
poster_image, background_image = self.library.find_assets(self.obj, name=name_mapping, upload=False, folders=self.details["asset_folders"], create=self.details["create_asset_folders"])
|
||||
poster_image, background_image, asset_location = self.library.find_assets(
|
||||
self.obj, name=name_mapping, upload=False,
|
||||
folders=self.details["asset_folders"], create=self.details["create_asset_folders"]
|
||||
)
|
||||
if poster_image:
|
||||
self.posters["asset_directory"] = poster_image
|
||||
if background_image:
|
||||
|
@ -2269,7 +2275,21 @@ class CollectionBuilder:
|
|||
for p in self.posters:
|
||||
logger.debug(f"Method: {p} Poster: {self.posters[p]}")
|
||||
|
||||
if "url_poster" in self.posters: self.collection_poster = ImageData("url_poster", self.posters["url_poster"])
|
||||
if "url_poster" in self.posters:
|
||||
if self.library.download_url_assets and asset_location:
|
||||
if poster_image:
|
||||
self.collection_poster = self.posters["asset_directory"]
|
||||
else:
|
||||
response = self.config.get(self.posters["url_poster"], headers=util.header())
|
||||
if response.status_code >= 400 or "Content-Type" not in response.headers or response.headers["Content-Type"] not in ["image/png", "image/jpeg"]:
|
||||
logger.error(f"Image Error: Failed to parse Image at {self.posters['url_poster']}")
|
||||
else:
|
||||
new_image = os.path.join(asset_location, f"poster{'.png' if response.headers['Content-Type'] == 'image/png' else '.jpg'}")
|
||||
with open(new_image, "wb") as handler:
|
||||
handler.write(response.content)
|
||||
self.collection_poster = ImageData("asset_directory", new_image, prefix=f"{self.obj.title}'s ", is_url=False)
|
||||
if not self.collection_poster:
|
||||
self.collection_poster = ImageData("url_poster", self.posters["url_poster"])
|
||||
elif "file_poster" in self.posters: self.collection_poster = ImageData("file_poster", self.posters["file_poster"], is_url=False)
|
||||
elif "tmdb_poster" in self.posters: self.collection_poster = ImageData("tmdb_poster", self.posters["tmdb_poster"])
|
||||
elif "tmdb_profile" in self.posters: self.collection_poster = ImageData("tmdb_poster", self.posters["tmdb_profile"])
|
||||
|
@ -2295,7 +2315,21 @@ class CollectionBuilder:
|
|||
for b in self.backgrounds:
|
||||
logger.debug(f"Method: {b} Background: {self.backgrounds[b]}")
|
||||
|
||||
if "url_background" in self.backgrounds: self.collection_background = ImageData("url_background", self.backgrounds["url_background"], is_poster=False)
|
||||
if "url_background" in self.backgrounds:
|
||||
if self.library.download_url_assets and asset_location:
|
||||
if background_image:
|
||||
self.collection_background = self.backgrounds["asset_directory"]
|
||||
else:
|
||||
response = self.config.get(self.backgrounds["url_background"], headers=util.header())
|
||||
if response.status_code >= 400 or "Content-Type" not in response.headers or response.headers["Content-Type"] not in ["image/png", "image/jpeg"]:
|
||||
logger.error(f"Image Error: Failed to parse Image at {self.backgrounds['url_background']}")
|
||||
else:
|
||||
new_image = os.path.join(asset_location, f"background{'.png' if response.headers['Content-Type'] == 'image/png' else '.jpg'}")
|
||||
with open(new_image, "wb") as handler:
|
||||
handler.write(response.content)
|
||||
self.collection_background = ImageData("asset_directory", new_image, prefix=f"{self.obj.title}'s ", is_url=False, is_poster=False)
|
||||
if not self.collection_background:
|
||||
self.collection_background = ImageData("url_background", self.backgrounds["url_background"], is_poster=False)
|
||||
elif "file_background" in self.backgrounds: self.collection_background = ImageData("file_background", self.backgrounds["file_background"], is_poster=False, is_url=False)
|
||||
elif "tmdb_background" in self.backgrounds: self.collection_background = ImageData("tmdb_background", self.backgrounds["tmdb_background"], is_poster=False)
|
||||
elif "tvdb_background" in self.backgrounds: self.collection_background = ImageData("tvdb_background", self.backgrounds["tvdb_background"], is_poster=False)
|
||||
|
|
|
@ -265,6 +265,7 @@ class ConfigFile:
|
|||
"asset_depth": check_for_attribute(self.data, "asset_depth", parent="settings", var_type="int", default=0),
|
||||
"create_asset_folders": check_for_attribute(self.data, "create_asset_folders", parent="settings", var_type="bool", default=False),
|
||||
"dimensional_asset_rename": check_for_attribute(self.data, "dimensional_asset_rename", parent="settings", var_type="bool", default=False),
|
||||
"download_url_assets": check_for_attribute(self.data, "download_url_assets", parent="settings", var_type="bool", default=False),
|
||||
"show_missing_season_assets": check_for_attribute(self.data, "show_missing_season_assets", parent="settings", var_type="bool", default=False),
|
||||
"sync_mode": check_for_attribute(self.data, "sync_mode", parent="settings", default="append", test_list=sync_modes),
|
||||
"default_collection_order": check_for_attribute(self.data, "default_collection_order", parent="settings", default_is_none=True),
|
||||
|
@ -563,6 +564,7 @@ class ConfigFile:
|
|||
params["only_filter_missing"] = check_for_attribute(lib, "only_filter_missing", parent="settings", var_type="bool", default=self.general["only_filter_missing"], 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)
|
||||
params["dimensional_asset_rename"] = check_for_attribute(lib, "dimensional_asset_rename", parent="settings", var_type="bool", default=self.general["dimensional_asset_rename"], do_print=False, save=False)
|
||||
params["download_url_assets"] = check_for_attribute(lib, "download_url_assets", parent="settings", var_type="bool", default=self.general["download_url_assets"], do_print=False, save=False)
|
||||
params["show_missing_season_assets"] = check_for_attribute(lib, "show_missing_season_assets", parent="settings", var_type="bool", default=self.general["show_missing_season_assets"], do_print=False, save=False)
|
||||
params["minimum_items"] = check_for_attribute(lib, "minimum_items", parent="settings", var_type="int", default=self.general["minimum_items"], do_print=False, save=False)
|
||||
params["delete_below_minimum"] = check_for_attribute(lib, "delete_below_minimum", parent="settings", var_type="bool", default=self.general["delete_below_minimum"], do_print=False, save=False)
|
||||
|
|
|
@ -44,6 +44,7 @@ class Library(ABC):
|
|||
self.asset_folders = params["asset_folders"]
|
||||
self.create_asset_folders = params["create_asset_folders"]
|
||||
self.dimensional_asset_rename = params["dimensional_asset_rename"]
|
||||
self.download_url_assets = params["download_url_assets"]
|
||||
self.show_missing_season_assets = params["show_missing_season_assets"]
|
||||
self.sync_mode = params["sync_mode"]
|
||||
self.default_collection_order = params["default_collection_order"]
|
||||
|
|
|
@ -827,12 +827,12 @@ class Plex(Library):
|
|||
elif isinstance(item, Collection):
|
||||
name = name if name else item.title
|
||||
else:
|
||||
return None, None
|
||||
return None, None, None
|
||||
if not folders:
|
||||
folders = self.asset_folders
|
||||
if not create:
|
||||
create = self.create_asset_folders
|
||||
found_folder = False
|
||||
found_folder = None
|
||||
poster = None
|
||||
background = None
|
||||
for ad in self.asset_directory:
|
||||
|
@ -851,7 +851,7 @@ class Plex(Library):
|
|||
break
|
||||
if item_dir is None:
|
||||
continue
|
||||
found_folder = True
|
||||
found_folder = item_dir
|
||||
poster_filter = os.path.join(item_dir, "poster.*")
|
||||
background_filter = os.path.join(item_dir, "background.*")
|
||||
else:
|
||||
|
@ -887,7 +887,7 @@ class Plex(Library):
|
|||
if upload:
|
||||
self.upload_images(item, poster=poster, background=background, overlay=overlay)
|
||||
else:
|
||||
return poster, background
|
||||
return poster, background, item_dir
|
||||
if isinstance(item, Show):
|
||||
missing_assets = ""
|
||||
found_season = False
|
||||
|
@ -923,13 +923,15 @@ class Plex(Library):
|
|||
self.upload_images(episode, poster=episode_poster)
|
||||
if self.show_missing_season_assets and found_season and missing_assets:
|
||||
util.print_multiline(f"Missing Season Posters for {item.title}{missing_assets}", info=True)
|
||||
|
||||
if isinstance(item, (Movie, Show)) and not poster and overlay:
|
||||
self.upload_images(item, overlay=overlay)
|
||||
if create and 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)}")
|
||||
found_folder = os.path.join(self.asset_directory[0], name)
|
||||
os.makedirs(found_folder, exist_ok=True)
|
||||
logger.info(f"Asset Directory Created: {found_folder}")
|
||||
elif isinstance(item, (Movie, Show)) and not overlay and folders and not found_folder:
|
||||
logger.warning(f"Asset Warning: No asset folder found called '{name}'")
|
||||
elif isinstance(item, (Movie, Show)) and not poster and not background and self.show_missing_assets:
|
||||
logger.warning(f"Asset Warning: No poster or background found in an assets folder for '{name}'")
|
||||
return None, None
|
||||
return None, None, found_folder
|
||||
|
|
Loading…
Reference in a new issue