mirror of
https://github.com/ciromattia/kcc
synced 2025-12-19 04:31:50 +00:00
kindlesplit: Python3 update
This commit is contained in:
@@ -100,11 +100,11 @@ def nullsection(datain, secno): # make it zero-length without deleting it
|
|||||||
datalst.append(struct.pack('>L', ofs) + struct.pack('>L', flgval))
|
datalst.append(struct.pack('>L', ofs) + struct.pack('>L', flgval))
|
||||||
lpad = zerosecstart - (first_pdb_record + 8*nsec)
|
lpad = zerosecstart - (first_pdb_record + 8*nsec)
|
||||||
if lpad > 0:
|
if lpad > 0:
|
||||||
datalst.append('\0' * lpad)
|
datalst.append(b'\0' * lpad)
|
||||||
datalst.append(datain[zerosecstart: secstart])
|
datalst.append(datain[zerosecstart: secstart])
|
||||||
datalst.append(datain[secend:])
|
datalst.append(datain[secend:])
|
||||||
dataout = "".join(str(datalst)[1:-1])
|
dataout = b"".join(datalst)
|
||||||
return dataout.encode('utf-8')
|
return dataout
|
||||||
|
|
||||||
|
|
||||||
def deletesectionrange(datain, firstsec, lastsec): # delete a range of sections
|
def deletesectionrange(datain, firstsec, lastsec): # delete a range of sections
|
||||||
@@ -130,11 +130,11 @@ def deletesectionrange(datain, firstsec, lastsec): # delete a range of sections
|
|||||||
datalst.append(struct.pack('>L', ofs) + struct.pack('>L', flgval))
|
datalst.append(struct.pack('>L', ofs) + struct.pack('>L', flgval))
|
||||||
lpad = newstart - (first_pdb_record + 8*(nsec - (lastsec - firstsec + 1)))
|
lpad = newstart - (first_pdb_record + 8*(nsec - (lastsec - firstsec + 1)))
|
||||||
if lpad > 0:
|
if lpad > 0:
|
||||||
datalst.append('\0' * lpad)
|
datalst.append(b'\0' * lpad)
|
||||||
datalst.append(datain[zerosecstart:firstsecstart])
|
datalst.append(datain[zerosecstart:firstsecstart])
|
||||||
datalst.append(datain[lastsecend:])
|
datalst.append(datain[lastsecend:])
|
||||||
dataout = "".join(str(datalst)[1:-1])
|
dataout = b"".join(datalst)
|
||||||
return dataout.encode('utf-8')
|
return dataout
|
||||||
|
|
||||||
|
|
||||||
def insertsection(datain, secno, secdata): # insert a new section
|
def insertsection(datain, secno, secdata): # insert a new section
|
||||||
@@ -160,18 +160,17 @@ def insertsection(datain, secno, secdata): # insert a new section
|
|||||||
datalst.append(struct.pack('>L', ofs) + struct.pack('>L', flgval))
|
datalst.append(struct.pack('>L', ofs) + struct.pack('>L', flgval))
|
||||||
lpad = newstart - (first_pdb_record + 8*(nsec + 1))
|
lpad = newstart - (first_pdb_record + 8*(nsec + 1))
|
||||||
if lpad > 0:
|
if lpad > 0:
|
||||||
datalst.append('\0' * lpad)
|
datalst.append(b'\0' * lpad)
|
||||||
datalst.append(datain[zerosecstart:secstart])
|
datalst.append(datain[zerosecstart:secstart])
|
||||||
datalst.append(secdata)
|
datalst.append(secdata)
|
||||||
datalst.append(datain[secstart:])
|
datalst.append(datain[secstart:])
|
||||||
dataout = "".join(str(datalst)[1:-1])
|
dataout = b"".join(datalst)
|
||||||
return dataout.encode('utf-8')
|
return dataout
|
||||||
|
|
||||||
|
|
||||||
def insertsectionrange(sectionsource, firstsec, lastsec, sectiontarget, targetsec): # insert a range of sections
|
def insertsectionrange(sectionsource, firstsec, lastsec, sectiontarget, targetsec): # insert a range of sections
|
||||||
dataout = sectiontarget
|
dataout = sectiontarget
|
||||||
for idx in range(lastsec, firstsec-1, -1):
|
for idx in range(lastsec, firstsec-1, -1):
|
||||||
print(dataout)
|
|
||||||
dataout = insertsection(dataout, targetsec, readsection(sectionsource, idx))
|
dataout = insertsection(dataout, targetsec, readsection(sectionsource, idx))
|
||||||
return dataout
|
return dataout
|
||||||
|
|
||||||
@@ -287,7 +286,7 @@ class mobi_split:
|
|||||||
# datain_rec0 = del_exth(datain_rec0,534)
|
# datain_rec0 = del_exth(datain_rec0,534)
|
||||||
# don't remove the EXTH 125 KF8 Count of Resources, seems to be present in mobi6 files as well
|
# don't remove the EXTH 125 KF8 Count of Resources, seems to be present in mobi6 files as well
|
||||||
# set the EXTH 129 KF8 Masthead / Cover Image string to the null string
|
# set the EXTH 129 KF8 Masthead / Cover Image string to the null string
|
||||||
datain_rec0 = write_exth(datain_rec0, 129, '')
|
datain_rec0 = write_exth(datain_rec0, 129, b'')
|
||||||
# don't remove the EXTH 131 KF8 Unidentified Count, seems to be present in mobi6 files as well
|
# don't remove the EXTH 131 KF8 Unidentified Count, seems to be present in mobi6 files as well
|
||||||
|
|
||||||
# Make sure we have an ASIN & cdeType set...
|
# Make sure we have an ASIN & cdeType set...
|
||||||
|
|||||||
Reference in New Issue
Block a user