Created
August 19, 2018 10:15
-
-
Save SunjunKim/4a13be21eeccbe001104c356b8eb4ba0 to your computer and use it in GitHub Desktop.
Epub font remover
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import glob | |
| import ruamel.std.zipfile as zipfile | |
| import re | |
| import os.path | |
| import os | |
| import shutil | |
| originalDir = 'Original' | |
| reducedDir = 'Reduced' | |
| files = glob.glob(originalDir+'/**/*.*', recursive='True') | |
| fontsDict = {} | |
| for filename in files: | |
| #print(filename) | |
| newfile = os.path.normpath(os.path.join(reducedDir, filename)) | |
| newDir = os.path.dirname(newfile) | |
| if os.path.isdir(filename): | |
| continue | |
| if not os.path.exists(newDir): | |
| os.makedirs(newDir) | |
| print("Processing", filename) | |
| if filename.endswith('epub'): | |
| zin = zipfile.ZipFile (filename, 'r') | |
| zout = zipfile.ZipFile (newfile, 'w') | |
| for item in zin.infolist(): | |
| buffer = zin.read(item.filename) | |
| if (item.filename[-4:] != '.ttf') and (item.filename[-4:] != '.otf'): | |
| zout.writestr(item, buffer) | |
| zout.close() | |
| zin.close() | |
| else: | |
| shutil.copy2(filename, newfile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment