Skip to content

Commit

Permalink
simplify cover upload on newer MTP based Kindles by replacing EBOK wi…
Browse files Browse the repository at this point in the history
…th PDOC (#767)

* simplify covers by replacing ebok with pdoc

* refactor

* fix order
  • Loading branch information
axu2 authored Nov 8, 2024
1 parent 421e6bc commit 78c014b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion kindlecomicconverter/KCC_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def run(self):
except Exception:
pass
MW.addMessage.emit('Processing MOBI files... <b>Done!</b>', 'info', True)
k = kindle.Kindle()
k = kindle.Kindle(options.profile)
if k.path and k.coverSupport:
for item in outputPath:
comic2ebook.options.covers[outputPath.index(item)][0].saveToKindle(
Expand Down
5 changes: 3 additions & 2 deletions kindlecomicconverter/comic2ebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ def makeBook(source, qtgui=None):
print('Error: KindleGen failed to create MOBI!')
print(errors)
return filepath
k = kindle.Kindle()
k = kindle.Kindle(options.profile)
if k.path and k.coverSupport:
print("Kindle detected. Uploading covers...")
for i in filepath:
Expand All @@ -1249,12 +1249,13 @@ def makeBook(source, qtgui=None):


def makeMOBIFix(item, uuid):
is_pdoc = options.profile in image.ProfileData.ProfilesKindlePDOC.keys()
if not options.keep_epub:
os.remove(item)
mobiPath = item.replace('.epub', '.mobi')
move(mobiPath, mobiPath + '_toclean')
try:
dualmetafix.DualMobiMetaFix(mobiPath + '_toclean', mobiPath, bytes(uuid, 'UTF-8'))
dualmetafix.DualMobiMetaFix(mobiPath + '_toclean', mobiPath, bytes(uuid, 'UTF-8'), is_pdoc)
return [True]
except Exception as err:
return [False, format(err)]
Expand Down
10 changes: 7 additions & 3 deletions kindlecomicconverter/dualmetafix.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ def del_exth(rec0, exth_num):


class DualMobiMetaFix:
def __init__(self, infile, outfile, asin):
def __init__(self, infile, outfile, asin, is_pdoc):
cdetype = b'EBOK'
if is_pdoc:
cdetype = b'PDOC'

shutil.copyfile(infile, outfile)
f = open(outfile, "r+b")
self.datain = mmap.mmap(f.fileno(), 0)
Expand All @@ -147,7 +151,7 @@ def __init__(self, infile, outfile, asin):
rec0 = self.datain_rec0
rec0 = del_exth(rec0, 501)
rec0 = del_exth(rec0, 113)
rec0 = add_exth(rec0, 501, b'EBOK')
rec0 = add_exth(rec0, 501, cdetype)
rec0 = add_exth(rec0, 113, asin)
replacesection(self.datain, 0, rec0)

Expand All @@ -174,7 +178,7 @@ def __init__(self, infile, outfile, asin):
rec0 = self.datain_kfrec0
rec0 = del_exth(rec0, 501)
rec0 = del_exth(rec0, 113)
rec0 = add_exth(rec0, 501, b'EBOK')
rec0 = add_exth(rec0, 501, cdetype)
rec0 = add_exth(rec0, 113, asin)
replacesection(self.datain, datain_kf8, rec0)

Expand Down
7 changes: 6 additions & 1 deletion kindlecomicconverter/kindle.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,21 @@
import os.path
import psutil

from . import image


class Kindle:
def __init__(self):
def __init__(self, profile):
self.profile = profile
self.path = self.findDevice()
if self.path:
self.coverSupport = self.checkThumbnails()
else:
self.coverSupport = False

def findDevice(self):
if self.profile in image.ProfileData.ProfilesKindlePDOC.keys():
return False
for drive in reversed(psutil.disk_partitions(False)):
if (drive[2] == 'FAT32' and drive[3] == 'rw,removable') or \
(drive[2] in ('vfat', 'msdos', 'FAT', 'apfs') and 'rw' in drive[3]):
Expand Down

0 comments on commit 78c014b

Please sign in to comment.