INNER CODE UNIT · Python
sanitize_filename
cognitivetech/ollama-ebook-summary · book2text.py:14
def sanitize_filename(filename):
# Remove or replace unsafe characters
filename = re.sub(r'[<>:"/\\|?*]', '_', filename)
# Trim spaces and periods from the end
filename = filename.rstrip('. ')
# Ensure the filename isn't empty and doesn't exceed max length
filename = filename[:255] or 'untitled'
return filename
def split_epub_by_sections(input_file, output_dir):
"""
Split an EPUB file into multiple EPUBs by sections/chapters.
Args: