mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
PML Input: Allow for images to be in top level, bookname_img, or images directory for both PML and PMLZ.
This commit is contained in:
parent
990f4f3bc4
commit
44ba14e77b
@ -1,3 +1,4 @@
|
|||||||
|
import os.path
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
@ -56,6 +57,32 @@ class PMLInput(InputFormatPlugin):
|
|||||||
|
|
||||||
return hizer.get_toc()
|
return hizer.get_toc()
|
||||||
|
|
||||||
|
def get_images(self, stream, tdir, top_level=False):
|
||||||
|
images = []
|
||||||
|
imgs = []
|
||||||
|
|
||||||
|
if top_level:
|
||||||
|
imgs = glob.glob(os.path.join(tdir, '*.png'))
|
||||||
|
# Images not in top level try bookname_img directory because
|
||||||
|
# that's where Dropbook likes to see them.
|
||||||
|
if not imgs:
|
||||||
|
if hasattr(stream, 'name'):
|
||||||
|
imgs = glob.glob(os.path.join(os.path.join(tdir, os.path.splitext(os.path.basename(stream.name))[0] + '_img'), '*.png'))
|
||||||
|
# No images in Dropbook location try generic images directory
|
||||||
|
if not imgs:
|
||||||
|
imgs = glob.glob(os.path.join(os.path.join(tdir, 'images'), '*.png'))
|
||||||
|
if imgs:
|
||||||
|
os.makedirs(os.path.join(os.getcwd(), 'images'))
|
||||||
|
for img in imgs:
|
||||||
|
pimg_name = os.path.basename(img)
|
||||||
|
pimg_path = os.path.join(os.getcwd(), 'images', pimg_name)
|
||||||
|
|
||||||
|
images.append('images/' + pimg_name)
|
||||||
|
|
||||||
|
shutil.copy(img, pimg_path)
|
||||||
|
|
||||||
|
return images
|
||||||
|
|
||||||
def convert(self, stream, options, file_ext, log,
|
def convert(self, stream, options, file_ext, log,
|
||||||
accelerators):
|
accelerators):
|
||||||
self.options = options
|
self.options = options
|
||||||
@ -78,22 +105,13 @@ class PMLInput(InputFormatPlugin):
|
|||||||
log.debug('Processing PML item %s...' % pml)
|
log.debug('Processing PML item %s...' % pml)
|
||||||
ttoc = self.process_pml(pml, html_path)
|
ttoc = self.process_pml(pml, html_path)
|
||||||
toc += ttoc
|
toc += ttoc
|
||||||
|
images = self.get_images(stream, tdir, True)
|
||||||
imgs = glob.glob(os.path.join(tdir, '*.png'))
|
|
||||||
if len(imgs) > 0:
|
|
||||||
os.makedirs(os.path.join(os.getcwd(), 'images'))
|
|
||||||
for img in imgs:
|
|
||||||
pimg_name = os.path.basename(img)
|
|
||||||
pimg_path = os.path.join(os.getcwd(), 'images', pimg_name)
|
|
||||||
|
|
||||||
images.append('images/' + pimg_name)
|
|
||||||
|
|
||||||
shutil.move(img, pimg_path)
|
|
||||||
else:
|
else:
|
||||||
toc = self.process_pml(stream, 'index.html')
|
toc = self.process_pml(stream, 'index.html')
|
||||||
|
|
||||||
pages.append('index.html')
|
pages.append('index.html')
|
||||||
images = []
|
|
||||||
|
if hasattr(stream, 'name'):
|
||||||
|
images = self.get_images(stream, os.path.abspath(os.path.dirname(stream.name)))
|
||||||
|
|
||||||
# We want pages to be orded alphabetically.
|
# We want pages to be orded alphabetically.
|
||||||
pages.sort()
|
pages.sort()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user