Beispiel #1
0
def GetDecryptedBook(infile, kInfoFiles, serials, pids, starttime = time.time()):
    # handle the obvious cases at the beginning
    if not os.path.isfile(infile):
        raise DRMException (u"Input file does not exist.")

    mobi = True
    magic3 = file(infile,'rb').read(3)
    if magic3 == 'TPZ':
        mobi = False

    if mobi:
        mb = mobidedrm.MobiBook(infile)
    else:
        mb = topazextract.TopazBook(infile)

    bookname = unescape(mb.getBookTitle())
    print u"Decrypting {1} ebook: {0}".format(bookname, mb.getBookType())

    # extend PID list with book-specific PIDs
    md1, md2 = mb.getPIDMetaInfo()
    pids.extend(kgenpids.getPidList(md1, md2, serials, kInfoFiles))
    print u"Found {1:d} keys to try after {0:.1f} seconds".format(time.time()-starttime, len(pids))

    try:
        mb.processBook(pids)
    except:
        mb.cleanup
        raise

    print u"Decryption succeeded after {0:.1f} seconds".format(time.time()-starttime)
    return mb
Beispiel #2
0
def decryptBook(infile, outdir, k4, kInfoFiles, serials, pids):
    # handle the obvious cases at the beginning
    if not os.path.isfile(infile):
        print "Error: Input file does not exist"
        return 1

    mobi = True
    magic3 = file(infile,'rb').read(3)
    if magic3 == 'TPZ':
        mobi = False

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

    if mobi:
        mb = mobidedrm.MobiBook(infile)
    else:
        mb = topazextract.TopazBook(infile)

    title = mb.getBookTitle()
    print "Processing Book: ", title
    filenametitle = cleanup_name(title)
    outfilename = bookname
    if len(bookname)>4 and len(filenametitle)>4 and bookname[:4] != filenametitle[:4]:
        outfilename = outfilename + "_" + filenametitle

    # build pid list
    md1, md2 = mb.getPIDMetaInfo()
    pidlst = kgenpids.getPidList(md1, md2, k4, pids, serials, kInfoFiles) 

    try:
        mb.processBook(pidlst)

    except mobidedrm.DrmException, e:
        print "Error: " + str(e) + "\nDRM Removal Failed.\n"
        return 1
def decryptBook(infile, outdir, k4, kInfoFiles, serials, pids):
    global buildXML


    # handle the obvious cases at the beginning
    if not os.path.isfile(infile):
        print >>sys.stderr, ('K4MobiDeDrm v%(__version__)s\n' % globals()) + "Error: Input file does not exist"
        return 1

    starttime = time.time()
    print "Starting decryptBook routine."


    mobi = True
    magic3 = file(infile,'rb').read(3)
    if magic3 == 'TPZ':
        mobi = False

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

    if mobi:
        mb = mobidedrm.MobiBook(infile)
    else:
        mb = topazextract.TopazBook(infile)

    title = mb.getBookTitle()
    print "Processing Book: ", title
    filenametitle = cleanup_name(title)
    outfilename = cleanup_name(bookname)

    # generate 'sensible' filename, that will sort with the original name,
    # but is close to the name from the file.
    outlength = len(outfilename)
    comparelength = min(8,min(outlength,len(filenametitle)))
    copylength = min(max(outfilename.find(' '),8),len(outfilename))
    if outlength==0:
        outfilename = filenametitle
    elif comparelength > 0:
    	if outfilename[:comparelength] == filenametitle[:comparelength]:
        	outfilename = filenametitle
        else:
        	outfilename = outfilename[:copylength] + " " + filenametitle

    # avoid excessively long file names
    if len(outfilename)>150:
        outfilename = outfilename[:150]

    # build pid list
    md1, md2 = mb.getPIDMetaInfo()
    pids.extend(kgenpids.getPidList(md1, md2, k4, serials, kInfoFiles))

    print "Found {1:d} keys to try after {0:.1f} seconds".format(time.time()-starttime, len(pids))


    try:
        mb.processBook(pids)

    except mobidedrm.DrmException, e:
        print >>sys.stderr, ('K4MobiDeDrm v%(__version__)s\n' % globals()) + "Error: " + str(e) + "\nDRM Removal Failed.\n"
        print "Failed to decrypted book after {0:.1f} seconds".format(time.time()-starttime)
        return 1
    k4 = True

    infile = args[0]
    outdir = args[1]

    if not os.path.isfile(infile):
        print "Input File Does Not Exist"
        return 1

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

    tb = TopazBook(infile)
    title = tb.getBookTitle()
    print "Processing Book: ", title
    keysRecord, keysRecordRecord = tb.getPIDMetaInfo()
    pids.extend(kgenpids.getPidList(keysRecord, keysRecordRecord, k4, serials, kInfoFiles))

    try:
        print "Decrypting Book"
        tb.processBook(pids)

        print "   Creating HTML ZIP Archive"
        zipname = os.path.join(outdir, bookname + '_nodrm' + '.htmlz')
        tb.getHTMLZip(zipname)

        print "   Creating SVG ZIP Archive"
        zipname = os.path.join(outdir, bookname + '_SVG' + '.zip')
        tb.getSVGZip(zipname)

        if buildXML:
            print "   Creating XML ZIP Archive"
Beispiel #5
0
        if o == '-p':
            if a == None :
                raise DrmException("Invalid parameter for -p")
            pids = a.split(',')
        if o == '-s':
            if a == None :
                raise DrmException("Invalid parameter for -s")
            serials = [serial.replace(" ","") for serial in a.split(',')]

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

    tb = TopazBook(infile)
    title = tb.getBookTitle()
    print u"Processing Book: {0}".format(title)
    md1, md2 = tb.getPIDMetaInfo()
    pids.extend(kgenpids.getPidList(md1, md2, serials, kInfoFiles))

    try:
        print u"Decrypting Book"
        tb.processBook(pids)

        print u"   Creating HTML ZIP Archive"
        zipname = os.path.join(outdir, bookname + u"_nodrm.htmlz")
        tb.getFile(zipname)

        print u"   Creating SVG ZIP Archive"
        zipname = os.path.join(outdir, bookname + u"_SVG.zip")
        tb.getSVGZip(zipname)

        # removing internal temporary directory of pieces
        tb.cleanup()
Beispiel #6
0
    k4 = True

    infile = args[0]
    outdir = args[1]

    if not os.path.isfile(infile):
        print "Input File Does Not Exist"
        return 1

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

    tb = TopazBook(infile)
    title = tb.getBookTitle()
    print "Processing Book: ", title
    keysRecord, keysRecordRecord = tb.getPIDMetaInfo()
    pidlst = kgenpids.getPidList(keysRecord, keysRecordRecord, k4, pids,
                                 serials, kInfoFiles)

    try:
        print "Decrypting Book"
        tb.processBook(pidlst)

        print "   Creating HTML ZIP Archive"
        zipname = os.path.join(outdir, bookname + '_nodrm' + '.htmlz')
        tb.getHTMLZip(zipname)

        print "   Creating SVG ZIP Archive"
        zipname = os.path.join(outdir, bookname + '_SVG' + '.htmlz')
        tb.getSVGZip(zipname)

        print "   Creating XML ZIP Archive"
        zipname = os.path.join(outdir, bookname + '_XML' + '.zip')
Beispiel #7
0
    k4 = True

    infile = args[0]
    outdir = args[1]

    if not os.path.isfile(infile):
        print "Input File Does Not Exist"
        return 1

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

    tb = TopazBook(infile)
    title = tb.getBookTitle()
    print "Processing Book: ", title
    keysRecord, keysRecordRecord = tb.getPIDMetaInfo()
    pidlst = kgenpids.getPidList(keysRecord, keysRecordRecord, k4, pids, serials, kInfoFiles) 

    try:
        print "Decrypting Book"
        tb.processBook(pidlst)

        print "   Creating HTML ZIP Archive"
        zipname = os.path.join(outdir, bookname + '_nodrm' + '.htmlz')
        tb.getHTMLZip(zipname)

        print "   Creating SVG ZIP Archive"
        zipname = os.path.join(outdir, bookname + '_SVG' + '.htmlz')
        tb.getSVGZip(zipname)

        print "   Creating XML ZIP Archive"
        zipname = os.path.join(outdir, bookname + '_XML' + '.zip')