Skip to content

Commit

Permalink
Merge pull request #62 from CollinHeist/develop
Browse files Browse the repository at this point in the history
Optional zero-padded season folders, improved bad setup handling
  • Loading branch information
CollinHeist authored Apr 10, 2022
2 parents 75c6d7d + 995f63f commit f1a0699
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 17 deletions.
26 changes: 19 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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):
Expand Down
29 changes: 29 additions & 0 deletions modules/PreferenceParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}'


7 changes: 6 additions & 1 deletion modules/Show.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
17 changes: 8 additions & 9 deletions modules/TitleCard.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit f1a0699

Please sign in to comment.