mirror of
https://github.com/ciromattia/kcc
synced 2025-12-12 17:26:23 +00:00
simplify cover upload on newer MTP based Kindles by replacing EBOK with PDOC (#767)
* simplify covers by replacing ebok with pdoc * refactor * fix order
This commit is contained in:
@@ -380,7 +380,7 @@ class WorkerThread(QtCore.QThread):
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
MW.addMessage.emit('Processing MOBI files... <b>Done!</b>', 'info', True)
|
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:
|
if k.path and k.coverSupport:
|
||||||
for item in outputPath:
|
for item in outputPath:
|
||||||
comic2ebook.options.covers[outputPath.index(item)][0].saveToKindle(
|
comic2ebook.options.covers[outputPath.index(item)][0].saveToKindle(
|
||||||
|
|||||||
@@ -1227,7 +1227,7 @@ def makeBook(source, qtgui=None):
|
|||||||
print('Error: KindleGen failed to create MOBI!')
|
print('Error: KindleGen failed to create MOBI!')
|
||||||
print(errors)
|
print(errors)
|
||||||
return filepath
|
return filepath
|
||||||
k = kindle.Kindle()
|
k = kindle.Kindle(options.profile)
|
||||||
if k.path and k.coverSupport:
|
if k.path and k.coverSupport:
|
||||||
print("Kindle detected. Uploading covers...")
|
print("Kindle detected. Uploading covers...")
|
||||||
for i in filepath:
|
for i in filepath:
|
||||||
@@ -1249,12 +1249,13 @@ def makeBook(source, qtgui=None):
|
|||||||
|
|
||||||
|
|
||||||
def makeMOBIFix(item, uuid):
|
def makeMOBIFix(item, uuid):
|
||||||
|
is_pdoc = options.profile in image.ProfileData.ProfilesKindlePDOC.keys()
|
||||||
if not options.keep_epub:
|
if not options.keep_epub:
|
||||||
os.remove(item)
|
os.remove(item)
|
||||||
mobiPath = item.replace('.epub', '.mobi')
|
mobiPath = item.replace('.epub', '.mobi')
|
||||||
move(mobiPath, mobiPath + '_toclean')
|
move(mobiPath, mobiPath + '_toclean')
|
||||||
try:
|
try:
|
||||||
dualmetafix.DualMobiMetaFix(mobiPath + '_toclean', mobiPath, bytes(uuid, 'UTF-8'))
|
dualmetafix.DualMobiMetaFix(mobiPath + '_toclean', mobiPath, bytes(uuid, 'UTF-8'), is_pdoc)
|
||||||
return [True]
|
return [True]
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
return [False, format(err)]
|
return [False, format(err)]
|
||||||
|
|||||||
@@ -136,7 +136,11 @@ def del_exth(rec0, exth_num):
|
|||||||
|
|
||||||
|
|
||||||
class DualMobiMetaFix:
|
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)
|
shutil.copyfile(infile, outfile)
|
||||||
f = open(outfile, "r+b")
|
f = open(outfile, "r+b")
|
||||||
self.datain = mmap.mmap(f.fileno(), 0)
|
self.datain = mmap.mmap(f.fileno(), 0)
|
||||||
@@ -147,7 +151,7 @@ class DualMobiMetaFix:
|
|||||||
rec0 = self.datain_rec0
|
rec0 = self.datain_rec0
|
||||||
rec0 = del_exth(rec0, 501)
|
rec0 = del_exth(rec0, 501)
|
||||||
rec0 = del_exth(rec0, 113)
|
rec0 = del_exth(rec0, 113)
|
||||||
rec0 = add_exth(rec0, 501, b'EBOK')
|
rec0 = add_exth(rec0, 501, cdetype)
|
||||||
rec0 = add_exth(rec0, 113, asin)
|
rec0 = add_exth(rec0, 113, asin)
|
||||||
replacesection(self.datain, 0, rec0)
|
replacesection(self.datain, 0, rec0)
|
||||||
|
|
||||||
@@ -174,7 +178,7 @@ class DualMobiMetaFix:
|
|||||||
rec0 = self.datain_kfrec0
|
rec0 = self.datain_kfrec0
|
||||||
rec0 = del_exth(rec0, 501)
|
rec0 = del_exth(rec0, 501)
|
||||||
rec0 = del_exth(rec0, 113)
|
rec0 = del_exth(rec0, 113)
|
||||||
rec0 = add_exth(rec0, 501, b'EBOK')
|
rec0 = add_exth(rec0, 501, cdetype)
|
||||||
rec0 = add_exth(rec0, 113, asin)
|
rec0 = add_exth(rec0, 113, asin)
|
||||||
replacesection(self.datain, datain_kf8, rec0)
|
replacesection(self.datain, datain_kf8, rec0)
|
||||||
|
|
||||||
|
|||||||
@@ -19,9 +19,12 @@
|
|||||||
import os.path
|
import os.path
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
|
from . import image
|
||||||
|
|
||||||
|
|
||||||
class Kindle:
|
class Kindle:
|
||||||
def __init__(self):
|
def __init__(self, profile):
|
||||||
|
self.profile = profile
|
||||||
self.path = self.findDevice()
|
self.path = self.findDevice()
|
||||||
if self.path:
|
if self.path:
|
||||||
self.coverSupport = self.checkThumbnails()
|
self.coverSupport = self.checkThumbnails()
|
||||||
@@ -29,6 +32,8 @@ class Kindle:
|
|||||||
self.coverSupport = False
|
self.coverSupport = False
|
||||||
|
|
||||||
def findDevice(self):
|
def findDevice(self):
|
||||||
|
if self.profile in image.ProfileData.ProfilesKindlePDOC.keys():
|
||||||
|
return False
|
||||||
for drive in reversed(psutil.disk_partitions(False)):
|
for drive in reversed(psutil.disk_partitions(False)):
|
||||||
if (drive[2] == 'FAT32' and drive[3] == 'rw,removable') or \
|
if (drive[2] == 'FAT32' and drive[3] == 'rw,removable') or \
|
||||||
(drive[2] in ('vfat', 'msdos', 'FAT', 'apfs') and 'rw' in drive[3]):
|
(drive[2] in ('vfat', 'msdos', 'FAT', 'apfs') and 'rw' in drive[3]):
|
||||||
|
|||||||
Reference in New Issue
Block a user