mirror of
https://github.com/ciromattia/kcc
synced 2025-12-15 02:36:44 +00:00
Fix page order and bookmarks by renaming numerically (#507)
* disable slugify * rename to digits * add -kcc * add ABC checks * remove kobo * don't use if statements * rename to suffix * re-order check * only slugify directories * add break * add sorted * fix kcc-b logic * add kcc to front of filename --------- Co-authored-by: Alexander Xu <alexanderx@qualtrics.com>
This commit is contained in:
@@ -514,18 +514,30 @@ def buildEPUB(path, chapternames, tomenumber):
|
|||||||
# Overwrite chapternames if tree is flat and ComicInfo.xml has bookmarks
|
# Overwrite chapternames if tree is flat and ComicInfo.xml has bookmarks
|
||||||
if not chapternames and options.chapters:
|
if not chapternames and options.chapters:
|
||||||
chapterlist = []
|
chapterlist = []
|
||||||
globaldiff = 0
|
|
||||||
|
global_diff = 0
|
||||||
|
diff_delta = 0
|
||||||
|
|
||||||
|
# if split
|
||||||
|
if options.splitter == 0:
|
||||||
|
diff_delta = 1
|
||||||
|
# if rotate and split
|
||||||
|
elif options.splitter == 2:
|
||||||
|
diff_delta = 2
|
||||||
|
|
||||||
for aChapter in options.chapters:
|
for aChapter in options.chapters:
|
||||||
pageid = aChapter[0]
|
pageid = aChapter[0]
|
||||||
for x in range(0, pageid + globaldiff + 1):
|
cur_diff = global_diff
|
||||||
|
global_diff = 0
|
||||||
|
|
||||||
|
for x in range(0, pageid + cur_diff + 1):
|
||||||
if '-kcc-b' in filelist[x][1]:
|
if '-kcc-b' in filelist[x][1]:
|
||||||
pageid += 1
|
pageid += diff_delta
|
||||||
if '-kcc-c' in filelist[pageid][1]:
|
global_diff += diff_delta
|
||||||
pageid -= 1
|
|
||||||
filename = filelist[pageid][1]
|
filename = filelist[pageid][1]
|
||||||
chapterlist.append((filelist[pageid][0].replace('Images', 'Text'), filename))
|
chapterlist.append((filelist[pageid][0].replace('Images', 'Text'), filename))
|
||||||
chapternames[filename] = aChapter[1]
|
chapternames[filename] = aChapter[1]
|
||||||
globaldiff = pageid - (aChapter[0] + globaldiff)
|
|
||||||
buildNCX(path, options.title, chapterlist, chapternames)
|
buildNCX(path, options.title, chapterlist, chapternames)
|
||||||
buildNAV(path, options.title, chapterlist, chapternames)
|
buildNAV(path, options.title, chapterlist, chapternames)
|
||||||
buildOPF(path, options.title, filelist, cover)
|
buildOPF(path, options.title, filelist, cover)
|
||||||
@@ -749,19 +761,23 @@ def getPanelViewSize(deviceres, size):
|
|||||||
def sanitizeTree(filetree):
|
def sanitizeTree(filetree):
|
||||||
chapterNames = {}
|
chapterNames = {}
|
||||||
for root, dirs, files in os.walk(filetree, False):
|
for root, dirs, files in os.walk(filetree, False):
|
||||||
for name in files:
|
for i, name in enumerate(sorted(files)):
|
||||||
splitname = os.path.splitext(name)
|
splitname = os.path.splitext(name)
|
||||||
slugified = slugify(splitname[0], False)
|
|
||||||
while os.path.exists(os.path.join(root, slugified + splitname[1])) and splitname[0].upper()\
|
# file needs kcc at front AND back to avoid renaming issues
|
||||||
!= slugified.upper():
|
slugified = f'kcc-{i:04}'
|
||||||
slugified += "A"
|
for suffix in '-KCC', '-KCC-A', '-KCC-B', '-KCC-C':
|
||||||
|
if splitname[0].endswith(suffix):
|
||||||
|
slugified += suffix.lower()
|
||||||
|
break
|
||||||
|
|
||||||
newKey = os.path.join(root, slugified + splitname[1])
|
newKey = os.path.join(root, slugified + splitname[1])
|
||||||
key = os.path.join(root, name)
|
key = os.path.join(root, name)
|
||||||
if key != newKey:
|
if key != newKey:
|
||||||
os.replace(key, newKey)
|
os.replace(key, newKey)
|
||||||
for name in dirs:
|
for name in dirs:
|
||||||
tmpName = name
|
tmpName = name
|
||||||
slugified = slugify(name, True)
|
slugified = slugify(name)
|
||||||
while os.path.exists(os.path.join(root, slugified)) and name.upper() != slugified.upper():
|
while os.path.exists(os.path.join(root, slugified)) and name.upper() != slugified.upper():
|
||||||
slugified += "A"
|
slugified += "A"
|
||||||
chapterNames[slugified] = tmpName
|
chapterNames[slugified] = tmpName
|
||||||
@@ -772,23 +788,6 @@ def sanitizeTree(filetree):
|
|||||||
return chapterNames
|
return chapterNames
|
||||||
|
|
||||||
|
|
||||||
def sanitizeTreeKobo(filetree):
|
|
||||||
pageNumber = 0
|
|
||||||
for root, dirs, files in os.walk(filetree):
|
|
||||||
dirs, files = walkSort(dirs, files)
|
|
||||||
for name in files:
|
|
||||||
splitname = os.path.splitext(name)
|
|
||||||
slugified = str(pageNumber).zfill(5)
|
|
||||||
pageNumber += 1
|
|
||||||
while os.path.exists(os.path.join(root, slugified + splitname[1])) and splitname[0].upper()\
|
|
||||||
!= slugified.upper():
|
|
||||||
slugified += "A"
|
|
||||||
newKey = os.path.join(root, slugified + splitname[1])
|
|
||||||
key = os.path.join(root, name)
|
|
||||||
if key != newKey:
|
|
||||||
os.replace(key, newKey)
|
|
||||||
|
|
||||||
|
|
||||||
def sanitizePermissions(filetree):
|
def sanitizePermissions(filetree):
|
||||||
for root, dirs, files in os.walk(filetree, False):
|
for root, dirs, files in os.walk(filetree, False):
|
||||||
for name in files:
|
for name in files:
|
||||||
@@ -911,11 +910,8 @@ def createNewTome():
|
|||||||
return tomePath, tomePathRoot
|
return tomePath, tomePathRoot
|
||||||
|
|
||||||
|
|
||||||
def slugify(value, isdir):
|
def slugify(value):
|
||||||
if isdir:
|
value = slugify_ext(value, regex_pattern=r'[^-a-z0-9_\.]+').strip('.')
|
||||||
value = slugify_ext(value, regex_pattern=r'[^-a-z0-9_\.]+').strip('.')
|
|
||||||
else:
|
|
||||||
value = slugify_ext(value).strip('.')
|
|
||||||
value = sub(r'0*([0-9]{4,})', r'\1', sub(r'([0-9]+)', r'0000\1', value, count=2))
|
value = sub(r'0*([0-9]{4,})', r'\1', sub(r'([0-9]+)', r'0000\1', value, count=2))
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@@ -1162,8 +1158,6 @@ def makeBook(source, qtgui=None):
|
|||||||
if GUI:
|
if GUI:
|
||||||
GUI.progressBarTick.emit('1')
|
GUI.progressBarTick.emit('1')
|
||||||
chapterNames = sanitizeTree(os.path.join(path, 'OEBPS', 'Images'))
|
chapterNames = sanitizeTree(os.path.join(path, 'OEBPS', 'Images'))
|
||||||
if 'Ko' in options.profile and options.format == 'CBZ':
|
|
||||||
sanitizeTreeKobo(os.path.join(path, 'OEBPS', 'Images'))
|
|
||||||
if options.batchsplit > 0:
|
if options.batchsplit > 0:
|
||||||
tomes = splitDirectory(path)
|
tomes = splitDirectory(path)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user