Skip to content

Instantly share code, notes, and snippets.

@SunjunKim
Created August 19, 2018 10:15
Show Gist options
  • Select an option

  • Save SunjunKim/4a13be21eeccbe001104c356b8eb4ba0 to your computer and use it in GitHub Desktop.

Select an option

Save SunjunKim/4a13be21eeccbe001104c356b8eb4ba0 to your computer and use it in GitHub Desktop.
Epub font remover
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