|
|
@ -1,8 +1,21 @@
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from jinja2 import Environment, Undefined
|
|
|
|
|
|
|
|
from .constants import DEFAULT_OUTPUT_FILENAME_TEMPLATE
|
|
|
|
|
|
|
|
from .configuration_controller import ConfigurationController
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EmptyStringUndefined(Undefined):
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
|
|
|
|
return ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DIFF_ADDED_KEY = 'added'
|
|
|
|
DIFF_ADDED_KEY = 'added'
|
|
|
|
DIFF_REMOVED_KEY = 'removed'
|
|
|
|
DIFF_REMOVED_KEY = 'removed'
|
|
|
|
DIFF_CHANGED_KEY = 'changed'
|
|
|
|
DIFF_CHANGED_KEY = 'changed'
|
|
|
|
DIFF_UNCHANGED_KEY = 'unchanged'
|
|
|
|
DIFF_UNCHANGED_KEY = 'unchanged'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def dictDiff(a : dict, b : dict):
|
|
|
|
def dictDiff(a : dict, b : dict):
|
|
|
|
|
|
|
|
|
|
|
|
a_keys = set(a.keys())
|
|
|
|
a_keys = set(a.keys())
|
|
|
@ -75,3 +88,79 @@ def filterFilename(fileName: str) -> str:
|
|
|
|
fileName = str(fileName).replace("?", '#')
|
|
|
|
fileName = str(fileName).replace("?", '#')
|
|
|
|
|
|
|
|
|
|
|
|
return fileName.strip()
|
|
|
|
return fileName.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getEpisodeFileBasename(showName,
|
|
|
|
|
|
|
|
episodeName,
|
|
|
|
|
|
|
|
season,
|
|
|
|
|
|
|
|
episode,
|
|
|
|
|
|
|
|
indexSeasonDigits = 2,
|
|
|
|
|
|
|
|
indexEpisodeDigits = 2,
|
|
|
|
|
|
|
|
indicatorSeasonDigits = 2,
|
|
|
|
|
|
|
|
indicatorEpisodeDigits = 2,
|
|
|
|
|
|
|
|
context = None):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
One Piece:
|
|
|
|
|
|
|
|
indexSeasonDigits = 0,
|
|
|
|
|
|
|
|
indexEpisodeDigits = 4,
|
|
|
|
|
|
|
|
indicatorSeasonDigits = 2,
|
|
|
|
|
|
|
|
indicatorEpisodeDigits = 4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Three-Body:
|
|
|
|
|
|
|
|
indexSeasonDigits = 0,
|
|
|
|
|
|
|
|
indexEpisodeDigits = 2,
|
|
|
|
|
|
|
|
indicatorSeasonDigits = 2,
|
|
|
|
|
|
|
|
indicatorEpisodeDigits = 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Dragonball:
|
|
|
|
|
|
|
|
indexSeasonDigits = 0,
|
|
|
|
|
|
|
|
indexEpisodeDigits = 3,
|
|
|
|
|
|
|
|
indicatorSeasonDigits = 2,
|
|
|
|
|
|
|
|
indicatorEpisodeDigits = 3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Boruto:
|
|
|
|
|
|
|
|
indexSeasonDigits = 0,
|
|
|
|
|
|
|
|
indexEpisodeDigits = 4,
|
|
|
|
|
|
|
|
indicatorSeasonDigits = 2,
|
|
|
|
|
|
|
|
indicatorEpisodeDigits = 4
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cc: ConfigurationController = context['config'] if context is not None and 'config' in context.keys() else None
|
|
|
|
|
|
|
|
configData = cc.getData() if cc is not None else {}
|
|
|
|
|
|
|
|
outputFilenameTemplate = configData.get(ConfigurationController.OUTPUT_FILENAME_TEMPLATE_KEY,
|
|
|
|
|
|
|
|
DEFAULT_OUTPUT_FILENAME_TEMPLATE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if context is not None and 'logger' in context.keys():
|
|
|
|
|
|
|
|
logger = context['logger']
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
logger = logging.getLogger('FFX')
|
|
|
|
|
|
|
|
logger.addHandler(logging.NullHandler())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
indexSeparator = ' ' if indexSeasonDigits or indexEpisodeDigits else ''
|
|
|
|
|
|
|
|
seasonIndex = '{num:{fill}{width}}'.format(num=season, fill='0', width=indexSeasonDigits) if indexSeasonDigits else ''
|
|
|
|
|
|
|
|
episodeIndex = '{num:{fill}{width}}'.format(num=episode, fill='0', width=indexEpisodeDigits) if indexEpisodeDigits else ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
indicatorSeparator = ' - ' if indicatorSeasonDigits or indicatorEpisodeDigits else ''
|
|
|
|
|
|
|
|
seasonIndicator = 'S{num:{fill}{width}}'.format(num=season, fill='0', width=indicatorSeasonDigits) if indicatorSeasonDigits else ''
|
|
|
|
|
|
|
|
episodeIndicator = 'E{num:{fill}{width}}'.format(num=episode, fill='0', width=indicatorEpisodeDigits) if indicatorEpisodeDigits else ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jinjaKwargs = {
|
|
|
|
|
|
|
|
'ffx_show_name': showName,
|
|
|
|
|
|
|
|
'ffx_index_separator': indexSeparator,
|
|
|
|
|
|
|
|
'ffx_season_index': str(seasonIndex),
|
|
|
|
|
|
|
|
'ffx_episode_index': str(episodeIndex),
|
|
|
|
|
|
|
|
'ffx_index': str(seasonIndex) + str(episodeIndex),
|
|
|
|
|
|
|
|
'ffx_episode_name': episodeName,
|
|
|
|
|
|
|
|
'ffx_indicator_separator': indicatorSeparator,
|
|
|
|
|
|
|
|
'ffx_season_indicator': str(seasonIndicator),
|
|
|
|
|
|
|
|
'ffx_episode_indicator': str(episodeIndicator),
|
|
|
|
|
|
|
|
'ffx_indicator': str(seasonIndicator) + str(episodeIndicator)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jinjaEnv = Environment(undefined=EmptyStringUndefined)
|
|
|
|
|
|
|
|
jinjaTemplate = jinjaEnv.from_string(outputFilenameTemplate)
|
|
|
|
|
|
|
|
return jinjaTemplate.render(**jinjaKwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# return ''.join(filenameTokens)
|
|
|
|
|
|
|
|
|
|
|
|