Skip to content

Commit

Permalink
tools v3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
apprenticealf committed Mar 5, 2015
1 parent bc968f8 commit 8b632e3
Show file tree
Hide file tree
Showing 38 changed files with 462 additions and 1,374 deletions.
11 changes: 10 additions & 1 deletion Calibre_Plugins/K4MobiDeDRM_plugin/flatxml2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def extract(path, key):
ys = []
gdefs = []

# get path defintions, positions, dimensions for ecah glyph
# get path defintions, positions, dimensions for each glyph
# that makes up the image, and find min x and min y to reposition origin
minx = -1
miny = -1
Expand Down Expand Up @@ -305,6 +305,15 @@ def getParaDescription(self, start, end, regtype):
lastGlyph = firstglyphList[last]
else :
lastGlyph = len(gidList)

# handle case of white sapce paragraphs with no actual glyphs in them
# by reverting to text based paragraph
if firstGlyph >= lastGlyph:
# revert to standard text based paragraph
for wordnum in xrange(first, last):
result.append(('ocr', wordnum))
return pclass, result

for glyphnum in xrange(firstGlyph, lastGlyph):
glyphList.append(glyphnum)
# include any extratokens if they exist
Expand Down
Binary file modified Calibre_Plugins/eReaderPDB2PML_plugin.zip
Binary file not shown.
114 changes: 55 additions & 59 deletions Calibre_Plugins/eReaderPDB2PML_plugin/erdr2pml.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@
# 0.16 - convert to use openssl DES (very very fast) or pure python DES if openssl's libcrypto is not available
# 0.17 - added support for pycrypto's DES as well
# 0.18 - on Windows try PyCrypto first and OpenSSL next
# 0.19 - Modify the interface to allow use of import

__version__='0.18'
__version__='0.19'

class Unbuffered:
def __init__(self, stream):
Expand Down Expand Up @@ -111,12 +112,14 @@ def __getattr__(self, attr):
# older Python release
import sha
sha1 = lambda s: sha.new(s)

import cgi
import logging

logging.basicConfig()
#logging.basicConfig(level=logging.DEBUG)


class Sectionizer(object):
def __init__(self, filename, ident):
self.contents = file(filename, 'rb').read()
Expand Down Expand Up @@ -364,7 +367,7 @@ def cleanPML(pml):
def convertEreaderToPml(infile, name, cc, outdir):
if not os.path.exists(outdir):
os.makedirs(outdir)

bookname = os.path.splitext(os.path.basename(infile))[0]
print " Decoding File"
sect = Sectionizer(infile, 'PNRdPPrs')
er = EreaderProcessor(sect.loadSection, name, cc)
Expand All @@ -390,6 +393,47 @@ def convertEreaderToPml(infile, name, cc, outdir):
# file(os.path.join(outdir, 'bookinfo.txt'),'wb').write(bkinfo)



def decryptBook(infile, outdir, name, cc, make_pmlz):
if make_pmlz :
# ignore specified outdir, use tempdir instead
outdir = tempfile.mkdtemp()
try:
print "Processing..."
convertEreaderToPml(infile, name, cc, outdir)
if make_pmlz :
import zipfile
import shutil
print " Creating PMLZ file"
zipname = infile[:-4] + '.pmlz'
myZipFile = zipfile.ZipFile(zipname,'w',zipfile.ZIP_STORED, False)
list = os.listdir(outdir)
for file in list:
localname = file
filePath = os.path.join(outdir,file)
if os.path.isfile(filePath):
myZipFile.write(filePath, localname)
elif os.path.isdir(filePath):
imageList = os.listdir(filePath)
localimgdir = os.path.basename(filePath)
for image in imageList:
localname = os.path.join(localimgdir,image)
imagePath = os.path.join(filePath,image)
if os.path.isfile(imagePath):
myZipFile.write(imagePath, localname)
myZipFile.close()
# remove temporary directory
shutil.rmtree(outdir, True)
print 'output is %s' % zipname
else :
print 'output in %s' % outdir
print "done"
except ValueError, e:
print "Error: %s" % e
return 1
return 0


def usage():
print "Converts DRMed eReader books to PML Source"
print "Usage:"
Expand All @@ -404,84 +448,36 @@ def usage():
print " It's enough to enter the last 8 digits of the credit card number"
return


def main(argv=None):
global bookname
try:
opts, args = getopt.getopt(sys.argv[1:], "h", ["make-pmlz"])
except getopt.GetoptError, err:
print str(err)
usage()
return 1
make_pmlz = False
zipname = None
for o, a in opts:
if o == "-h":
usage()
return 0
elif o == "--make-pmlz":
make_pmlz = True
zipname = ''

print "eRdr2Pml v%s. Copyright (c) 2009 The Dark Reverser" % __version__

if len(args)!=3 and len(args)!=4:
usage()
return 1
else:
if len(args)==3:
infile, name, cc = args[0], args[1], args[2]
outdir = infile[:-4] + '_Source'
elif len(args)==4:
infile, outdir, name, cc = args[0], args[1], args[2], args[3]

if make_pmlz :
# ignore specified outdir, use tempdir instead
outdir = tempfile.mkdtemp()

bookname = os.path.splitext(os.path.basename(infile))[0]

try:
print "Processing..."
import time
start_time = time.time()
convertEreaderToPml(infile, name, cc, outdir)

if make_pmlz :
import zipfile
import shutil
print " Creating PMLZ file"
zipname = infile[:-4] + '.pmlz'
myZipFile = zipfile.ZipFile(zipname,'w',zipfile.ZIP_STORED, False)
list = os.listdir(outdir)
for file in list:
localname = file
filePath = os.path.join(outdir,file)
if os.path.isfile(filePath):
myZipFile.write(filePath, localname)
elif os.path.isdir(filePath):
imageList = os.listdir(filePath)
localimgdir = os.path.basename(filePath)
for image in imageList:
localname = os.path.join(localimgdir,image)
imagePath = os.path.join(filePath,image)
if os.path.isfile(imagePath):
myZipFile.write(imagePath, localname)
myZipFile.close()
# remove temporary directory
shutil.rmtree(outdir, True)

end_time = time.time()
search_time = end_time - start_time
print 'elapsed time: %.2f seconds' % (search_time, )
if make_pmlz :
print 'output is %s' % zipname
else :
print 'output in %s' % outdir
print "done"
except ValueError, e:
print "Error: %s" % e
return 1
return 0
if len(args)==3:
infile, name, cc = args[0], args[1], args[2]
outdir = infile[:-4] + '_Source'
elif len(args)==4:
infile, outdir, name, cc = args[0], args[1], args[2], args[3]

return decryptBook(infile, outdir, name, cc, make_pmlz)


if __name__ == "__main__":
sys.exit(main())
Expand Down
Binary file modified Calibre_Plugins/ignobleepub_plugin.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion Calibre_Plugins/ignobleepub_plugin/ignobleepub_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class IgnobleDeDRM(FileTypePlugin):
Credit given to I <3 Cabbages for the original stand-alone scripts.'
supported_platforms = ['linux', 'osx', 'windows']
author = 'DiapDealer'
version = (0, 1, 3)
version = (0, 1, 4)
minimum_calibre_version = (0, 6, 44) # Compiled python libraries cannot be imported in earlier versions.
file_types = set(['epub'])
on_import = True
Expand Down
74 changes: 49 additions & 25 deletions Calibre_Plugins/ignobleepub_plugin/zipfix.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,44 @@ def fix(self):
# get the zipinfo for each member of the input archive
# and copy member over to output archive
# if problems exist with local vs central filename, fix them

for i, zinfo in enumerate(self.inzip.infolist()):
data = None
nzinfo = zinfo

try:
data = self.inzip.read(zinfo)
except zipfile.BadZipfile or zipfile.error:
local_name = self.getlocalname(zinfo)
data = self.getfiledata(zinfo)
nzinfo.filename = local_name

nzinfo.date_time = zinfo.date_time
nzinfo.compress_type = zinfo.compress_type
nzinfo.flag_bits = 0
nzinfo.internal_attr = 0
self.outzip.writestr(nzinfo,data)
# also fix bad epub compression

# write mimetype file first, if present, and with no compression
for zinfo in self.inzip.infolist():
if zinfo.filename == "mimetype":
nzinfo = zinfo
try:
data = self.inzip.read(zinfo.filename)
except zipfile.BadZipfile or zipfile.error:
local_name = self.getlocalname(zinfo)
data = self.getfiledata(zinfo)
nzinfo.filename = local_name

nzinfo.date_time = zinfo.date_time
nzinfo.compress_type = zipfile.ZIP_STORED
nzinfo.flag_bits = 0
nzinfo.internal_attr = 0
nzinfo.extra = ""
self.outzip.writestr(nzinfo,data)
break

# write the rest of the files
for zinfo in self.inzip.infolist():
if zinfo.filename != "mimetype":
data = None
nzinfo = zinfo
try:
data = self.inzip.read(zinfo.filename)
except zipfile.BadZipfile or zipfile.error:
local_name = self.getlocalname(zinfo)
data = self.getfiledata(zinfo)
nzinfo.filename = local_name

nzinfo.date_time = zinfo.date_time
nzinfo.compress_type = zinfo.compress_type
nzinfo.flag_bits = 0
nzinfo.internal_attr = 0
self.outzip.writestr(nzinfo,data)

self.bzf.close()
self.inzip.close()
Expand All @@ -111,14 +132,7 @@ def usage():
"""


def main(argv=sys.argv):
if len(argv)!=3:
usage()
return 1
infile = None
outfile = None
infile = argv[1]
outfile = argv[2]
def repairBook(infile, outfile):
if not os.path.exists(infile):
print "Error: Input Zip File does not exist"
return 1
Expand All @@ -130,6 +144,16 @@ def main(argv=sys.argv):
print "Error Occurred ", e
return 2


def main(argv=sys.argv):
if len(argv)!=3:
usage()
return 1
infile = argv[1]
outfile = argv[2]
return repairBook(infile, outfile)


if __name__ == '__main__' :
sys.exit(main())

Expand Down
Binary file modified Calibre_Plugins/ineptepub_plugin.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion Calibre_Plugins/ineptepub_plugin/ineptepub_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class IneptDeDRM(FileTypePlugin):
Credit given to I <3 Cabbages for the original stand-alone scripts.'
supported_platforms = ['linux', 'osx', 'windows']
author = 'DiapDealer'
version = (0, 1, 4)
version = (0, 1, 5)
minimum_calibre_version = (0, 6, 44) # Compiled python libraries cannot be imported in earlier versions.
file_types = set(['epub'])
on_import = True
Expand Down
Loading

0 comments on commit 8b632e3

Please sign in to comment.