1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-04-10 23:23:34 +02: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:
2020-04-11 19:33:43 +02:00
parent 69d2e536c5
commit 0f9792df36
252 changed files with 1925 additions and 2344 deletions

View File

@@ -9,12 +9,12 @@ __docformat__ = 'restructuredtext en'
import re, codecs, os, numbers
from collections import namedtuple
from calibre import strftime
from calibre.customize import CatalogPlugin
from calibre.library.catalogs import FIELDS, TEMPLATE_ALLOWED_FIELDS
from calibre.customize.conversion import DummyReporter
from calibre.ebooks.metadata import format_isbn
from polyglot.builtins import filter, string_or_bytes, unicode_type
from ebook_converter import strftime
from ebook_converter.customize import CatalogPlugin
from ebook_converter.library.catalogs import FIELDS, TEMPLATE_ALLOWED_FIELDS
from ebook_converter.customize.conversion import DummyReporter
from ebook_converter.ebooks.metadata import format_isbn
from ebook_converter.polyglot.builtins import filter, string_or_bytes, unicode_type
class BIBTEX(CatalogPlugin):
@@ -108,12 +108,12 @@ class BIBTEX(CatalogPlugin):
"Applies to: BIBTEX output format"))]
def run(self, path_to_output, opts, db, notification=DummyReporter()):
from calibre.utils.date import isoformat
from calibre.utils.html2text import html2text
from calibre.utils.bibtex import BibTeX
from calibre.library.save_to_disk import preprocess_template
from calibre.utils.logging import default_log as log
from calibre.utils.filenames import ascii_text
from ebook_converter.utils.date import isoformat
from ebook_converter.utils.html2text import html2text
from ebook_converter.utils.bibtex import BibTeX
from ebook_converter.library.save_to_disk import preprocess_template
from ebook_converter.utils.logging import default_log as log
from ebook_converter.utils.filenames import ascii_text
library_name = os.path.basename(db.library_path)

View File

@@ -9,10 +9,10 @@ __docformat__ = 'restructuredtext en'
import re, codecs, os
from collections import namedtuple
from calibre.customize import CatalogPlugin
from calibre.library.catalogs import FIELDS
from calibre.customize.conversion import DummyReporter
from polyglot.builtins import unicode_type
from ebook_converter.customize import CatalogPlugin
from ebook_converter.library.catalogs import FIELDS
from ebook_converter.customize.conversion import DummyReporter
from ebook_converter.polyglot.builtins import unicode_type
class CSV_XML(CatalogPlugin):
@@ -52,12 +52,12 @@ class CSV_XML(CatalogPlugin):
"Applies to: CSV, XML output formats"))]
def run(self, path_to_output, opts, db, notification=DummyReporter()):
from calibre.library import current_library_name
from calibre.utils.date import isoformat
from calibre.utils.html2text import html2text
from calibre.utils.logging import default_log as log
from ebook_converter.library import current_library_name
from ebook_converter.utils.date import isoformat
from ebook_converter.utils.html2text import html2text
from ebook_converter.utils.logging import default_log as log
from lxml import etree
from calibre.ebooks.metadata import authors_to_string
from ebook_converter.ebooks.metadata import authors_to_string
self.fmt = path_to_output.rpartition('.')[2]
self.notification = notification

View File

@@ -9,14 +9,14 @@ __docformat__ = 'restructuredtext en'
import datetime, os, time
from collections import namedtuple
from calibre import strftime
from calibre.customize import CatalogPlugin
from calibre.customize.conversion import OptionRecommendation, DummyReporter
from calibre.library import current_library_name
from calibre.library.catalogs import AuthorSortMismatchException, EmptyCatalogException
from calibre.ptempfile import PersistentTemporaryFile
from calibre.utils.localization import calibre_langcode_to_name, canonicalize_lang, get_lang
from polyglot.builtins import unicode_type
from ebook_converter import strftime
from ebook_converter.customize import CatalogPlugin
from ebook_converter.customize.conversion import OptionRecommendation, DummyReporter
from ebook_converter.library import current_library_name
from ebook_converter.library.catalogs import AuthorSortMismatchException, EmptyCatalogException
from ebook_converter.ptempfile import PersistentTemporaryFile
from ebook_converter.utils.localization import calibre_langcode_to_name, canonicalize_lang, get_lang
from ebook_converter.polyglot.builtins import unicode_type
Option = namedtuple('Option', 'option, default, dest, action, help')
@@ -191,9 +191,9 @@ class EPUB_MOBI(CatalogPlugin):
# }}}
def run(self, path_to_output, opts, db, notification=DummyReporter()):
from calibre.library.catalogs.epub_mobi_builder import CatalogBuilder
from calibre.utils.logging import default_log as log
from calibre.utils.config import JSONConfig
from ebook_converter.library.catalogs.epub_mobi_builder import CatalogBuilder
from ebook_converter.utils.logging import default_log as log
from ebook_converter.utils.config import JSONConfig
# If preset specified from the cli, insert stored options from JSON file
if hasattr(opts, 'preset') and opts.preset:
@@ -465,7 +465,7 @@ class EPUB_MOBI(CatalogPlugin):
recommendations.append(('cover', cpath, OptionRecommendation.HIGH))
log.info("using existing catalog cover")
else:
from calibre.ebooks.covers import calibre_cover2
from ebook_converter.ebooks.covers import calibre_cover2
log.info("replacing catalog cover")
new_cover_path = PersistentTemporaryFile(suffix='.jpg')
new_cover = calibre_cover2(opts.catalog_title, 'calibre')
@@ -474,7 +474,7 @@ class EPUB_MOBI(CatalogPlugin):
recommendations.append(('cover', new_cover_path.name, OptionRecommendation.HIGH))
# Run ebook-convert
from calibre.ebooks.conversion.plumber import Plumber
from ebook_converter.ebooks.conversion.plumber import Plumber
plumber = Plumber(os.path.join(catalog.catalog_path, opts.basename + '.opf'),
path_to_output, log, report_progress=notification,
abort_after_input_dump=False)
@@ -487,9 +487,9 @@ class EPUB_MOBI(CatalogPlugin):
pass
if GENERATE_DEBUG_EPUB:
from calibre.ebooks.epub import initialize_container
from calibre.ebooks.tweak import zip_rebuilder
from calibre.utils.zipfile import ZipFile
from ebook_converter.ebooks.epub import initialize_container
from ebook_converter.ebooks.tweak import zip_rebuilder
from ebook_converter.utils.zipfile import ZipFile
input_path = os.path.join(catalog_debug_path, 'input')
epub_shell = os.path.join(catalog_debug_path, 'epub_shell.zip')
initialize_container(epub_shell, opf_name='content.opf')