mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-03-16 15:03:30 +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:
@@ -11,10 +11,10 @@ Provides abstraction for metadata reading.writing from a variety of ebook format
|
||||
"""
|
||||
import os, sys, re
|
||||
|
||||
from calibre import relpath, guess_type, prints, force_unicode
|
||||
from calibre.utils.config_base import tweaks
|
||||
from polyglot.builtins import codepoint_to_chr, unicode_type, range, map, zip, getcwd, iteritems, itervalues, as_unicode
|
||||
from polyglot.urllib import quote, unquote, urlparse
|
||||
from ebook_converter import relpath, guess_type, prints, force_unicode
|
||||
from ebook_converter.utils.config_base import tweaks
|
||||
from ebook_converter.polyglot.builtins import codepoint_to_chr, unicode_type, range, map, zip, getcwd, iteritems, itervalues, as_unicode
|
||||
from ebook_converter.polyglot.urllib import quote, unquote, urlparse
|
||||
|
||||
|
||||
try:
|
||||
@@ -131,7 +131,7 @@ def get_title_sort_pat(lang=None):
|
||||
if ans is not None:
|
||||
return ans
|
||||
q = lang
|
||||
from calibre.utils.localization import canonicalize_lang, get_lang
|
||||
from ebook_converter.utils.localization import canonicalize_lang, get_lang
|
||||
if lang is None:
|
||||
q = tweaks['default_language_for_title_sort']
|
||||
if q is None:
|
||||
@@ -348,7 +348,7 @@ def MetaInformation(title, authors=(_('Unknown'),)):
|
||||
@param title: title or ``_('Unknown')`` or a MetaInformation object
|
||||
@param authors: List of strings or []
|
||||
'''
|
||||
from calibre.ebooks.metadata.book.base import Metadata
|
||||
from ebook_converter.ebooks.metadata.book.base import Metadata
|
||||
mi = None
|
||||
if hasattr(title, 'title') and hasattr(title, 'authors'):
|
||||
mi = title
|
||||
|
||||
@@ -9,9 +9,9 @@ __docformat__ = 'restructuredtext en'
|
||||
import os
|
||||
from contextlib import closing
|
||||
|
||||
from calibre.customize import FileTypePlugin
|
||||
from calibre.utils.localization import canonicalize_lang
|
||||
from polyglot.builtins import filter, unicode_type
|
||||
from ebook_converter.customize import FileTypePlugin
|
||||
from ebook_converter.utils.localization import canonicalize_lang
|
||||
from ebook_converter.polyglot.builtins import filter, unicode_type
|
||||
|
||||
|
||||
def is_comic(list_of_names):
|
||||
@@ -22,7 +22,7 @@ def is_comic(list_of_names):
|
||||
|
||||
|
||||
def archive_type(stream):
|
||||
from calibre.utils.zipfile import stringFileHeader
|
||||
from ebook_converter.utils.zipfile import stringFileHeader
|
||||
try:
|
||||
pos = stream.tell()
|
||||
except:
|
||||
@@ -51,7 +51,7 @@ class KPFExtract(FileTypePlugin):
|
||||
on_import = True
|
||||
|
||||
def run(self, archive):
|
||||
from calibre.utils.zipfile import ZipFile
|
||||
from ebook_converter.utils.zipfile import ZipFile
|
||||
with ZipFile(archive, 'r') as zf:
|
||||
fnames = zf.namelist()
|
||||
candidates = [x for x in fnames if x.lower().endswith('.docx')]
|
||||
@@ -74,10 +74,10 @@ class ArchiveExtract(FileTypePlugin):
|
||||
on_import = True
|
||||
|
||||
def run(self, archive):
|
||||
from calibre.utils.zipfile import ZipFile
|
||||
from ebook_converter.utils.zipfile import ZipFile
|
||||
is_rar = archive.lower().endswith('.rar')
|
||||
if is_rar:
|
||||
from calibre.utils.unrar import extract_member, names
|
||||
from ebook_converter.utils.unrar import extract_member, names
|
||||
else:
|
||||
zf = ZipFile(archive, 'r')
|
||||
|
||||
@@ -166,7 +166,7 @@ def get_comic_book_info(d, mi, series_index='volume'):
|
||||
mi.comments = comments.strip()
|
||||
pubm, puby = d.get('publicationMonth', None), d.get('publicationYear', None)
|
||||
if puby is not None:
|
||||
from calibre.utils.date import parse_only_date
|
||||
from ebook_converter.utils.date import parse_only_date
|
||||
from datetime import date
|
||||
try:
|
||||
dt = date(puby, 6 if pubm is None else pubm, 15)
|
||||
@@ -178,7 +178,7 @@ def get_comic_book_info(d, mi, series_index='volume'):
|
||||
|
||||
def parse_comic_comment(comment, series_index='volume'):
|
||||
# See http://code.google.com/p/comicbookinfo/wiki/Example
|
||||
from calibre.ebooks.metadata import MetaInformation
|
||||
from ebook_converter.ebooks.metadata import MetaInformation
|
||||
import json
|
||||
mi = MetaInformation(None, None)
|
||||
m = json.loads(comment)
|
||||
@@ -193,11 +193,11 @@ def parse_comic_comment(comment, series_index='volume'):
|
||||
def get_comic_metadata(stream, stream_type, series_index='volume'):
|
||||
comment = None
|
||||
if stream_type == 'cbz':
|
||||
from calibre.utils.zipfile import ZipFile
|
||||
from ebook_converter.utils.zipfile import ZipFile
|
||||
zf = ZipFile(stream)
|
||||
comment = zf.comment
|
||||
elif stream_type == 'cbr':
|
||||
from calibre.utils.unrar import comment as get_comment
|
||||
from ebook_converter.utils.unrar import comment as get_comment
|
||||
comment = get_comment(stream)
|
||||
|
||||
return parse_comic_comment(comment or b'{}', series_index=series_index)
|
||||
|
||||
@@ -8,14 +8,14 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
import copy, traceback
|
||||
|
||||
from calibre import prints
|
||||
from calibre.constants import DEBUG, ispy3
|
||||
from calibre.ebooks.metadata.book import (SC_COPYABLE_FIELDS,
|
||||
from ebook_converter import prints
|
||||
from ebook_converter.constants import DEBUG, ispy3
|
||||
from ebook_converter.ebooks.metadata.book import (SC_COPYABLE_FIELDS,
|
||||
SC_FIELDS_COPY_NOT_NULL, STANDARD_METADATA_FIELDS,
|
||||
TOP_LEVEL_IDENTIFIERS, ALL_METADATA_FIELDS)
|
||||
from calibre.library.field_metadata import FieldMetadata
|
||||
from calibre.utils.icu import sort_key
|
||||
from polyglot.builtins import iteritems, unicode_type, filter, map
|
||||
from ebook_converter.library.field_metadata import FieldMetadata
|
||||
from ebook_converter.utils.icu import sort_key
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, filter, map
|
||||
|
||||
# Special sets used to optimize the performance of getting and setting
|
||||
# attributes on Metadata objects
|
||||
@@ -52,7 +52,7 @@ def reset_field_metadata():
|
||||
field_metadata = FieldMetadata()
|
||||
|
||||
|
||||
ck = lambda typ: icu_lower(typ).strip().replace(':', '').replace(',', '')
|
||||
ck = lambda typ: typ.lower().strip().replace(':', '').replace(',', '')
|
||||
cv = lambda val: val.strip().replace(',', '|')
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ class Metadata(object):
|
||||
# List of strings or []
|
||||
self.author = list(authors) if authors else [] # Needed for backward compatibility
|
||||
self.authors = list(authors) if authors else []
|
||||
from calibre.ebooks.metadata.book.formatter import SafeFormat
|
||||
from ebook_converter.ebooks.metadata.book.formatter import SafeFormat
|
||||
self.formatter = SafeFormat() if formatter is None else formatter
|
||||
self.template_cache = template_cache
|
||||
|
||||
@@ -441,7 +441,7 @@ class Metadata(object):
|
||||
'''
|
||||
if not ops:
|
||||
return
|
||||
from calibre.ebooks.metadata.book.formatter import SafeFormat
|
||||
from ebook_converter.ebooks.metadata.book.formatter import SafeFormat
|
||||
formatter = SafeFormat()
|
||||
for op in ops:
|
||||
try:
|
||||
@@ -584,14 +584,15 @@ class Metadata(object):
|
||||
for attr in TOP_LEVEL_IDENTIFIERS:
|
||||
copy_not_none(self, other, attr)
|
||||
|
||||
other_lang = getattr(other, 'languages', [])
|
||||
if other_lang and other_lang != ['und']:
|
||||
self.languages = list(other_lang)
|
||||
# other_lang = getattr(other, 'languages', [])
|
||||
# if other_lang and other_lang != ['und']:
|
||||
# self.languages = list(other_lang)
|
||||
self.languages = []
|
||||
if not getattr(self, 'series', None):
|
||||
self.series_index = None
|
||||
|
||||
def format_series_index(self, val=None):
|
||||
from calibre.ebooks.metadata import fmt_sidx
|
||||
from ebook_converter.ebooks.metadata import fmt_sidx
|
||||
v = self.series_index if val is None else val
|
||||
try:
|
||||
x = float(v)
|
||||
@@ -600,11 +601,11 @@ class Metadata(object):
|
||||
return fmt_sidx(x)
|
||||
|
||||
def authors_from_string(self, raw):
|
||||
from calibre.ebooks.metadata import string_to_authors
|
||||
from ebook_converter.ebooks.metadata import string_to_authors
|
||||
self.authors = string_to_authors(raw)
|
||||
|
||||
def format_authors(self):
|
||||
from calibre.ebooks.metadata import authors_to_string
|
||||
from ebook_converter.ebooks.metadata import authors_to_string
|
||||
return authors_to_string(self.authors)
|
||||
|
||||
def format_tags(self):
|
||||
@@ -625,12 +626,12 @@ class Metadata(object):
|
||||
return (name, val)
|
||||
|
||||
def format_field_extended(self, key, series_with_index=True):
|
||||
from calibre.ebooks.metadata import authors_to_string
|
||||
from ebook_converter.ebooks.metadata import authors_to_string
|
||||
'''
|
||||
returns the tuple (display_name, formatted_value, original_value,
|
||||
field_metadata)
|
||||
'''
|
||||
from calibre.utils.date import format_date
|
||||
from ebook_converter.utils.date import format_date
|
||||
|
||||
# Handle custom series index
|
||||
if key.startswith('#') and key.endswith('_index'):
|
||||
@@ -715,8 +716,8 @@ class Metadata(object):
|
||||
A string representation of this object, suitable for printing to
|
||||
console
|
||||
'''
|
||||
from calibre.utils.date import isoformat
|
||||
from calibre.ebooks.metadata import authors_to_string
|
||||
from ebook_converter.utils.date import isoformat
|
||||
from ebook_converter.ebooks.metadata import authors_to_string
|
||||
ans = []
|
||||
|
||||
def fmt(x, y):
|
||||
@@ -765,8 +766,8 @@ class Metadata(object):
|
||||
'''
|
||||
A HTML representation of this object.
|
||||
'''
|
||||
from calibre.ebooks.metadata import authors_to_string
|
||||
from calibre.utils.date import isoformat
|
||||
from ebook_converter.ebooks.metadata import authors_to_string
|
||||
from ebook_converter.utils.date import isoformat
|
||||
ans = [(_('Title'), unicode_type(self.title))]
|
||||
ans += [(_('Author(s)'), (authors_to_string(self.authors) if self.authors else _('Unknown')))]
|
||||
ans += [(_('Publisher'), unicode_type(self.publisher))]
|
||||
@@ -817,7 +818,7 @@ def field_from_string(field, raw, field_metadata):
|
||||
elif dt == 'rating':
|
||||
val = float(raw) * 2
|
||||
elif dt == 'datetime':
|
||||
from calibre.utils.date import parse_only_date
|
||||
from ebook_converter.utils.date import parse_only_date
|
||||
val = parse_only_date(raw)
|
||||
elif dt == 'bool':
|
||||
if raw.lower() in {'true', 'yes', 'y'}:
|
||||
@@ -833,7 +834,7 @@ def field_from_string(field, raw, field_metadata):
|
||||
if field == 'identifiers':
|
||||
val = {x.partition(':')[0]:x.partition(':')[-1] for x in val}
|
||||
elif field == 'languages':
|
||||
from calibre.utils.localization import canonicalize_lang
|
||||
from ebook_converter.utils.localization import canonicalize_lang
|
||||
val = [canonicalize_lang(x) for x in val]
|
||||
val = [x for x in val if x]
|
||||
if val is object:
|
||||
|
||||
@@ -5,9 +5,9 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
from calibre.ebooks.metadata.book import TOP_LEVEL_IDENTIFIERS, ALL_METADATA_FIELDS
|
||||
from ebook_converter.ebooks.metadata.book import TOP_LEVEL_IDENTIFIERS, ALL_METADATA_FIELDS
|
||||
|
||||
from calibre.utils.formatter import TemplateFormatter
|
||||
from ebook_converter.utils.formatter import TemplateFormatter
|
||||
|
||||
|
||||
class SafeFormat(TemplateFormatter):
|
||||
@@ -21,7 +21,7 @@ class SafeFormat(TemplateFormatter):
|
||||
key = orig_key = orig_key.lower()
|
||||
if (key != 'title_sort' and key not in TOP_LEVEL_IDENTIFIERS and
|
||||
key not in ALL_METADATA_FIELDS):
|
||||
from calibre.ebooks.metadata.book.base import field_metadata
|
||||
from ebook_converter.ebooks.metadata.book.base import field_metadata
|
||||
key = field_metadata.search_term_to_field_key(key)
|
||||
if key is None or (self.book and
|
||||
key not in self.book.all_field_keys()):
|
||||
|
||||
@@ -9,19 +9,19 @@ Created on 4 Jun 2010
|
||||
import json, traceback
|
||||
from datetime import datetime, time
|
||||
|
||||
from calibre.ebooks.metadata.book import SERIALIZABLE_FIELDS
|
||||
from calibre.constants import filesystem_encoding, preferred_encoding
|
||||
from calibre.library.field_metadata import FieldMetadata
|
||||
from calibre import isbytestring
|
||||
from polyglot.builtins import iteritems, itervalues, as_bytes
|
||||
from polyglot.binary import as_base64_unicode, from_base64_bytes
|
||||
from ebook_converter.ebooks.metadata.book import SERIALIZABLE_FIELDS
|
||||
from ebook_converter.constants import filesystem_encoding, preferred_encoding
|
||||
from ebook_converter.library.field_metadata import FieldMetadata
|
||||
from ebook_converter import isbytestring
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, as_bytes
|
||||
from ebook_converter.polyglot.binary import as_base64_unicode, from_base64_bytes
|
||||
|
||||
# Translate datetimes to and from strings. The string form is the datetime in
|
||||
# UTC. The returned date is also UTC
|
||||
|
||||
|
||||
def string_to_datetime(src):
|
||||
from calibre.utils.iso8601 import parse_iso8601
|
||||
from ebook_converter.utils.iso8601 import parse_iso8601
|
||||
if src != "None":
|
||||
try:
|
||||
return parse_iso8601(src)
|
||||
@@ -31,7 +31,7 @@ def string_to_datetime(src):
|
||||
|
||||
|
||||
def datetime_to_string(dateval):
|
||||
from calibre.utils.date import isoformat, UNDEFINED_DATE, local_tz
|
||||
from ebook_converter.utils.date import isoformat, UNDEFINED_DATE, local_tz
|
||||
if dateval is None:
|
||||
return "None"
|
||||
if not isinstance(dateval, datetime):
|
||||
@@ -47,7 +47,7 @@ def encode_thumbnail(thumbnail):
|
||||
'''
|
||||
Encode the image part of a thumbnail, then return the 3 part tuple
|
||||
'''
|
||||
from calibre.utils.imghdr import identify
|
||||
from ebook_converter.utils.imghdr import identify
|
||||
if thumbnail is None:
|
||||
return None
|
||||
if not isinstance(thumbnail, (tuple, list)):
|
||||
|
||||
@@ -15,12 +15,12 @@ from collections import defaultdict
|
||||
from html5_parser import parse
|
||||
from lxml.etree import Comment
|
||||
|
||||
from calibre.ebooks.metadata import string_to_authors, authors_to_string
|
||||
from calibre.ebooks.metadata.book.base import Metadata
|
||||
from calibre.ebooks.chardet import xml_to_unicode
|
||||
from calibre import replace_entities, isbytestring
|
||||
from calibre.utils.date import parse_date, is_date_undefined
|
||||
from polyglot.builtins import iteritems
|
||||
from ebook_converter.ebooks.metadata import string_to_authors, authors_to_string
|
||||
from ebook_converter.ebooks.metadata.book.base import Metadata
|
||||
from ebook_converter.ebooks.chardet import xml_to_unicode
|
||||
from ebook_converter import replace_entities, isbytestring
|
||||
from ebook_converter.utils.date import parse_date, is_date_undefined
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
|
||||
|
||||
def get_metadata(stream):
|
||||
|
||||
@@ -5,13 +5,13 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import os, re, collections
|
||||
|
||||
from calibre.utils.config import prefs
|
||||
from calibre.constants import filesystem_encoding
|
||||
from calibre.ebooks.metadata.opf2 import OPF
|
||||
from calibre import isbytestring
|
||||
from calibre.customize.ui import get_file_type_metadata, set_file_type_metadata
|
||||
from calibre.ebooks.metadata import MetaInformation, string_to_authors
|
||||
from polyglot.builtins import getcwd, unicode_type
|
||||
from ebook_converter.utils.config import prefs
|
||||
from ebook_converter.constants import filesystem_encoding
|
||||
from ebook_converter.ebooks.metadata.opf2 import OPF
|
||||
from ebook_converter import isbytestring
|
||||
from ebook_converter.customize.ui import get_file_type_metadata, set_file_type_metadata
|
||||
from ebook_converter.ebooks.metadata import MetaInformation, string_to_authors
|
||||
from ebook_converter.polyglot.builtins import getcwd, unicode_type
|
||||
|
||||
# The priorities for loading metadata from different file types
|
||||
# Higher values should be used to update metadata from lower values
|
||||
@@ -184,7 +184,7 @@ def metadata_from_filename(name, pat=None, fallback_pat=None):
|
||||
try:
|
||||
pubdate = match.group('published')
|
||||
if pubdate:
|
||||
from calibre.utils.date import parse_only_date
|
||||
from ebook_converter.utils.date import parse_only_date
|
||||
mi.pubdate = parse_only_date(pubdate)
|
||||
except:
|
||||
pass
|
||||
@@ -224,7 +224,7 @@ def opf_metadata(opfpath):
|
||||
|
||||
|
||||
def forked_read_metadata(path, tdir):
|
||||
from calibre.ebooks.metadata.opf2 import metadata_to_opf
|
||||
from ebook_converter.ebooks.metadata.opf2 import metadata_to_opf
|
||||
with lopen(path, 'rb') as f:
|
||||
fmt = os.path.splitext(path)[1][1:].lower()
|
||||
f.seek(0, 2)
|
||||
|
||||
@@ -27,17 +27,17 @@ import re
|
||||
|
||||
from lxml.etree import fromstring, tostring
|
||||
|
||||
from calibre.ebooks.metadata import (
|
||||
from ebook_converter.ebooks.metadata import (
|
||||
MetaInformation, authors_to_string, check_isbn, string_to_authors
|
||||
)
|
||||
from calibre.utils.date import isoformat, parse_date
|
||||
from calibre.utils.imghdr import identify
|
||||
from calibre.utils.localization import canonicalize_lang, lang_as_iso639_1
|
||||
from calibre.utils.zipfile import ZipFile, safe_replace
|
||||
from ebook_converter.utils.date import isoformat, parse_date
|
||||
from ebook_converter.utils.imghdr import identify
|
||||
from ebook_converter.utils.localization import canonicalize_lang, lang_as_iso639_1
|
||||
from ebook_converter.utils.zipfile import ZipFile, safe_replace
|
||||
from odf.draw import Frame as odFrame, Image as odImage
|
||||
from odf.namespaces import DCNS, METANS, OFFICENS
|
||||
from odf.opendocument import load as odLoad
|
||||
from polyglot.builtins import as_unicode
|
||||
from ebook_converter.polyglot.builtins import as_unicode
|
||||
|
||||
fields = {
|
||||
'title': (DCNS, 'title'),
|
||||
|
||||
@@ -12,20 +12,20 @@ import re, sys, unittest, functools, os, uuid, glob, io, json, copy
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from calibre.ebooks import escape_xpath_attr
|
||||
from calibre.constants import __appname__, __version__, filesystem_encoding, ispy3
|
||||
from calibre.ebooks.metadata.toc import TOC
|
||||
from calibre.ebooks.metadata.utils import parse_opf, pretty_print_opf as _pretty_print
|
||||
from calibre.ebooks.metadata import string_to_authors, MetaInformation, check_isbn
|
||||
from calibre.ebooks.metadata.book.base import Metadata
|
||||
from calibre.utils.date import parse_date, isoformat
|
||||
from calibre.utils.localization import get_lang, canonicalize_lang
|
||||
from calibre import prints, guess_type
|
||||
from calibre.utils.cleantext import clean_ascii_chars, clean_xml_chars
|
||||
from calibre.utils.config import tweaks
|
||||
from calibre.utils.xml_parse import safe_xml_fromstring
|
||||
from polyglot.builtins import iteritems, unicode_type, getcwd, map
|
||||
from polyglot.urllib import unquote, urlparse
|
||||
from ebook_converter.ebooks import escape_xpath_attr
|
||||
from ebook_converter.constants import __appname__, __version__, filesystem_encoding, ispy3
|
||||
from ebook_converter.ebooks.metadata.toc import TOC
|
||||
from ebook_converter.ebooks.metadata.utils import parse_opf, pretty_print_opf as _pretty_print
|
||||
from ebook_converter.ebooks.metadata import string_to_authors, MetaInformation, check_isbn
|
||||
from ebook_converter.ebooks.metadata.book.base import Metadata
|
||||
from ebook_converter.utils.date import parse_date, isoformat
|
||||
from ebook_converter.utils.localization import get_lang, canonicalize_lang
|
||||
from ebook_converter import prints, guess_type
|
||||
from ebook_converter.utils.cleantext import clean_ascii_chars, clean_xml_chars
|
||||
from ebook_converter.utils.config import tweaks
|
||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, getcwd, map
|
||||
from ebook_converter.polyglot.urllib import unquote, urlparse
|
||||
|
||||
pretty_print_opf = False
|
||||
|
||||
@@ -487,8 +487,8 @@ class TitleSortField(MetadataField):
|
||||
|
||||
|
||||
def serialize_user_metadata(metadata_elem, all_user_metadata, tail='\n'+(' '*8)):
|
||||
from calibre.utils.config import to_json
|
||||
from calibre.ebooks.metadata.book.json_codec import (object_to_unicode,
|
||||
from ebook_converter.utils.config import to_json
|
||||
from ebook_converter.ebooks.metadata.book.json_codec import (object_to_unicode,
|
||||
encode_is_multiple)
|
||||
|
||||
for name, fm in all_user_metadata.items():
|
||||
@@ -512,7 +512,7 @@ def serialize_user_metadata(metadata_elem, all_user_metadata, tail='\n'+(' '*8))
|
||||
def dump_dict(cats):
|
||||
if not cats:
|
||||
cats = {}
|
||||
from calibre.ebooks.metadata.book.json_codec import object_to_unicode
|
||||
from ebook_converter.ebooks.metadata.book.json_codec import object_to_unicode
|
||||
return json.dumps(object_to_unicode(cats), ensure_ascii=False,
|
||||
skipkeys=True)
|
||||
|
||||
@@ -620,8 +620,8 @@ class OPF(object): # {{{
|
||||
def read_user_metadata(self):
|
||||
self._user_metadata_ = {}
|
||||
temp = Metadata('x', ['x'])
|
||||
from calibre.utils.config import from_json
|
||||
from calibre.ebooks.metadata.book.json_codec import decode_is_multiple
|
||||
from ebook_converter.utils.config import from_json
|
||||
from ebook_converter.ebooks.metadata.book.json_codec import decode_is_multiple
|
||||
elems = self.root.xpath('//*[name() = "meta" and starts-with(@name,'
|
||||
'"calibre:user_metadata:") and @content]')
|
||||
for elem in elems:
|
||||
@@ -643,7 +643,7 @@ class OPF(object): # {{{
|
||||
|
||||
def to_book_metadata(self):
|
||||
if self.package_version >= 3.0:
|
||||
from calibre.ebooks.metadata.opf3 import read_metadata
|
||||
from ebook_converter.ebooks.metadata.opf3 import read_metadata
|
||||
return read_metadata(self.root)
|
||||
ans = MetaInformation(self)
|
||||
for n, v in self._user_metadata_.items():
|
||||
@@ -964,7 +964,7 @@ class OPF(object): # {{{
|
||||
found_scheme = False
|
||||
for attr, val in iteritems(x.attrib):
|
||||
if attr.endswith('scheme'):
|
||||
typ = icu_lower(val)
|
||||
typ = val.lower()
|
||||
val = etree.tostring(x, with_tail=False, encoding='unicode',
|
||||
method='text').strip()
|
||||
if val and typ not in ('calibre', 'uuid'):
|
||||
@@ -1447,7 +1447,7 @@ class OPFCreator(Metadata):
|
||||
|
||||
# Actual rendering
|
||||
from lxml.builder import ElementMaker
|
||||
from calibre.ebooks.oeb.base import OPF2_NS, DC11_NS, CALIBRE_NS
|
||||
from ebook_converter.ebooks.oeb.base import OPF2_NS, DC11_NS, CALIBRE_NS
|
||||
DNS = OPF2_NS+'___xx___'
|
||||
E = ElementMaker(namespace=DNS, nsmap={None:DNS})
|
||||
M = ElementMaker(namespace=DNS,
|
||||
@@ -1494,7 +1494,7 @@ class OPFCreator(Metadata):
|
||||
if self.publisher:
|
||||
a(DC_ELEM('publisher', self.publisher))
|
||||
for key, val in iteritems(self.get_identifiers()):
|
||||
a(DC_ELEM('identifier', val, opf_attrs={'scheme':icu_upper(key)}))
|
||||
a(DC_ELEM('identifier', val, opf_attrs={'scheme':key.upper()}))
|
||||
if self.rights:
|
||||
a(DC_ELEM('rights', self.rights))
|
||||
if self.tags:
|
||||
@@ -1513,7 +1513,7 @@ class OPFCreator(Metadata):
|
||||
if self.publication_type is not None:
|
||||
a(CAL_ELEM('calibre:publication_type', self.publication_type))
|
||||
if self.user_categories:
|
||||
from calibre.ebooks.metadata.book.json_codec import object_to_unicode
|
||||
from ebook_converter.ebooks.metadata.book.json_codec import object_to_unicode
|
||||
a(CAL_ELEM('calibre:user_categories',
|
||||
json.dumps(object_to_unicode(self.user_categories))))
|
||||
if self.primary_writing_mode:
|
||||
@@ -1572,7 +1572,7 @@ class OPFCreator(Metadata):
|
||||
def metadata_to_opf(mi, as_string=True, default_lang=None):
|
||||
from lxml import etree
|
||||
import textwrap
|
||||
from calibre.ebooks.oeb.base import OPF, DC
|
||||
from ebook_converter.ebooks.oeb.base import OPF, DC
|
||||
|
||||
if not mi.application_id:
|
||||
mi.application_id = unicode_type(uuid.uuid4())
|
||||
@@ -1641,7 +1641,7 @@ def metadata_to_opf(mi, as_string=True, default_lang=None):
|
||||
if mi.publisher:
|
||||
factory(DC('publisher'), mi.publisher)
|
||||
for key, val in iteritems(mi.get_identifiers()):
|
||||
factory(DC('identifier'), val, scheme=icu_upper(key))
|
||||
factory(DC('identifier'), val, scheme=key.upper())
|
||||
if mi.rights:
|
||||
factory(DC('rights'), mi.rights)
|
||||
for lang in mi.languages:
|
||||
@@ -1689,7 +1689,7 @@ def metadata_to_opf(mi, as_string=True, default_lang=None):
|
||||
|
||||
|
||||
def test_m2o():
|
||||
from calibre.utils.date import now as nowf
|
||||
from ebook_converter.utils.date import now as nowf
|
||||
mi = MetaInformation('test & title', ['a"1', "a'2"])
|
||||
mi.title_sort = 'a\'"b'
|
||||
mi.author_sort = 'author sort'
|
||||
|
||||
@@ -8,28 +8,28 @@ import json
|
||||
import re
|
||||
from collections import defaultdict, namedtuple
|
||||
from functools import wraps
|
||||
from polyglot.builtins import iteritems, map, filter
|
||||
from ebook_converter.polyglot.builtins import iteritems, map, filter
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from calibre import prints
|
||||
from calibre.ebooks.metadata import authors_to_string, check_isbn, string_to_authors
|
||||
from calibre.ebooks.metadata.book.base import Metadata
|
||||
from calibre.ebooks.metadata.book.json_codec import (
|
||||
from ebook_converter import prints
|
||||
from ebook_converter.ebooks.metadata import authors_to_string, check_isbn, string_to_authors
|
||||
from ebook_converter.ebooks.metadata.book.base import Metadata
|
||||
from ebook_converter.ebooks.metadata.book.json_codec import (
|
||||
decode_is_multiple, encode_is_multiple, object_to_unicode
|
||||
)
|
||||
from calibre.ebooks.metadata.utils import (
|
||||
from ebook_converter.ebooks.metadata.utils import (
|
||||
create_manifest_item, ensure_unique, normalize_languages, parse_opf,
|
||||
pretty_print_opf
|
||||
)
|
||||
from calibre.ebooks.oeb.base import DC, OPF, OPF2_NSMAP
|
||||
from calibre.utils.config import from_json, to_json
|
||||
from calibre.utils.date import (
|
||||
from ebook_converter.ebooks.oeb.base import DC, OPF, OPF2_NSMAP
|
||||
from ebook_converter.utils.config import from_json, to_json
|
||||
from ebook_converter.utils.date import (
|
||||
fix_only_date, is_date_undefined, isoformat, parse_date as parse_date_, utcnow,
|
||||
w3cdtf
|
||||
)
|
||||
from calibre.utils.iso8601 import parse_iso8601
|
||||
from calibre.utils.localization import canonicalize_lang
|
||||
from ebook_converter.utils.iso8601 import parse_iso8601
|
||||
from ebook_converter.utils.localization import canonicalize_lang
|
||||
|
||||
# Utils {{{
|
||||
_xpath_cache = {}
|
||||
|
||||
@@ -9,9 +9,9 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
||||
import codecs
|
||||
import re
|
||||
|
||||
from calibre import force_unicode
|
||||
from calibre.ebooks.metadata import MetaInformation
|
||||
from polyglot.builtins import codepoint_to_chr, string_or_bytes, unicode_type, int_to_byte, filter
|
||||
from ebook_converter import force_unicode
|
||||
from ebook_converter.ebooks.metadata import MetaInformation
|
||||
from ebook_converter.polyglot.builtins import codepoint_to_chr, string_or_bytes, unicode_type, int_to_byte, filter
|
||||
|
||||
title_pat = re.compile(br'\{\\info.*?\{\\title(.*?)(?<!\\)\}', re.DOTALL)
|
||||
author_pat = re.compile(br'\{\\info.*?\{\\author(.*?)(?<!\\)\}', re.DOTALL)
|
||||
@@ -232,7 +232,7 @@ def set_metadata(stream, options):
|
||||
def find_tests():
|
||||
import unittest
|
||||
from io import BytesIO
|
||||
from calibre.ebooks.metadata.book.base import Metadata
|
||||
from ebook_converter.ebooks.metadata.book.base import Metadata
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
|
||||
|
||||
@@ -10,12 +10,12 @@ from collections import Counter
|
||||
from lxml import etree
|
||||
from lxml.builder import ElementMaker
|
||||
|
||||
from calibre.constants import __appname__, __version__
|
||||
from calibre.ebooks.chardet import xml_to_unicode
|
||||
from calibre.utils.xml_parse import safe_xml_fromstring
|
||||
from calibre.utils.cleantext import clean_xml_chars
|
||||
from polyglot.builtins import unicode_type, getcwd
|
||||
from polyglot.urllib import unquote, urlparse
|
||||
from ebook_converter.constants import __appname__, __version__
|
||||
from ebook_converter.ebooks.chardet import xml_to_unicode
|
||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||
from ebook_converter.utils.cleantext import clean_xml_chars
|
||||
from ebook_converter.polyglot.builtins import unicode_type, getcwd
|
||||
from ebook_converter.polyglot.urllib import unquote, urlparse
|
||||
|
||||
NCX_NS = "http://www.daisy.org/z3986/2005/ncx/"
|
||||
CALIBRE_NS = "http://calibre.kovidgoyal.net/2009/metadata"
|
||||
@@ -26,7 +26,7 @@ C = ElementMaker(namespace=CALIBRE_NS, nsmap=NSMAP)
|
||||
|
||||
def parse_html_toc(data):
|
||||
from html5_parser import parse
|
||||
from calibre.utils.cleantext import clean_xml_chars
|
||||
from ebook_converter.utils.cleantext import clean_xml_chars
|
||||
from lxml import etree
|
||||
if isinstance(data, bytes):
|
||||
data = xml_to_unicode(data, strip_encoding_pats=True, resolve_entities=True)[0]
|
||||
|
||||
@@ -6,14 +6,14 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
from calibre.ebooks.chardet import xml_to_unicode
|
||||
from calibre.ebooks.oeb.base import OPF
|
||||
from calibre.ebooks.oeb.polish.utils import guess_type
|
||||
from calibre.spell import parse_lang_code
|
||||
from calibre.utils.cleantext import clean_xml_chars
|
||||
from calibre.utils.localization import lang_as_iso639_1
|
||||
from calibre.utils.xml_parse import safe_xml_fromstring
|
||||
from polyglot.builtins import filter, map
|
||||
from ebook_converter.ebooks.chardet import xml_to_unicode
|
||||
from ebook_converter.ebooks.oeb.base import OPF
|
||||
from ebook_converter.ebooks.oeb.polish.utils import guess_type
|
||||
from ebook_converter.spell import parse_lang_code
|
||||
from ebook_converter.utils.cleantext import clean_xml_chars
|
||||
from ebook_converter.utils.localization import lang_as_iso639_1
|
||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||
from ebook_converter.polyglot.builtins import filter, map
|
||||
|
||||
OPFVersion = namedtuple('OPFVersion', 'major minor patch')
|
||||
|
||||
@@ -99,6 +99,6 @@ def create_manifest_item(root, href_template, id_template, media_type=None):
|
||||
|
||||
|
||||
def pretty_print_opf(root):
|
||||
from calibre.ebooks.oeb.polish.pretty import pretty_opf, pretty_xml_tree
|
||||
from ebook_converter.ebooks.oeb.polish.pretty import pretty_opf, pretty_xml_tree
|
||||
pretty_opf(root)
|
||||
pretty_xml_tree(root)
|
||||
|
||||
Reference in New Issue
Block a user