Skip to content

Commit 38fa136

Browse files
authored
A "Covers" folder next to source files defines custom covers (ciromattia#1432)
* A "Covers" folder next to source files defines custom covers * fix case with output folder unchecked
1 parent 6d3bd02 commit 38fa136

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

kindlecomicconverter/comic2ebook.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,7 @@ def makeBook(source, qtgui=None, job_progress=''):
18241824
print(f"{job_progress}Preparing source images...")
18251825
path = getWorkFolder(source, options)
18261826
print(f"{job_progress}Checking images...")
1827+
_, ext = os.path.splitext(source)
18271828

18281829
if options.lightnovel:
18291830
for root, _, files in os.walk(os.path.join(path, 'OEBPS', 'Images')):
@@ -1844,7 +1845,6 @@ def makeBook(source, qtgui=None, job_progress=''):
18441845
if img.size[0] > x or img.size[1] > y:
18451846
img = ImageOps.contain(img, (x, y))
18461847
img.save(os.path.join(root, file), quality=options.jpegquality)
1847-
_, ext = os.path.splitext(source)
18481848
if ext != '.epub':
18491849
ext = '.cbz'
18501850
output_file = getOutputFilename(source, options.output, ext, '')
@@ -1887,6 +1887,25 @@ def makeBook(source, qtgui=None, job_progress=''):
18871887
if options.filefusion:
18881888
# Strip the fusion_0001_ sort prefix from makeFusion if present
18891889
chapterNames = {k: sub(r'^fusion_\d{4}_', '', v) for k, v in chapterNames.items()}
1890+
1891+
source_path = Path(source)
1892+
options.customcover = False
1893+
if source_path.parent.joinpath('Covers').is_dir():
1894+
series = os_sorted(filter(lambda s: s.endswith(ext) and '_kcc' not in s, os.listdir(source_path.parent)))
1895+
source_index = series.index(os.path.basename(source))
1896+
covers = os.listdir(source_path.parent.joinpath('Covers'))
1897+
filtered_covers = []
1898+
for cover in covers:
1899+
_, cover_ext = getImageFileName(cover)
1900+
if cover_ext in IMAGE_TYPES:
1901+
filtered_covers.append(cover)
1902+
sorted_covers = os_sorted(filtered_covers)
1903+
try:
1904+
cover_path = source_path.parent.joinpath('Covers', sorted_covers[source_index])
1905+
options.customcover = True
1906+
except IndexError:
1907+
pass
1908+
18901909
cover = None
18911910
if not options.webtoon:
18921911
cover = image.Cover(cover_path, options)
@@ -1968,7 +1987,7 @@ def makeBook(source, qtgui=None, job_progress=''):
19681987
filepath.append(getOutputFilename(source, options.output, '.cbz', ' ' + str(tomeNumber)))
19691988
else:
19701989
filepath.append(getOutputFilename(source, options.output, '.cbz', ''))
1971-
if cover and cover.smartcover:
1990+
if cover and (cover.smartcover or options.customcover):
19721991
cover.save_to_folder(os.path.join(tome, 'OEBPS', 'Images', '##cover.jpg'), tomeNumber, len(tomes))
19731992
if options.comicinfo_xml:
19741993
with open(os.path.join(tome, 'OEBPS', 'Images', 'ComicInfo.xml'), 'wb') as xmlOutput:
@@ -1979,7 +1998,7 @@ def makeBook(source, qtgui=None, job_progress=''):
19791998
# determine output filename based on source and tome count
19801999
suffix = (' ' + str(tomeNumber)) if len(tomes) > 1 else ''
19812000
output_file = getOutputFilename(source, options.output, '.pdf', suffix)
1982-
if cover and cover.smartcover:
2001+
if cover and (cover.smartcover or options.customcover):
19832002
cover.save_to_folder(os.path.join(tome, 'OEBPS', 'Images', 'cover.jpg'), tomeNumber, len(tomes))
19842003
# use optimized buildPDF logic with streaming and compression
19852004
output_pdf = buildPDF(tome, options.title, job_progress, None, output_file)

0 commit comments

Comments
 (0)