-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix list index out of range for comicrack #604
Changes from all commits
d2f060d
d33decd
6131e23
d105f93
bcb2d31
521a3dd
204deec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -513,6 +513,7 @@ def buildEPUB(path, chapternames, tomenumber): | |
tomenumber), options.uuid)) | ||
# Overwrite chapternames if tree is flat and ComicInfo.xml has bookmarks | ||
if not chapternames and options.chapters: | ||
filelen = len(filelist) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just use |
||
chapterlist = [] | ||
|
||
global_diff = 0 | ||
|
@@ -525,16 +526,25 @@ def buildEPUB(path, chapternames, tomenumber): | |
elif options.splitter == 2: | ||
diff_delta = 2 | ||
|
||
if options.spreadadjust and options.splitter != 1: | ||
diff_delta -= 1 | ||
|
||
for aChapter in options.chapters: | ||
pageid = aChapter[0] | ||
cur_diff = global_diff | ||
global_diff = 0 | ||
|
||
for x in range(0, pageid + cur_diff + 1): | ||
if '-kcc-b' in filelist[x][1]: | ||
pageid += diff_delta | ||
global_diff += diff_delta | ||
|
||
if x < filelen: | ||
if '-kcc-b' in filelist[x][1]: | ||
pageid += diff_delta | ||
global_diff += diff_delta | ||
if options.spreadadjust and options.splitter == 1 and '-kcc-a' in filelist[x][1]: | ||
pageid -= 1 | ||
global_diff -= 1 | ||
|
||
if pageid >= filelen: | ||
pageid = filelen - 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pageid = min(pageid, len(filelist) -1) I assume this is the code related to bookmarks near the end? Add a clarifying comment. Moreover, probably should just use len(filelist) since you are using the var less often. |
||
filename = filelist[pageid][1] | ||
chapterlist.append((filelist[pageid][0].replace('Images', 'Text'), filename)) | ||
chapternames[filename] = aChapter[1] | ||
|
@@ -576,7 +586,8 @@ def imgDirectoryProcessing(path): | |
raise UserWarning("Source directory is empty.") | ||
|
||
|
||
def imgFileProcessingTick(output): | ||
def imgFileProcessingTick(result): | ||
output, spreadadjust = result | ||
if isinstance(output, tuple): | ||
workerOutput.append(output) | ||
workerPool.terminate() | ||
|
@@ -585,6 +596,9 @@ def imgFileProcessingTick(output): | |
if page is not None: | ||
options.imgMetadata[page[0]] = page[1] | ||
options.imgOld.append(page[2]) | ||
# 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 = spreadadjust | ||
if GUI: | ||
GUI.progressBarTick.emit('tick') | ||
if not GUI.conversionAlive: | ||
|
@@ -598,6 +612,7 @@ def imgFileProcessing(work): | |
opt = work[2] | ||
output = [] | ||
workImg = image.ComicPageParser((dirpath, afile), opt) | ||
spreadadjust = workImg.opt.spreadadjust | ||
for i in workImg.payload: | ||
img = image.ComicPage(opt, *i) | ||
if opt.cropping == 2 and not opt.webtoon: | ||
|
@@ -609,7 +624,7 @@ def imgFileProcessing(work): | |
if opt.forcepng and not opt.forcecolor: | ||
img.quantizeImage() | ||
output.append(img.saveToDir()) | ||
return output | ||
return (output, spreadadjust) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need for parentheses to return a tuple |
||
except Exception: | ||
return str(sys.exc_info()[1]), sanitizeTrace(sys.exc_info()[2]) | ||
|
||
|
@@ -691,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': | ||
|
@@ -728,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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this entire code section should be skipped if a 400 mb split is detected (as if the xml doesn't exist?)? If it can be logically separated, make it a separate PR.