mirror of
https://github.com/kovidgoyal/calibre.git
synced 2026-05-30 02:32:33 -04:00
Implemented comic2epub
This commit is contained in:
@@ -555,8 +555,8 @@ class Processor(Parser):
|
||||
# TODO: Figure out what to do about CSS imports from linked stylesheets
|
||||
|
||||
def do_layout(self):
|
||||
self.css += '\nbody {margin-top: 0pt; margin-botton: 0pt; margin-left: 0pt; margin-right: 0pt}\n'
|
||||
self.css += '@page {margin-top: %fpt; margin-botton: %fpt; margin-left: %fpt; margin-right: %fpt}\n'%(self.opts.margin_top, self.opts.margin_bottom, self.opts.margin_left, self.opts.margin_right)
|
||||
self.css += '\nbody {margin-top: 0pt; margin-bottom: 0pt; margin-left: 0pt; margin-right: 0pt}\n'
|
||||
self.css += '@page {margin-top: %fpt; margin-bottom: %fpt; margin-left: %fpt; margin-right: %fpt}\n'%(self.opts.margin_top, self.opts.margin_bottom, self.opts.margin_left, self.opts.margin_right)
|
||||
|
||||
def config(defaults=None, config_name='html',
|
||||
desc=_('Options to control the traversal of HTML')):
|
||||
|
||||
@@ -325,8 +325,11 @@ def create_epub(pages, profile, opts, thumbnail=None):
|
||||
wrappers = []
|
||||
WRAPPER = textwrap.dedent('''\
|
||||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
<head>
|
||||
<title>Page #%d</title>
|
||||
<style type="text/css">@page {margin:0pt; padding: 0pt;}</style>
|
||||
</head>
|
||||
<body style="margin: 0pt; padding: 0pt">
|
||||
<div style="text-align:center">
|
||||
<img src="%s" alt="comic page #%d" />
|
||||
</div>
|
||||
@@ -335,7 +338,7 @@ def create_epub(pages, profile, opts, thumbnail=None):
|
||||
''')
|
||||
dir = os.path.dirname(pages[0])
|
||||
for i, page in enumerate(pages):
|
||||
wrapper = WRAPPER%(os.path.basename(page), i+1)
|
||||
wrapper = WRAPPER%(i+1, os.path.basename(page), i+1)
|
||||
page = os.path.join(dir, 'page_%d.html'%(i+1))
|
||||
open(page, 'wb').write(wrapper)
|
||||
wrappers.append(page)
|
||||
@@ -346,8 +349,9 @@ def create_epub(pages, profile, opts, thumbnail=None):
|
||||
opf.create_spine(wrappers)
|
||||
metadata = os.path.join(dir, 'metadata.opf')
|
||||
opf.render(open(metadata, 'wb'))
|
||||
opts = html2epub_config('margin_left=0\nmargin_right=0\nmargin_top=0\nmargin_bottom=0').parse()
|
||||
html2epub(metadata, opts)
|
||||
opts2 = html2epub_config('margin_left=0\nmargin_right=0\nmargin_top=0\nmargin_bottom=0').parse()
|
||||
opts2.output = opts.output
|
||||
html2epub(metadata, opts2)
|
||||
|
||||
def create_lrf(pages, profile, opts, thumbnail=None):
|
||||
width, height = PROFILES[profile]
|
||||
@@ -371,6 +375,7 @@ def create_lrf(pages, profile, opts, thumbnail=None):
|
||||
book.append(_page)
|
||||
|
||||
book.renderLrf(open(opts.output, 'wb'))
|
||||
print _('Output written to'), opts.output
|
||||
|
||||
|
||||
def do_convert(path_to_file, opts, notification=lambda m, p: p, output_format='lrf'):
|
||||
@@ -379,7 +384,6 @@ def do_convert(path_to_file, opts, notification=lambda m, p: p, output_format='l
|
||||
opts.title = os.path.splitext(os.path.basename(source))[0]
|
||||
if not opts.output:
|
||||
opts.output = os.path.abspath(os.path.splitext(os.path.basename(source))[0]+'.'+output_format)
|
||||
|
||||
tdir = extract_comic(source)
|
||||
pages = find_pages(tdir, sort_on_mtime=opts.no_sort, verbose=opts.verbose)
|
||||
if not pages:
|
||||
@@ -394,6 +398,7 @@ def do_convert(path_to_file, opts, notification=lambda m, p: p, output_format='l
|
||||
thumbnail = os.path.join(tdir2, 'thumbnail.png')
|
||||
if not os.access(thumbnail, os.R_OK):
|
||||
thumbnail = None
|
||||
|
||||
if output_format == 'lrf':
|
||||
create_lrf(pages, opts.profile, opts, thumbnail=thumbnail)
|
||||
else:
|
||||
@@ -417,7 +422,7 @@ def main(args=sys.argv, notification=None, output_format='lrf'):
|
||||
|
||||
source = os.path.abspath(args[1])
|
||||
do_convert(source, opts, notification, output_format=output_format)
|
||||
print _('Output written to'), opts.output
|
||||
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -53,6 +53,7 @@ entry_points = {
|
||||
'lrf2html = calibre.ebooks.lrf.html.convert_to:main',
|
||||
'lit2oeb = calibre.ebooks.lit.reader:main',
|
||||
'comic2lrf = calibre.ebooks.lrf.comic.convert_from:main',
|
||||
'comic2epub = calibre.ebooks.epub.from_comic:main',
|
||||
'calibre-debug = calibre.debug:main',
|
||||
'calibredb = calibre.library.cli:main',
|
||||
'calibre-fontconfig = calibre.utils.fontconfig:main',
|
||||
@@ -176,7 +177,8 @@ def setup_completion(fatal_errors):
|
||||
from calibre.ebooks.epub.from_html import option_parser as html2epub
|
||||
from calibre.ebooks.html import option_parser as html2oeb
|
||||
from calibre.ebooks.epub.from_feeds import option_parser as feeds2epub
|
||||
from calibre.ebooks.epub.from_any import option_parser as any2epub
|
||||
from calibre.ebooks.epub.from_any import option_parser as any2epub
|
||||
from calibre.ebooks.epub.from_comic import option_parser as comic2epub
|
||||
any_formats = ['epub', 'htm', 'html', 'xhtml', 'xhtm', 'rar', 'zip',
|
||||
'txt', 'lit', 'rtf', 'pdf', 'prc', 'mobi', 'fb2']
|
||||
f = open_file('/etc/bash_completion.d/libprs500')
|
||||
@@ -212,6 +214,7 @@ def setup_completion(fatal_errors):
|
||||
f.write(opts_and_exts('mobi2oeb', mobioeb, ['mobi', 'prc']))
|
||||
f.write(opts_and_exts('lit2oeb', lit2oeb, ['lit']))
|
||||
f.write(opts_and_exts('comic2lrf', comicop, ['cbz', 'cbr']))
|
||||
f.write(opts_and_exts('comic2epub', comic2epub, ['cbz', 'cbr']))
|
||||
f.write(opts_and_words('feeds2disk', feeds2disk, feed_titles))
|
||||
f.write(opts_and_words('feeds2lrf', feeds2lrf, feed_titles))
|
||||
f.write(opts_and_words('feeds2lrf', feeds2epub, feed_titles))
|
||||
|
||||
+523
-443
File diff suppressed because it is too large
Load Diff
+527
-447
File diff suppressed because it is too large
Load Diff
+569
-438
File diff suppressed because it is too large
Load Diff
+523
-443
File diff suppressed because it is too large
Load Diff
+507
-437
File diff suppressed because it is too large
Load Diff
+521
-441
File diff suppressed because it is too large
Load Diff
+532
-433
File diff suppressed because it is too large
Load Diff
+528
-450
File diff suppressed because it is too large
Load Diff
+569
-438
File diff suppressed because it is too large
Load Diff
+538
-437
File diff suppressed because it is too large
Load Diff
+523
-443
File diff suppressed because it is too large
Load Diff
+523
-443
File diff suppressed because it is too large
Load Diff
+510
-435
File diff suppressed because it is too large
Load Diff
+523
-443
File diff suppressed because it is too large
Load Diff
+523
-443
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user