From d0b4cce3cd281c6800487875bdbebd626b9f14a7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 16 Oct 2008 17:33:40 -0700 Subject: [PATCH] Fix #1169 (any2epub ignores --metadata-from= for lit files) --- src/calibre/ebooks/epub/from_html.py | 6 +++++- src/calibre/ebooks/html.py | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/epub/from_html.py b/src/calibre/ebooks/epub/from_html.py index fb37c25893..3271a0d421 100644 --- a/src/calibre/ebooks/epub/from_html.py +++ b/src/calibre/ebooks/epub/from_html.py @@ -224,6 +224,10 @@ def convert(htmlfile, opts, notification=None): opts.override_css = open(opts.override_css, 'rb').read().decode(preferred_encoding, 'replace') except: opts.override_css = opts.override_css.decode(preferred_encoding, 'replace') + if opts.from_opf: + opts.from_opf = os.path.abspath(opts.from_opf) + if opts.from_ncx: + opts.from_ncx = os.path.abspath(opts.from_ncx) if htmlfile.lower().endswith('.opf'): opf = OPF(htmlfile, os.path.dirname(os.path.abspath(htmlfile))) filelist = opf_traverse(opf, verbose=opts.verbose, encoding=opts.encoding) @@ -233,7 +237,7 @@ def convert(htmlfile, opts, notification=None): if htmlfile is None: raise ValueError('Could not find suitable file to convert.') filelist = get_filelist(htmlfile, opts)[1] - mi = MetaInformation(opf) + mi = merge_metadata(None, opf, opts) else: opf, filelist = get_filelist(htmlfile, opts) mi = merge_metadata(htmlfile, opf, opts) diff --git a/src/calibre/ebooks/html.py b/src/calibre/ebooks/html.py index 9fd0f348b0..64168823d5 100644 --- a/src/calibre/ebooks/html.py +++ b/src/calibre/ebooks/html.py @@ -906,11 +906,12 @@ def merge_metadata(htmlfile, opf, opts): ''' if opf: mi = MetaInformation(opf) - else: + elif htmlfile: try: mi = get_metadata(open(htmlfile, 'rb'), 'html') except: mi = MetaInformation(None, None) + if opts.from_opf is not None and os.access(opts.from_opf, os.R_OK): mi.smart_update(OPF(open(opts.from_opf, 'rb'), os.path.abspath(os.path.dirname(opts.from_opf)))) for attr in ('title', 'authors', 'publisher', 'tags', 'comments'):