diff --git a/main.py b/main.py index 1e8742f9..f7df1aa1 100755 --- a/main.py +++ b/main.py @@ -1,17 +1,22 @@ 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.ImageMagickInterface import ImageMagickInterface + 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('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') @@ -58,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): diff --git a/modules/PreferenceParser.py b/modules/PreferenceParser.py index c581e3c0..38b73eda 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/Show.py b/modules/Show.py index 315593f1..70288243 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') diff --git a/modules/TitleCard.py b/modules/TitleCard.py index 20961b74..7860fc10 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(