From bd89058ceb1038b3a9bd67147add766f4a1ee4ad Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Fri, 10 Jun 2022 22:05:16 -0400 Subject: [PATCH] [35] add font_style and fixed assets --- VERSION | 2 +- docs/metadata/overlay.md | 1 + modules/config.py | 2 +- modules/meta.py | 10 +++++----- modules/plex.py | 20 ++++++++++---------- modules/util.py | 11 ++++++++++- 6 files changed, 28 insertions(+), 18 deletions(-) diff --git a/VERSION b/VERSION index a1f713ff..e1b7b862 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.17.0-develop34 +1.17.0-develop35 diff --git a/docs/metadata/overlay.md b/docs/metadata/overlay.md index e61aaa24..62965bbd 100644 --- a/docs/metadata/overlay.md +++ b/docs/metadata/overlay.md @@ -82,6 +82,7 @@ There are many attributes available when using overlays to edit how they work. | `vertical_offset` | Vertical Offset of this overlay. Can be a %.
**`horizontal_offset` is required when using `vertical_offset`**
**Value:** Integer 0 or greater or 0%-100% | ❌ | | `vertical_align` | Vertical Alignment of the overlay.
**Values:** `top`, `center`, `bottom` | ❌ | | `font` | System Font Filename or path to font file for the Text Overlay.
**Value:** System Font Filename or path to font file | ❌ | +| `font_style` | Font style for Variable Fonts. Only needed when using a Variable Font.
**Value:** Variable Font Style | ❌ | | `font_size` | Font Size for the Text Overlay.
**Value:** Integer greater than 0 | ❌ | | `font_color` | Font Color for the Text Overlay.
**Value:** Color Hex Code in format `#RGB`, `#RGBA`, `#RRGGBB` or `#RRGGBBAA`. | ❌ | | `back_color` | Backdrop Color for the Text Overlay.
**Value:** Color Hex Code in format `#RGB`, `#RGBA`, `#RRGGBB` or `#RRGGBBAA`. | ❌ | diff --git a/modules/config.py b/modules/config.py index 1d7109e2..32258e0c 100644 --- a/modules/config.py +++ b/modules/config.py @@ -782,7 +782,7 @@ class ConfigFile: raise Failed("Config Error: overlay_path attribute is blank") files = util.load_files(lib["overlay_path"], "overlay_path", lib_vars=lib_vars) if not files: - raise Failed("Config Error: No Paths Found for overlay_path") + logger.error("Config Error: No Paths Found for overlay_path") for file in util.get_list(lib["overlay_path"], split=False): if isinstance(file, dict): if ("remove_overlays" in file and file["remove_overlays"] is True) \ diff --git a/modules/meta.py b/modules/meta.py index 3956fe5e..d6a20580 100644 --- a/modules/meta.py +++ b/modules/meta.py @@ -917,7 +917,7 @@ class MetadataFile(DataFile): logger.info(f"{self.library.type}: {mapping_name} Details Update {'Complete' if updated else 'Not Needed'}") - asset_location = self.library.item_images(item, meta, methods) + asset_location, folder_name = self.library.item_images(item, meta, methods) if "seasons" in methods and self.library.is_show: if not meta[methods["seasons"]]: @@ -948,7 +948,7 @@ class MetadataFile(DataFile): finish_edit(season, f"Season: {season_id}") self.library.item_images(season, season_dict, season_methods, asset_location=asset_location, title=f"{item.title} Season {season.seasonNumber}", - image_name=f"Season{'0' if season.seasonNumber < 10 else ''}{season.seasonNumber}") + image_name=f"Season{'0' if season.seasonNumber < 10 else ''}{season.seasonNumber}", folder_name=folder_name) logger.info(f"Season {season_id} of {mapping_name} Details Update {'Complete' if updated else 'Not Needed'}") if "episodes" in season_methods and self.library.is_show: @@ -985,7 +985,7 @@ class MetadataFile(DataFile): finish_edit(episode, f"Episode: {episode_str} in Season: {season_id}") self.library.item_images(episode, episode_dict, episode_methods, asset_location=asset_location, title=f"{item.title} {episode.seasonEpisode.upper()}", - image_name=episode.seasonEpisode.upper()) + image_name=episode.seasonEpisode.upper(), folder_name=folder_name) logger.info(f"Episode {episode_str} in Season {season_id} of {mapping_name} Details Update {'Complete' if updated else 'Not Needed'}") if "episodes" in methods and self.library.is_show: @@ -1025,7 +1025,7 @@ class MetadataFile(DataFile): finish_edit(episode, f"Episode: {episode_str} in Season: {season_id}") self.library.item_images(episode, episode_dict, episode_methods, asset_location=asset_location, title=f"{item.title} {episode.seasonEpisode.upper()}", - image_name=episode.seasonEpisode.upper()) + image_name=episode.seasonEpisode.upper(), folder_name=folder_name) logger.info(f"Episode S{season_id}E{episode_id} of {mapping_name} Details Update {'Complete' if updated else 'Not Needed'}") if "albums" in methods and self.library.is_music: @@ -1064,7 +1064,7 @@ class MetadataFile(DataFile): updated = True finish_edit(album, f"Album: {title}") self.library.item_images(album, album_dict, album_methods, asset_location=asset_location, - title=f"{item.title} Album {album.title}", image_name=album.title) + title=f"{item.title} Album {album.title}", image_name=album.title, folder_name=folder_name) logger.info(f"Album: {title} of {mapping_name} Details Update {'Complete' if updated else 'Not Needed'}") if "tracks" in album_methods: diff --git a/modules/plex.py b/modules/plex.py index 8c18f2e0..8abc1425 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -910,12 +910,12 @@ class Plex(Library): logger.info(final) return final - def item_images(self, item, group, alias, asset_location=None, title=None, image_name=None): + def item_images(self, item, group, alias, asset_location=None, title=None, image_name=None, folder_name=None): if title is None: title = item.title posters, backgrounds = util.get_image_dicts(group, alias) try: - asset_poster, asset_background, item_dir, _ = self.find_item_assets(item, item_asset_directory=asset_location) + asset_poster, asset_background, item_dir, folder_name = self.find_item_assets(item, item_asset_directory=asset_location) if asset_poster: posters["asset_directory"] = asset_poster if asset_background: @@ -929,7 +929,7 @@ class Plex(Library): is_poster=False, image_name=f"{image_name}_background" if image_name else image_name) if poster or background: self.upload_images(item, poster=poster, background=background) - return asset_location + return asset_location, folder_name def find_and_upload_assets(self, item): try: @@ -945,7 +945,7 @@ class Plex(Library): found_season = False found_episode = False for season in self.query(item.seasons): - season_poster, season_background, _, _ = self.find_item_assets(season, item_asset_directory=item_dir) + season_poster, season_background, _, _ = self.find_item_assets(season, item_asset_directory=item_dir, folder_name=name) if season_poster: found_season = True elif self.show_missing_season_assets and season.seasonNumber > 0: @@ -954,7 +954,7 @@ class Plex(Library): self.upload_images(season, poster=season_poster, background=season_background) for episode in self.query(season.episodes): if episode.seasonEpisode: - episode_poster, episode_background, _, _ = self.find_item_assets(episode, item_asset_directory=item_dir) + episode_poster, episode_background, _, _ = self.find_item_assets(episode, item_asset_directory=item_dir, folder_name=name) if episode_poster or episode_background: found_episode = True self.upload_images(episode, poster=episode_poster, background=episode_background) @@ -966,7 +966,7 @@ class Plex(Library): missing_assets = "" found_album = False for album in self.query(item.albums): - album_poster, album_background, _, _ = self.find_item_assets(album, item_asset_directory=item_dir) + album_poster, album_background, _, _ = self.find_item_assets(album, item_asset_directory=item_dir, folder_name=name) if album_poster or album_background: found_album = True elif self.show_missing_season_assets: @@ -979,10 +979,9 @@ class Plex(Library): if self.show_missing_assets: logger.warning(e) - def find_item_assets(self, item, item_asset_directory=None, asset_directory=None): + def find_item_assets(self, item, item_asset_directory=None, asset_directory=None, folder_name=None): poster = None background = None - folder_name = None if asset_directory is None: asset_directory = self.asset_directory @@ -1015,9 +1014,10 @@ class Plex(Library): else: folder_name, _ = util.validate_filename(item) - if not self.asset_folders: - file_name = folder_name if file_name == "poster" else f"{folder_name}_{file_name}" + if not self.asset_folders: + file_name = folder_name if file_name == "poster" else f"{folder_name}_{file_name}" + if not item_asset_directory: for ad in asset_directory: if self.asset_folders: if os.path.isdir(os.path.join(ad, folder_name)): diff --git a/modules/util.py b/modules/util.py index ef9ec678..4ee29691 100644 --- a/modules/util.py +++ b/modules/util.py @@ -1024,7 +1024,16 @@ class Overlay: if font not in fonts: raise Failed(f"Overlay Error: font: {font} not found. Options: {', '.join(fonts)}") self.font_name = font - self.font = ImageFont.truetype(self.font_name, self.font_size) + self.font = ImageFont.truetype(self.font_name, self.font_size) + if "font_style" in self.data and self.data["font_style"]: + try: + variation_names = [n.decode("utf-8") for n in self.font.get_variation_names()] + if self.data["font_style"] in variation_names: + self.font.set_variation_by_name(self.data["font_style"]) + else: + raise Failed(f"Overlay Error: Font Style {self.data['font_style']} not found. Options: {','.join(variation_names)}") + except OSError: + logger.warning(f"Overlay Warning: font: {self.font} does not have variations") self.font_color = None if "font_color" in self.data and self.data["font_color"]: try: