Skip to content

Instantly share code, notes, and snippets.

@jeryjs
jeryjs / compress_epubs.py
Last active March 10, 2024 12:23
Compress epub files in batch. The script works recursively, and maintains the same input directory's file structure in the output directory. Usage: py ./compress_epubs.py 'path/to/epubs/dir' 'path/to/output/dir'
import argparse
import os
import shutil
import zipfile
from PIL import Image
# min filesize threshold in MB
FILE_THRESHOLD = 1.5
# image compression threshold in %
COMPRESSION_QUALITY = 80