mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
More miscellaneous bug fixes
This commit is contained in:
parent
0504bbd929
commit
19e7ed0cb7
@ -110,7 +110,7 @@ class EPUBInput(InputFormatPlugin):
|
|||||||
parts = os.path.split(opf)
|
parts = os.path.split(opf)
|
||||||
opf = OPF(opf, os.path.dirname(os.path.abspath(opf)))
|
opf = OPF(opf, os.path.dirname(os.path.abspath(opf)))
|
||||||
|
|
||||||
if len(parts) > 1:
|
if len(parts) > 1 and parts[0]:
|
||||||
delta = '/'.join(parts[:-1])+'/'
|
delta = '/'.join(parts[:-1])+'/'
|
||||||
for elem in opf.itermanifest():
|
for elem in opf.itermanifest():
|
||||||
elem.set('href', delta+elem.get('href'))
|
elem.set('href', delta+elem.get('href'))
|
||||||
|
@ -6,13 +6,15 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os
|
import os, shutil
|
||||||
from urllib import unquote
|
from urllib import unquote
|
||||||
|
|
||||||
from calibre.customize.conversion import OutputFormatPlugin
|
from calibre.customize.conversion import OutputFormatPlugin
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
from calibre.constants import __appname__, __version__
|
from calibre.constants import __appname__, __version__
|
||||||
from calibre import strftime, guess_type
|
from calibre import strftime, guess_type
|
||||||
|
from calibre.customize.conversion import OptionRecommendation
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
|
|
||||||
@ -22,6 +24,14 @@ class EPUBOutput(OutputFormatPlugin):
|
|||||||
author = 'Kovid Goyal'
|
author = 'Kovid Goyal'
|
||||||
file_type = 'epub'
|
file_type = 'epub'
|
||||||
|
|
||||||
|
options = set([
|
||||||
|
OptionRecommendation(name='extract_to',
|
||||||
|
help=_('Extract the contents of the generated EPUB file to the '
|
||||||
|
'specified directory. The contents of the directory are first '
|
||||||
|
'deleted, so be careful.'))
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
TITLEPAGE_COVER = '''\
|
TITLEPAGE_COVER = '''\
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||||
<head>
|
<head>
|
||||||
@ -43,6 +53,7 @@ class EPUBOutput(OutputFormatPlugin):
|
|||||||
TITLEPAGE = '''\
|
TITLEPAGE = '''\
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
<title>%(title)s</title>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
body {
|
body {
|
||||||
background: white no-repeat fixed center center;
|
background: white no-repeat fixed center center;
|
||||||
@ -66,7 +77,7 @@ class EPUBOutput(OutputFormatPlugin):
|
|||||||
<h2>%(date)s</h2>
|
<h2>%(date)s</h2>
|
||||||
<br/><br/><br/><br/><br/>
|
<br/><br/><br/><br/><br/>
|
||||||
<h3>%(author)s</h3>
|
<h3>%(author)s</h3>
|
||||||
<br/><br/></br/><br/><br/><br/><br/><br/><br/>
|
<br/><br/><br/><br/><br/><br/><br/><br/><br/>
|
||||||
<h4>Produced by %(app)s</h4>
|
<h4>Produced by %(app)s</h4>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -94,6 +105,12 @@ class EPUBOutput(OutputFormatPlugin):
|
|||||||
from calibre.ebooks.epub import initialize_container
|
from calibre.ebooks.epub import initialize_container
|
||||||
epub = initialize_container(output_path, os.path.basename(opf))
|
epub = initialize_container(output_path, os.path.basename(opf))
|
||||||
epub.add_dir(tdir)
|
epub.add_dir(tdir)
|
||||||
|
if opts.extract_to is not None:
|
||||||
|
if os.path.exists(opts.extract_to):
|
||||||
|
shutil.rmtree(opts.extract_to)
|
||||||
|
os.mkdir(opts.extract_to)
|
||||||
|
epub.extractall(path=opts.extract_to)
|
||||||
|
self.log.info('EPUB extracted to', opts.extract_to)
|
||||||
epub.close()
|
epub.close()
|
||||||
|
|
||||||
def default_cover(self):
|
def default_cover(self):
|
||||||
@ -145,6 +162,8 @@ class EPUBOutput(OutputFormatPlugin):
|
|||||||
urldefrag(self.oeb.guide['titlepage'].href)[0]]
|
urldefrag(self.oeb.guide['titlepage'].href)[0]]
|
||||||
if item is not None:
|
if item is not None:
|
||||||
self.oeb.spine.insert(0, item, True)
|
self.oeb.spine.insert(0, item, True)
|
||||||
|
if 'cover' not in self.oeb.guide.refs:
|
||||||
|
self.oeb.guide.add('cover', 'Title Page', 'a')
|
||||||
self.oeb.guide.refs['cover'].href = item.href
|
self.oeb.guide.refs['cover'].href = item.href
|
||||||
if 'titlepage' in self.oeb.guide.refs:
|
if 'titlepage' in self.oeb.guide.refs:
|
||||||
self.oeb.guide.refs['titlepage'].href = item.href
|
self.oeb.guide.refs['titlepage'].href = item.href
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -620,7 +620,8 @@ class MobiReader(object):
|
|||||||
if r > -1 and (r < l or l == end or l == -1):
|
if r > -1 and (r < l or l == end or l == -1):
|
||||||
p = self.mobi_html.rfind('<', 0, end + 1)
|
p = self.mobi_html.rfind('<', 0, end + 1)
|
||||||
if pos < end and p > -1 and \
|
if pos < end and p > -1 and \
|
||||||
not end_tag_re.match(self.mobi_html[p:r]):
|
not end_tag_re.match(self.mobi_html[p:r]) and \
|
||||||
|
not self.mobi_html[p:r+1].endswith('/>'):
|
||||||
anchor = ' filepos-id="filepos%d"'
|
anchor = ' filepos-id="filepos%d"'
|
||||||
end = r
|
end = r
|
||||||
else:
|
else:
|
||||||
|
@ -1324,6 +1324,12 @@ class TOC(object):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def has_text(self, text):
|
||||||
|
for x in self.iter():
|
||||||
|
if x.title and x.title.lower() == text.lower():
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def iterdescendants(self):
|
def iterdescendants(self):
|
||||||
"""Iterate over all descendant nodes in depth-first order."""
|
"""Iterate over all descendant nodes in depth-first order."""
|
||||||
for child in self.nodes:
|
for child in self.nodes:
|
||||||
|
@ -85,7 +85,7 @@ class DetectStructure(object):
|
|||||||
|
|
||||||
def create_toc_from_links(self):
|
def create_toc_from_links(self):
|
||||||
for item in self.oeb.spine:
|
for item in self.oeb.spine:
|
||||||
for a in item.data.xpath('//h:a[@href]'):
|
for a in XPath('//h:a[@href]')(item.data):
|
||||||
href = a.get('href')
|
href = a.get('href')
|
||||||
purl = urlparse(href)
|
purl = urlparse(href)
|
||||||
if not purl[0] or purl[0] == 'file':
|
if not purl[0] or purl[0] == 'file':
|
||||||
|
@ -554,7 +554,8 @@ class PdfFileReader(object):
|
|||||||
if not self._override_encryption and self.isEncrypted:
|
if not self._override_encryption and self.isEncrypted:
|
||||||
# if we don't have the encryption key:
|
# if we don't have the encryption key:
|
||||||
if not hasattr(self, '_decryption_key'):
|
if not hasattr(self, '_decryption_key'):
|
||||||
raise Exception, "file has not been decrypted"
|
from calibre.ebooks import DRMError
|
||||||
|
raise DRMError('File contents are encrypted')
|
||||||
# otherwise, decrypt here...
|
# otherwise, decrypt here...
|
||||||
import struct, md5
|
import struct, md5
|
||||||
pack1 = struct.pack("<i", indirectReference.idnum)[:3]
|
pack1 = struct.pack("<i", indirectReference.idnum)[:3]
|
||||||
|
2
todo
2
todo
@ -12,3 +12,5 @@
|
|||||||
* Refactor add books to use a separate process named calibre-worker-add
|
* Refactor add books to use a separate process named calibre-worker-add
|
||||||
- Dont use the process for adding a single book
|
- Dont use the process for adding a single book
|
||||||
- Use a process pool for speed
|
- Use a process pool for speed
|
||||||
|
|
||||||
|
* Change mobi metadata setter to use author_sort setting from MOBI output plugin instead of mobi.py
|
||||||
|
Loading…
x
Reference in New Issue
Block a user