Skip to content

Commit

Permalink
Merge pull request #195 from CollinHeist/develop
Browse files Browse the repository at this point in the history
Create Roman Numeral card type, make separator modifiable, minor changes and fixes
  • Loading branch information
CollinHeist authored Jun 18, 2022
2 parents f2ca07a + 80a5287 commit cc59ba9
Show file tree
Hide file tree
Showing 16 changed files with 291 additions and 66 deletions.
13 changes: 7 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ def runtime(arg: str) -> dict:

def frequency(arg: str) -> dict:
try:
interval, unit = match(r'(\d+)(m|h|d|w)', arg).groups()
interval, unit = match(r'(\d+)(s|m|h|d|w)', arg).groups()
interval, unit = int(interval), unit.lower()
assert interval > 0 and unit in ('m', 'h', 'd', 'w')
assert interval > 0 and unit in ('s', 'm', 'h', 'd', 'w')
return {
'interval': interval,
'unit': {'m':'minutes', 'h':'hours', 'd':'days', 'w':'weeks'}[unit]
'unit': {'s': 'seconds', 'm':'minutes', 'h':'hours', 'd':'days',
'w':'weeks'}[unit],
}
except Exception:
raise ArgumentTypeError(f'Invalid frequency, specify as FREQUENCY[unit]'
Expand Down Expand Up @@ -78,9 +79,9 @@ def frequency(arg: str) -> dict:
type=frequency,
default=environ.get(ENV_FREQUENCY, DEFAULT_FREQUENCY),
metavar='FREQUENCY[unit]',
help=f'How often to run the TitleCardMaker. Units can be m/h/d/w for '
f'minutes/hours/days/weeks. Environment variable {ENV_FREQUENCY}. '
f'Defaults to "{DEFAULT_FREQUENCY}"')
help=f'How often to run the TitleCardMaker. Units can be s/m/h/d/w for '
f'seconds/minutes/hours/days/weeks. Environment variable '
f'{ENV_FREQUENCY}. Defaults to "{DEFAULT_FREQUENCY}"')
parser.add_argument(
'-m', '--missing', '--missing-file',
type=Path,
Expand Down
4 changes: 2 additions & 2 deletions mini_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ class Show:
season_text=args.season_text,
font=args.season_font,
font_color=args.season_font_color,
font_size=args.season_font_size,
font_kerning=args.season_font_kerning,
font_size=float(args.season_font_size[:-1])/100.0,
font_kerning=float(args.season_font_kerning[:-1])/100.0,
).create()


29 changes: 12 additions & 17 deletions modules/AnimeTitleCard.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,17 @@ class AnimeTitleCard(CardType):
"""Characteristics for title splitting by this class"""
TITLE_CHARACTERISTICS = {
'max_line_width': 25, # Character count to begin splitting titles
'max_line_count': 3, # Maximum number of lines a title can take up
'max_line_count': 4, # Maximum number of lines a title can take up
'top_heavy': False, # This class uses bottom heavy titling
}

"""How to name archive directories for this type of card"""
ARCHIVE_NAME = 'Anime Style'

"""Path to the font to use for the episode title"""
"""Characteristics of the default title font"""
TITLE_FONT = str((REF_DIRECTORY / 'Flanker Griffo.otf').resolve())
DEFAULT_FONT_CASE = 'source'

"""Color to use for the episode title"""
TITLE_COLOR = 'white'

"""Color of the episode/episode number text"""
EPISODE_TEXT_COLOR = 'white'

"""Default characters to replace in the generic font"""
FONT_REPLACEMENTS = {}

"""Whether this class uses season titles for the purpose of archives"""
Expand All @@ -46,24 +39,23 @@ class AnimeTitleCard(CardType):
"""Path to the font to use for the kanji font"""
KANJI_FONT = REF_DIRECTORY / 'hiragino-mincho-w3.ttc'

"""Path to the font to use for the series count text"""
"""Font characteristics for the series count text"""
SERIES_COUNT_FONT = REF_DIRECTORY / 'Avenir.ttc'

"""Character used to join season and episode text (with spacing)"""
SERIES_COUNT_JOIN_CHARACTER = '·'

SERIES_COUNT_TEXT_COLOR = '#CFCFCF'

"""Paths to intermediate files that are deleted after the card is created"""
__CONSTRAST_SOURCE = CardType.TEMP_DIR / 'adj_source.png'
__SOURCE_WITH_GRADIENT = CardType.TEMP_DIR / 'source_with_gradient.png'
__GRADIENT_WITH_TITLE = CardType.TEMP_DIR / 'gradient_with_title.png'

__slots__ = ('source_file', 'output_file', 'title', 'kanji', 'use_kanji',
'require_kanji', 'season_text', 'episode_text', 'hide_season',
'separator', 'blur', 'font_size')

def __init__(self, source: Path, output_file: Path, title: str,
season_text: str, episode_text: str, hide_season: bool,
kanji: str=None, require_kanji: bool=False, blur: bool=False,
font_size: float=1.0, *args, **kwargs) -> None:
kanji: str=None, require_kanji: bool=False, separator: str='·',
blur: bool=False, font_size: float=1.0, *args, **kwargs)->None:
"""
Constructs a new instance.
Expand All @@ -77,6 +69,8 @@ def __init__(self, source: Path, output_file: Path, title: str,
:param kanji: Kanji text to place above the
episode title on this card.
:param require_kanji: Whether to require kanji for this card.
:param separator: Character to use to separate season and
episode text.
:param blur: Whether to blur the source image.
:param font_size: Scalar to apply to the title font size.
:param args and kwargs: Unused arguments to permit generalized
Expand All @@ -102,6 +96,7 @@ def __init__(self, source: Path, output_file: Path, title: str,
self.season_text = self.image_magick.escape_chars(season_text.upper())
self.episode_text = self.image_magick.escape_chars(episode_text.upper())
self.hide_season = hide_season
self.separator = separator
self.blur = blur

# Font customizations
Expand Down Expand Up @@ -323,7 +318,7 @@ def __add_series_count_text(self, titled_image: Path) -> Path:
"""

# Construct season text
season_text = f'{self.season_text} {self.SERIES_COUNT_JOIN_CHARACTER} '
season_text = f'{self.season_text} {self.separator} '

# Command list used by both the metric and season text command
season_text_command_list = [
Expand Down
32 changes: 18 additions & 14 deletions modules/LogoTitleCard.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ class LogoTitleCard(CardType):
'top_heavy': False, # This class uses bottom heavy titling
}

"""Default font and text color for episode title text"""
"""Characteristics of the default title font"""
TITLE_FONT = str((REF_DIRECTORY / 'Sequel-Neue.otf').resolve())
TITLE_COLOR = '#EBEBEB'

"""Default characters to replace in the generic font"""
FONT_REPLACEMENTS = {'[': '(', ']': ')', '(': '[', ')': ']', '―': '-',
'…': '...'}

Expand All @@ -50,17 +48,17 @@ class LogoTitleCard(CardType):

__slots__ = ('source_file', 'output_file', 'title', 'season_text',
'episode_text', 'font', 'font_size', 'title_color',
'hide_season', 'blur', 'vertical_shift', 'interline_spacing',
'kerning', 'stroke_width')
'hide_season', 'separator', 'blur', 'vertical_shift',
'interline_spacing', 'kerning', 'stroke_width')


def __init__(self, output_file: Path, title: str, season_text: str,
episode_text: str, font: str, font_size: float,
title_color: str, hide_season: bool, blur: bool=False,
vertical_shift: int=0, interline_spacing: int=0,
kerning: float=1.0, stroke_width: float=1.0,
logo: str=None, background: str='#000000',
*args, **kwargs) -> None:
title_color: str, hide_season: bool, separator: str='•',
blur: bool=False, vertical_shift: int=0,
interline_spacing: int=0, kerning: float=1.0,
stroke_width: float=1.0, logo: str=None,
background: str='#000000', *args, **kwargs) -> None:
"""
Initialize the TitleCardMaker object. This primarily just stores
instance variables for later use in `create()`. If the provided font
Expand All @@ -76,6 +74,8 @@ def __init__(self, output_file: Path, title: str, season_text: str,
:param title_color: Color to use for the episode title.
:param hide_season: Whether to omit the season text (and joining
character) from the title card completely.
:param separator: Character to use to separate season and
episode text.
:param blur: Whether to blur the source image.
:param vertical_shift: Pixels to adjust title vertical shift by.
:param interline_spacing: Pixels to adjust title interline spacing by.
Expand All @@ -99,16 +99,20 @@ def __init__(self, output_file: Path, title: str, season_text: str,
self.season_text = self.image_magick.escape_chars(season_text.upper())
self.episode_text = self.image_magick.escape_chars(episode_text.upper())

# Font attributes
self.font = font
self.font_size = font_size
self.title_color = title_color
self.hide_season = hide_season
self.blur = blur
self.vertical_shift = vertical_shift
self.interline_spacing = interline_spacing
self.kerning = kerning
self.stroke_width = stroke_width

# Miscellaneous attributes
self.blur = blur
self.background = background
self.separator = separator


def __title_text_global_effects(self) -> list:
Expand Down Expand Up @@ -318,7 +322,7 @@ def _get_series_count_text_dimensions(self) -> dict:
f'-font "{self.EPISODE_COUNT_FONT.resolve()}"',
f'-gravity center',
*self.__series_count_text_effects(),
f'-annotate +0+689.5 " "',
f'-annotate +0+689.5 "{self.separator} "',
f'-gravity west',
*self.__series_count_text_effects(),
f'-annotate +1640+697.2 "{self.episode_text}"',
Expand Down Expand Up @@ -367,9 +371,9 @@ def _create_series_count_text_image(self, width: float, width1: float,
f'-annotate +0+{height-25} "{self.season_text} "',
f'-font "{self.EPISODE_COUNT_FONT.resolve()}"',
*self.__series_count_text_black_stroke(),
f'-annotate +{width1}+{height-25-6.5} ""',
f'-annotate +{width1}+{height-25-6.5} "{self.separator}"',
*self.__series_count_text_effects(),
f'-annotate +{width1}+{height-25-6.5} ""',
f'-annotate +{width1}+{height-25-6.5} "{self.separator}"',
*self.__series_count_text_black_stroke(),
f'-annotate +{width1+width2}+{height-25} "{self.episode_text}"',
*self.__series_count_text_effects(),
Expand Down
4 changes: 0 additions & 4 deletions modules/Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ def __init__(self) -> None:
# Get the global preferences
self.preferences = global_objects.pp

# Establish directory bases
self.source_base = self.preferences.source_directory
self.archive_base = self.preferences.archive_directory

# Optionally assign PlexInterface
self.plex_interface = None
if global_objects.pp.use_plex:
Expand Down
2 changes: 1 addition & 1 deletion modules/PlexInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def update_watched_statuses(self, library_name: str,
ep_key = f'{plex_episode.parentIndex}-{plex_episode.index}'
if not (episode := episode_map.get(ep_key)):
continue

# Set Episode watched/spoil statuses
episode.update_statuses(plex_episode.isWatched, watched_style,
unwatched_style)
Expand Down
8 changes: 6 additions & 2 deletions modules/Profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ def get_episode_text(self, episode: 'Episode') -> str:
if (self.__use_custom_seasons and '{abs_' in self.episode_text_format
and episode.episode_info.abs_number is None):
log.warning(f'Episode text formatting uses absolute episode '
f'number, but {episode} has no absolute number')
f'number, but {episode} has no absolute number - '
f'using episode number instead')
new_fmt = self.episode_text_format.replace('{abs_', '{episode_')
self.episode_text_format = new_fmt

# Format MultiEpisode episode text
if isinstance(episode, MultiEpisode):
Expand Down Expand Up @@ -291,7 +294,8 @@ def convert_title(self, title_text: str,
"""

# Modify the title if it contains the episode text format
if self.__use_custom_seasons:
if (self.__use_custom_seasons and
self.episode_text_format not in ('{abs_number}','{episode_number}')):
# Attempt to remove text that matches the episode text format string
title_text = self.__remove_episode_text_format(title_text)

Expand Down
Loading

0 comments on commit cc59ba9

Please sign in to comment.