mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-03-17 23:33:43 +01:00
Convert calibre modules to ebook_converter.
Here is the first batch of modules, which are needed for converting several formats to LRF. Some of the logic has been change, more cleanups will follow.
This commit is contained in:
@@ -6,14 +6,14 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import re
|
||||
from calibre.ebooks.oeb.base import XPath, urlunquote
|
||||
from polyglot.builtins import as_bytes
|
||||
from ebook_converter.ebooks.oeb.base import XPath, urlunquote
|
||||
from ebook_converter.polyglot.builtins import as_bytes
|
||||
|
||||
|
||||
class DataURL(object):
|
||||
|
||||
def __call__(self, oeb, opts):
|
||||
from calibre.utils.imghdr import what
|
||||
from ebook_converter.utils.imghdr import what
|
||||
self.log = oeb.log
|
||||
attr_path = XPath('//h:img[@src]')
|
||||
for item in oeb.spine:
|
||||
@@ -29,7 +29,7 @@ class DataURL(object):
|
||||
continue
|
||||
if ';base64' in header:
|
||||
data = re.sub(r'\s+', '', data)
|
||||
from polyglot.binary import from_base64_bytes
|
||||
from ebook_converter.polyglot.binary import from_base64_bytes
|
||||
try:
|
||||
data = from_base64_bytes(data)
|
||||
except Exception:
|
||||
@@ -46,7 +46,7 @@ class DataURL(object):
|
||||
|
||||
def convert_image_data_uri(self, data, fmt, oeb):
|
||||
self.log('Found image encoded as data URI converting it to normal image')
|
||||
from calibre import guess_type
|
||||
from ebook_converter import guess_type
|
||||
item_id, item_href = oeb.manifest.generate('data-url-image', 'data-url-image.' + fmt)
|
||||
oeb.manifest.add(item_id, item_href, guess_type(item_href)[0], data=data)
|
||||
return item_href
|
||||
|
||||
Reference in New Issue
Block a user