mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-18 20:23:34 +02:00
Added FB2 format.
This commit is contained in:
@@ -89,7 +89,7 @@ class FB2Input(InputFormatPlugin):
|
||||
log.debug('Converting XML to HTML...')
|
||||
with open(pkg_resources.resource_filename('ebook_converter',
|
||||
'data/fb2.xsl')) as f:
|
||||
ss = f.read().decode()
|
||||
ss = f.read()
|
||||
ss = ss.replace("__FB_NS__", fb_ns)
|
||||
if options.no_inline_fb2_toc:
|
||||
log('Disabling generation of inline FB2 TOC')
|
||||
|
||||
@@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
def base64_decode(raw):
|
||||
from io import BytesIO
|
||||
from polyglot.binary import from_base64_bytes
|
||||
from ebook_converter.polyglot.binary import from_base64_bytes
|
||||
|
||||
# First try the python implementation as it is faster
|
||||
try:
|
||||
|
||||
@@ -14,15 +14,15 @@ from datetime import datetime
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from calibre import prepare_string_for_xml
|
||||
from calibre.constants import __appname__, __version__
|
||||
from calibre.utils.localization import lang_as_iso639_1
|
||||
from calibre.utils.xml_parse import safe_xml_fromstring
|
||||
from calibre.utils.img import save_cover_data_to
|
||||
from calibre.ebooks.oeb.base import urlnormalize
|
||||
from polyglot.builtins import unicode_type, string_or_bytes, range, filter
|
||||
from polyglot.binary import as_base64_unicode
|
||||
from polyglot.urllib import urlparse
|
||||
from ebook_converter import prepare_string_for_xml
|
||||
from ebook_converter.constants import __appname__, __version__
|
||||
from ebook_converter.utils.localization import lang_as_iso639_1
|
||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||
from ebook_converter.utils.img import save_cover_data_to
|
||||
from ebook_converter.ebooks.oeb.base import urlnormalize
|
||||
from ebook_converter.polyglot.builtins import unicode_type, string_or_bytes, range, filter
|
||||
from ebook_converter.polyglot.binary import as_base64_unicode
|
||||
from ebook_converter.polyglot.urllib import urlparse
|
||||
|
||||
|
||||
class FB2MLizer(object):
|
||||
@@ -112,7 +112,7 @@ class FB2MLizer(object):
|
||||
return text
|
||||
|
||||
def fb2_header(self):
|
||||
from calibre.ebooks.oeb.base import OPF
|
||||
from ebook_converter.ebooks.oeb.base import OPF
|
||||
metadata = {}
|
||||
metadata['title'] = self.oeb_book.metadata.title[0].value
|
||||
metadata['appname'] = __appname__
|
||||
@@ -204,7 +204,7 @@ class FB2MLizer(object):
|
||||
except Exception:
|
||||
metadata['comments'] = ''
|
||||
else:
|
||||
from calibre.utils.html2text import html2text
|
||||
from ebook_converter.utils.html2text import html2text
|
||||
metadata['comments'] = '<annotation><p>{}</p></annotation>'.format(prepare_string_for_xml(html2text(comments.value).strip()))
|
||||
|
||||
# Keep the indentation level of the description the same as the body.
|
||||
@@ -242,7 +242,7 @@ class FB2MLizer(object):
|
||||
return '</FictionBook>'
|
||||
|
||||
def get_cover(self):
|
||||
from calibre.ebooks.oeb.base import OEB_RASTER_IMAGES
|
||||
from ebook_converter.ebooks.oeb.base import OEB_RASTER_IMAGES
|
||||
|
||||
cover_href = None
|
||||
|
||||
@@ -276,8 +276,8 @@ class FB2MLizer(object):
|
||||
return ''
|
||||
|
||||
def get_text(self):
|
||||
from calibre.ebooks.oeb.base import XHTML
|
||||
from calibre.ebooks.oeb.stylizer import Stylizer
|
||||
from ebook_converter.ebooks.oeb.base import XHTML
|
||||
from ebook_converter.ebooks.oeb.stylizer import Stylizer
|
||||
text = ['<body>']
|
||||
|
||||
# Create main section if there are no others to create
|
||||
@@ -314,7 +314,7 @@ class FB2MLizer(object):
|
||||
'''
|
||||
This function uses the self.image_hrefs dictionary mapping. It is populated by the dump_text function.
|
||||
'''
|
||||
from calibre.ebooks.oeb.base import OEB_RASTER_IMAGES
|
||||
from ebook_converter.ebooks.oeb.base import OEB_RASTER_IMAGES
|
||||
|
||||
images = []
|
||||
for item in self.oeb_book.manifest:
|
||||
@@ -405,7 +405,7 @@ class FB2MLizer(object):
|
||||
|
||||
@return: List of string representing the XHTML converted to FB2 markup.
|
||||
'''
|
||||
from calibre.ebooks.oeb.base import XHTML_NS, barename, namespace
|
||||
from ebook_converter.ebooks.oeb.base import XHTML_NS, barename, namespace
|
||||
elem = elem_tree
|
||||
|
||||
# Ensure what we are converting is not a string and that the fist tag is part of the XHTML namespace.
|
||||
|
||||
@@ -13,15 +13,15 @@ from string import ascii_letters, digits
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from calibre.utils.date import parse_only_date
|
||||
from calibre.utils.img import save_cover_data_to
|
||||
from calibre.utils.xml_parse import safe_xml_fromstring
|
||||
from calibre.utils.imghdr import identify
|
||||
from calibre import guess_type, guess_all_extensions, prints, force_unicode
|
||||
from calibre.ebooks.metadata import MetaInformation, check_isbn
|
||||
from calibre.ebooks.chardet import xml_to_unicode
|
||||
from polyglot.builtins import unicode_type
|
||||
from polyglot.binary import as_base64_unicode
|
||||
from ebook_converter.utils.date import parse_only_date
|
||||
from ebook_converter.utils.img import save_cover_data_to
|
||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||
from ebook_converter.utils.imghdr import identify
|
||||
from ebook_converter import guess_type, guess_all_extensions, prints, force_unicode
|
||||
from ebook_converter.ebooks.metadata import MetaInformation, check_isbn
|
||||
from ebook_converter.ebooks.chardet import xml_to_unicode
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
from ebook_converter.polyglot.binary import as_base64_unicode
|
||||
|
||||
|
||||
NAMESPACES = {
|
||||
@@ -90,7 +90,7 @@ class Context(object):
|
||||
|
||||
|
||||
def get_fb2_data(stream):
|
||||
from calibre.utils.zipfile import ZipFile, BadZipfile
|
||||
from ebook_converter.utils.zipfile import ZipFile, BadZipfile
|
||||
pos = stream.tell()
|
||||
try:
|
||||
zf = ZipFile(stream)
|
||||
@@ -225,7 +225,7 @@ def _parse_cover(root, mi, ctx):
|
||||
|
||||
|
||||
def _parse_cover_data(root, imgid, mi, ctx):
|
||||
from calibre.ebooks.fb2 import base64_decode
|
||||
from ebook_converter.ebooks.fb2 import base64_decode
|
||||
elm_binary = ctx.XPath('//fb:binary[@id="%s"]'%imgid)(root)
|
||||
if elm_binary:
|
||||
mimetype = elm_binary[0].get('content-type', 'image/jpeg')
|
||||
@@ -330,7 +330,7 @@ def _set_title(title_info, mi, ctx):
|
||||
|
||||
def _set_comments(title_info, mi, ctx):
|
||||
if not mi.is_null('comments'):
|
||||
from calibre.utils.html2text import html2text
|
||||
from ebook_converter.utils.html2text import html2text
|
||||
ctx.clear_meta_tags(title_info, 'annotation')
|
||||
title = ctx.get_or_create(title_info, 'annotation')
|
||||
ctx.text2fb2(title, html2text(mi.comments))
|
||||
@@ -432,7 +432,7 @@ def set_metadata(stream, mi, apply_null=False, update_timestamp=False):
|
||||
stream.seek(0)
|
||||
stream.truncate()
|
||||
if zip_file_name:
|
||||
from calibre.utils.zipfile import ZipFile
|
||||
from ebook_converter.utils.zipfile import ZipFile
|
||||
with ZipFile(stream, 'w') as zf:
|
||||
zf.writestr(zip_file_name, raw)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user