From 9ca10eac4b022f990745bd7d9621f6f9e2c9d521 Mon Sep 17 00:00:00 2001 From: Collin Heist Date: Sat, 9 Apr 2022 12:31:22 -0600 Subject: [PATCH 1/5] Don't permit title translations under title or abs_number keys --- modules/Show.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/Show.py b/modules/Show.py index 315593f1e..70288243f 100755 --- a/modules/Show.py +++ b/modules/Show.py @@ -183,7 +183,12 @@ def __parse_yaml(self): if (self.__is_specified('translation', 'language') and self.__is_specified('translation', 'key')): - self.title_language = self.__yaml['translation'] + key = self.__yaml['translation']['key'] + if key in ('title', 'abs_number'): + log.error(f'Cannot add translations under the key "{key}" in ' + f'series {self}') + else: + self.title_language = self.__yaml['translation'] # Validate season map & episode range aren't specified at the same time if (self.__is_specified('seasons') From 37a5f4627094110f82fac51dc06effe111d860e7 Mon Sep 17 00:00:00 2001 From: Collin Heist Date: Sat, 9 Apr 2022 21:51:06 -0600 Subject: [PATCH 2/5] Add ability to zero-pad season folders --- modules/PreferenceParser.py | 29 +++++++++++++++++++++++++++++ modules/TitleCard.py | 17 ++++++++--------- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/modules/PreferenceParser.py b/modules/PreferenceParser.py index c581e3c04..38b73eda4 100755 --- a/modules/PreferenceParser.py +++ b/modules/PreferenceParser.py @@ -43,6 +43,7 @@ def __init__(self, file: Path) -> None: self.card_type = 'standard' self.card_filename_format = TitleCard.DEFAULT_FILENAME_FORMAT self.validate_fonts = True + self.zero_pad_seasons = False self.archive_directory = None self.create_archive = False self.create_summaries = False @@ -136,6 +137,10 @@ def __parse_yaml(self) -> None: if self.__is_specified('options', 'validate_fonts'): self.validate_fonts = bool(self.__yaml['options']['validate_fonts']) + if self.__is_specified('options', 'zero_pad_seasons'): + val = self.__yaml['options']['zero_pad_seasons'] + self.zero_pad_seasons = bool(val) + if self.__is_specified('archive', 'path'): self.archive_directory = Path(self.__yaml['archive']['path']) self.create_archive = True @@ -299,3 +304,27 @@ def meets_minimum_resolution(self, width: int, height: int) -> bool: return width_ok and height_ok + + def get_season_folder(self, season_number: int) -> str: + """ + Get the season folder name for the given season number, padding the + season number if indicated by the preference file. + + :param season_number: The season number. + + :returns: The season folder. This is 'Specials' for 0, and either a + zero-padded or not zero-padded version of "Season {x}". + """ + + # Season 0 is always Specials + if season_number == 0: + return 'Specials' + + # Zero pad the season number if indicated + if self.zero_pad_seasons: + return f'Season {season_number:02}' + + # Return non-zero-padded season name + return f'Season {season_number}' + + diff --git a/modules/TitleCard.py b/modules/TitleCard.py index 20961b744..7860fc100 100755 --- a/modules/TitleCard.py +++ b/modules/TitleCard.py @@ -1,6 +1,7 @@ from re import match, sub, IGNORECASE from modules.Debug import log +import modules.preferences as global_preferences # CardType classes from modules.AnimeTitleCard import AnimeTitleCard @@ -48,7 +49,7 @@ def __init__(self, episode: 'Episode', profile: 'Profile', directly to the creation of the CardType object. """ - + # Store this card's associated episode and profile self.episode = episode self.profile = profile @@ -91,10 +92,9 @@ def get_output_filename(format_string: str, series_info: 'SeriesInfo', """ # Get the season folder for this entry's season - if episode_info.season_number == 0: - season_folder = 'Specials' - else: - season_folder = f'Season {episode_info.season_number}' + season_folder = global_preferences.pp.get_season_folder( + episode_info.season_number + ) # Get filename from the given format string filename = format_string.format( @@ -150,10 +150,9 @@ def get_multi_output_filename(format_string: str, series_info: 'SeriesInfo', mod_format_string, flags=IGNORECASE) # # Get the season folder for these episodes - if multi_episode.season_number == 0: - season_folder = 'Specials' - else: - season_folder = f'Season {multi_episode.season_number}' + season_folder = global_preferences.pp.get_season_folder( + multi_episode.season_number + ) # Get filename from the modified format string filename = modified_format_string.format( From 7d2ac58a868c3567c898145fe19db7c9f2f871a3 Mon Sep 17 00:00:00 2001 From: Collin Heist Date: Sat, 9 Apr 2022 22:41:23 -0600 Subject: [PATCH 3/5] Look for preferences file in local filepath, not execution path --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 1e8742f96..807948ee2 100755 --- a/main.py +++ b/main.py @@ -8,10 +8,10 @@ from modules.Manager import Manager # Default path for the preference file to parse -DEFAULT_PREFERENCE_FILE = Path('preferences.yml') +DEFAULT_PREFERENCE_FILE = Path(__file__).parent / 'preferences.yml' # Default path for the missing file to write to -DEFAULT_MISSING_FILE = Path('missing.yml') +DEFAULT_MISSING_FILE = Path(__file__).parent / 'missing.yml' # Set up argument parser parser = ArgumentParser(description='Start the TitleCardMaker') From c9bd55ed798cf0ea30239d33a14c47efdb15baa5 Mon Sep 17 00:00:00 2001 From: Collin Heist Date: Sat, 9 Apr 2022 22:41:49 -0600 Subject: [PATCH 4/5] Handle ImportError for missing packages on execution --- main.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 807948ee2..f9674c87e 100755 --- a/main.py +++ b/main.py @@ -1,11 +1,15 @@ from argparse import ArgumentParser from pathlib import Path -from modules.Debug import log -from modules.FontValidator import FontValidator -from modules.PreferenceParser import PreferenceParser -from modules.preferences import set_preference_parser, set_font_validator -from modules.Manager import Manager +try: + from modules.Debug import log + from modules.FontValidator import FontValidator + from modules.PreferenceParser import PreferenceParser + from modules.preferences import set_preference_parser, set_font_validator + from modules.Manager import Manager +except ImportError: + print(f'Required Python packages are missing - execute "pipenv install"') + exit(1) # Default path for the preference file to parse DEFAULT_PREFERENCE_FILE = Path(__file__).parent / 'preferences.yml' From 995f63f4abf691b9d20a982b7a8219d85e65a30f Mon Sep 17 00:00:00 2001 From: Collin Heist Date: Sat, 9 Apr 2022 23:07:14 -0600 Subject: [PATCH 5/5] Identify missing ImageMagick installation at start --- main.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.py b/main.py index f9674c87e..f7df1aa1d 100755 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ try: from modules.Debug import log from modules.FontValidator import FontValidator + from modules.ImageMagickInterface import ImageMagickInterface from modules.PreferenceParser import PreferenceParser from modules.preferences import set_preference_parser, set_font_validator from modules.Manager import Manager @@ -62,6 +63,13 @@ set_preference_parser(pp) set_font_validator(FontValidator()) +# Validate that ImageMagick is configured correctly +imi = ImageMagickInterface(pp.imagemagick_container) +font_output = imi.run_get_stdout('convert -list font') +if not all(_ in font_output for _ in ('Font:', 'family:', 'style:')): + log.critical(f"ImageMagick doesn't appear to be installed") + exit(1) + # Create and run the manager --run many times tcm = None for _ in range(args.run):