mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
PML Input: Allow for images in top-level bookname_image and images directories
This commit is contained in:
parent
ce529808a4
commit
820f2b6ce3
@ -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()
|
||||||
|
@ -13,7 +13,6 @@ import StringIO
|
|||||||
|
|
||||||
from calibre import my_unichr, prepare_string_for_xml
|
from calibre import my_unichr, prepare_string_for_xml
|
||||||
from calibre.ebooks.metadata.toc import TOC
|
from calibre.ebooks.metadata.toc import TOC
|
||||||
from calibre.ebooks.pdb.ereader import image_name
|
|
||||||
|
|
||||||
class PML_HTMLizer(object):
|
class PML_HTMLizer(object):
|
||||||
|
|
||||||
@ -445,7 +444,7 @@ class PML_HTMLizer(object):
|
|||||||
elif c == 'm':
|
elif c == 'm':
|
||||||
empty = False
|
empty = False
|
||||||
src = self.code_value(line)
|
src = self.code_value(line)
|
||||||
text = '<img src="images/%s" />' % image_name(src).strip('\x00')
|
text = '<img src="images/%s" />' % src
|
||||||
elif c == 'Q':
|
elif c == 'Q':
|
||||||
empty = False
|
empty = False
|
||||||
id = self.code_value(line)
|
id = self.code_value(line)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user