Skip to content

Commit

Permalink
fix: tested with proper ComicInfo.xml file, added additional checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Ger4ldK committed Oct 11, 2023
1 parent bcb2d31 commit 521a3dd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
23 changes: 13 additions & 10 deletions kindlecomicconverter/comic2ebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,8 @@ def buildEPUB(path, chapternames, tomenumber):
elif options.splitter == 2:
diff_delta = 2

if options.hasspreadpages:
# indicates that 2 page spreads exist and are merged in the source file
if diff_delta > 0:
if options.spreadadjust:
if (options.splitter == 0 or options.splitter == 2):
diff_delta -= 1

for aChapter in options.chapters:
Expand All @@ -541,7 +540,7 @@ def buildEPUB(path, chapternames, tomenumber):
if'-kcc-b' in filelist[x][1]:
pageid += diff_delta
global_diff += diff_delta
if options.hasspreadpages and options.splitter == 1 and '-kcc-a' in filelist[x][1]:
if options.spreadadjust and options.splitter == 1 and '-kcc-a' in filelist[x][1]:
pageid -= 1
global_diff -= 1

Expand Down Expand Up @@ -597,8 +596,9 @@ def imgFileProcessingTick(output):
if page is not None:
options.imgMetadata[page[0]] = page[1]
options.imgOld.append(page[2])
if not options.hasspreadpages:
options.hasspreadpages = output[1]
# options.doublepageattribute is True when there is a DoublePage attribute already found in the xml
if not options.doublepageattribute and not options.spreadadjust:
options.spreadadjust = output[1]
if GUI:
GUI.progressBarTick.emit('tick')
if not GUI.conversionAlive:
Expand All @@ -612,7 +612,7 @@ def imgFileProcessing(work):
opt = work[2]
output = []
workImg = image.ComicPageParser((dirpath, afile), opt)
hasspreadpages = workImg.opt.hasspreadpages
spreadadjust = workImg.opt.spreadadjust
for i in workImg.payload:
img = image.ComicPage(opt, *i)
if opt.cropping == 2 and not opt.webtoon:
Expand All @@ -624,7 +624,7 @@ def imgFileProcessing(work):
if opt.forcepng and not opt.forcecolor:
img.quantizeImage()
output.append(img.saveToDir())
return [output, hasspreadpages]
return [output, spreadadjust]
except Exception:
return str(sys.exc_info()[1]), sanitizeTrace(sys.exc_info()[2])

Expand Down Expand Up @@ -706,6 +706,9 @@ def getComicInfo(path, originalpath):
xmlPath = os.path.join(path, 'ComicInfo.xml')
options.authors = ['KCC']
options.chapters = []
options.doublepageattribute = False
# toggled only when splitCheck finds spread pages in source files AND the ComicInfo.xml does not find a DoublePage attribute in Pages list
options.spreadadjust = False
options.summary = ''
titleSuffix = ''
if options.title == 'defaulttitle':
Expand Down Expand Up @@ -743,6 +746,8 @@ def getComicInfo(path, originalpath):
options.authors = ['KCC']
if xml.data['Bookmarks']:
options.chapters = xml.data['Bookmarks']
if xml.data['DoublePages']:
options.doublepageattribute = xml.data['DoublePages']
if xml.data['Summary']:
options.summary = hescape(xml.data['Summary'])
os.remove(xmlPath)
Expand Down Expand Up @@ -1109,8 +1114,6 @@ def checkOptions(options):
if options.profile == 'KS' and (options.format == 'MOBI' or options.format == 'EPUB'):
options.profileData = list(options.profileData)
options.profileData[1] = (1440, 1920)
# flag if source file contains spread pages, set to True when a split check is done
options.hasspreadpages = False
return options


Expand Down
2 changes: 1 addition & 1 deletion kindlecomicconverter/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def splitCheck(self):
if self.opt.splitter > 0:
self.payload.append(['R', self.source, self.image.rotate(90, Image.Resampling.BICUBIC, True),
self.color, self.fill])
self.opt.hasspreadpages = True
self.opt.spreadadjust = True
else:
self.payload.append(['N', self.source, self.image, self.color, self.fill])

Expand Down
3 changes: 3 additions & 0 deletions kindlecomicconverter/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self, source):
'Colorists': [],
'Summary': '',
'Bookmarks': [],
'DoublePages': False,
'Title': ''}
self.rawdata = None
self.format = None
Expand Down Expand Up @@ -72,6 +73,8 @@ def parseXML(self):
if 'Bookmark' in page.attributes and 'Image' in page.attributes:
self.data['Bookmarks'].append((int(page.attributes['Image'].value),
page.attributes['Bookmark'].value))
if 'DoublePage' in page.attributes:
self.data['DoublePages'] = True

def saveXML(self):
if self.rawdata:
Expand Down

0 comments on commit 521a3dd

Please sign in to comment.