Closed npow closed 1 year ago
Describe the bug Final filename can exceed 255 if template string includes another pattern in addition to the title, causing the program to crash.
To Reproduce Steps to reproduce the behavior:
file_name_template
"[%publish_date%] %title%.%file_extension%"
Expected behavior Program should not crash. Need to truncate expanded template.
Desktop (please complete the following information):
Additional context Checked the code. Looks like the truncation only applies to the title, and not the expanded template.
def str_to_filename(value: str) -> str: value = unicodedata.normalize("NFKC", value) value = re.sub(r"[\u0000-\u001F\u007F\*/:<>\?\\\|]", " ", value) return value.strip()[:FILE_NAME_CHARACTER_LIMIT] def file_template_to_file_name(name_template: str, entity: RSSEntity) -> str: return ( name_template.replace("%file_name%", link_to_file_name(entity.link)) .replace("%publish_date%", time.strftime("%Y%m%d", entity.published_date)) .replace("%file_extension%", link_to_extension(entity.link)) .replace("%title%", str_to_filename(entity.title)) )
Describe the bug Final filename can exceed 255 if template string includes another pattern in addition to the title, causing the program to crash.
To Reproduce Steps to reproduce the behavior:
file_name_template
to"[%publish_date%] %title%.%file_extension%"
. Download an episode with title longer than 255 chars.Expected behavior Program should not crash. Need to truncate expanded template.
Desktop (please complete the following information):
Additional context Checked the code. Looks like the truncation only applies to the title, and not the expanded template.