mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
PML Meatadata: Read cover.
This commit is contained in:
parent
d19848184d
commit
113b4c8d09
@ -28,8 +28,12 @@ def get_metadata(stream, extract_cover=True):
|
|||||||
for p in pmls:
|
for p in pmls:
|
||||||
with open(p, 'r+b') as p_stream:
|
with open(p, 'r+b') as p_stream:
|
||||||
pml += p_stream.read()
|
pml += p_stream.read()
|
||||||
|
if extract_cover:
|
||||||
|
mi.cover_data = get_cover(os.path.splitext(os.path.basename(stream.name))[0], tdir, True)
|
||||||
else:
|
else:
|
||||||
pml = stream.read()
|
pml = stream.read()
|
||||||
|
if extract_cover:
|
||||||
|
mi.cover_data = get_cover(os.path.splitext(os.path.basename(stream.name))[0], os.path.abspath(os.path.dirname(stream.name)))
|
||||||
|
|
||||||
for comment in re.findall(r'(?mus)\\v.*?\\v', pml):
|
for comment in re.findall(r'(?mus)\\v.*?\\v', pml):
|
||||||
m = re.search(r'TITLE="(.*?)"', comment)
|
m = re.search(r'TITLE="(.*?)"', comment)
|
||||||
@ -51,3 +55,22 @@ def get_metadata(stream, extract_cover=True):
|
|||||||
mi.isbn = m.group(1).strip().decode('cp1252', 'replace')
|
mi.isbn = m.group(1).strip().decode('cp1252', 'replace')
|
||||||
|
|
||||||
return mi
|
return mi
|
||||||
|
|
||||||
|
def get_cover(name, tdir, top_level=False):
|
||||||
|
cover_path = []
|
||||||
|
cover_data = None
|
||||||
|
|
||||||
|
if top_level:
|
||||||
|
cover_path = glob.glob(os.path.join(tdir, 'cover.png'))
|
||||||
|
# Images not in top level try bookname_img directory because
|
||||||
|
# that's where Dropbook likes to see them.
|
||||||
|
if not cover_path:
|
||||||
|
cover_path = glob.glob(os.path.join(tdir, name + '_img', 'cover.png'))
|
||||||
|
# No images in Dropbook location try generic images directory
|
||||||
|
if not cover_path:
|
||||||
|
cover_path = glob.glob(os.path.join(os.path.join(tdir, 'images'), 'cover.png'))
|
||||||
|
if cover_path:
|
||||||
|
with open(cover_path[0], 'r+b') as cstream:
|
||||||
|
cover_data = cstream.read()
|
||||||
|
|
||||||
|
return ('png', cover_data)
|
||||||
|
@ -67,7 +67,7 @@ class PMLInput(InputFormatPlugin):
|
|||||||
# that's where Dropbook likes to see them.
|
# that's where Dropbook likes to see them.
|
||||||
if not imgs:
|
if not imgs:
|
||||||
if hasattr(stream, 'name'):
|
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'))
|
imgs = glob.glob(os.path.join(tdir, os.path.splitext(os.path.basename(stream.name))[0] + '_img', '*.png'))
|
||||||
# No images in Dropbook location try generic images directory
|
# No images in Dropbook location try generic images directory
|
||||||
if not imgs:
|
if not imgs:
|
||||||
imgs = glob.glob(os.path.join(os.path.join(tdir, 'images'), '*.png'))
|
imgs = glob.glob(os.path.join(os.path.join(tdir, 'images'), '*.png'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user