diff --git a/src/calibre/ebooks/epub/input.py b/src/calibre/ebooks/epub/input.py index 4c1cdbfcf5..5c8a5c9d89 100644 --- a/src/calibre/ebooks/epub/input.py +++ b/src/calibre/ebooks/epub/input.py @@ -51,8 +51,7 @@ class EPUBInput(InputFormatPlugin): traceback.print_exc() return False - def convert(self, stream, options, file_ext, parse_cache, log, - accelerators): + def convert(self, stream, options, file_ext, log, accelerators): from calibre.utils.zipfile import ZipFile from calibre import walk from calibre.ebooks import DRMError @@ -72,6 +71,5 @@ class EPUBInput(InputFormatPlugin): if os.path.exists(encfile): if not self.process_encryption(encfile, opf, log): raise DRMError(os.path.basename(path)) - - return opf - + + return os.path.join(os.getcwd(), opf) diff --git a/src/calibre/ebooks/htmlsymbols.py b/src/calibre/ebooks/htmlsymbols.py index fa10873845..d46e4c707a 100644 --- a/src/calibre/ebooks/htmlsymbols.py +++ b/src/calibre/ebooks/htmlsymbols.py @@ -306,5 +306,7 @@ HTML_SYMBOLS = { u'ý' : ['ý', 'ý'], # latin small letter y with acute u'þ' : ['þ', 'þ'], # latin small letter thorn u'ÿ' : ['ÿ', 'ÿ'], # latin small letter y with diaeresis + # More + u' ' : [' '], } diff --git a/src/calibre/ebooks/metadata/pdf.py b/src/calibre/ebooks/metadata/pdf.py index baf458e64b..4476eb0847 100644 --- a/src/calibre/ebooks/metadata/pdf.py +++ b/src/calibre/ebooks/metadata/pdf.py @@ -51,23 +51,18 @@ def get_metadata(stream, extract_cover=True): def set_metadata(stream, mi): stream.seek(0) - # Use a StringIO object for the pdf because we will want to over # write it later and if we are working on the stream directly it # could cause some issues. raw = StringIO.StringIO(stream.read()) orig_pdf = PdfFileReader(raw) - title = mi.title if mi.title else orig_pdf.documentInfo.title author = authors_to_string(mi.authors) if mi.authors else orig_pdf.documentInfo.author - out_pdf = PdfFileWriter(title=title, author=author) for page in orig_pdf.pages: out_pdf.addPage(page) - out_str = StringIO.StringIO() out_pdf.write(out_str) - stream.seek(0) stream.truncate() out_str.seek(0) diff --git a/src/calibre/ebooks/mobi/reader.py b/src/calibre/ebooks/mobi/reader.py index dbdcb1a24f..b68263ab28 100644 --- a/src/calibre/ebooks/mobi/reader.py +++ b/src/calibre/ebooks/mobi/reader.py @@ -158,22 +158,19 @@ class BookHeader(object): class MetadataHeader(BookHeader): - def __init__(self, stream): + def __init__(self, stream, log): self.stream = stream - self.ident = self.identity() self.num_sections = self.section_count() - if self.num_sections >= 2: header = self.header() - BookHeader.__init__(self, header, self.ident, None) + BookHeader.__init__(self, header, self.ident, None, log) else: self.exth = None def identity(self): self.stream.seek(60) ident = self.stream.read(8).upper() - if ident not in ['BOOKMOBI', 'TEXTREAD']: raise MobiError('Unknown book type: %s' % ident) return ident @@ -188,7 +185,6 @@ class MetadataHeader(BookHeader): def header(self): section_headers = [] - # First section with the metadata section_headers.append(self.section_offset(0)) # Second section used to get the lengh of the first @@ -196,20 +192,16 @@ class MetadataHeader(BookHeader): end_off = section_headers[1] off = section_headers[0] - self.stream.seek(off) return self.stream.read(end_off - off) def section_data(self, number): start = self.section_offset(number) - if number == self.num_sections -1: end = os.stat(self.stream.name).st_size else: end = self.section_offset(number + 1) - self.stream.seek(start) - return self.stream.read(end - start) @@ -470,7 +462,7 @@ class MobiReader(object): def create_opf(self, htmlfile, guide=None, root=None): mi = getattr(self.book_header.exth, 'mi', self.embedded_mi) if mi is None: - mi = MetaInformation(self.title, [_('Unknown')]) + mi = MetaInformation(self.book_header.title, [_('Unknown')]) opf = OPFCreator(os.path.dirname(htmlfile), mi) if hasattr(self.book_header.exth, 'cover_offset'): opf.cover = 'images/%05d.jpg'%(self.book_header.exth.cover_offset+1) @@ -649,20 +641,23 @@ class MobiReader(object): im.convert('RGB').save(open(path, 'wb'), format='JPEG') def get_metadata(stream): + from calibre.utils.logging import Log + log = Log() + mi = MetaInformation(os.path.basename(stream.name), [_('Unknown')]) try: - mh = MetadataHeader(stream) + mh = MetadataHeader(stream, log) if mh.exth is not None: if mh.exth.mi is not None: mi = mh.exth.mi else: with TemporaryDirectory('_mobi_meta_reader') as tdir: - mr = MobiReader(stream) - mr.extract_content(tdir, {}) + mr = MobiReader(stream, log) + parse_cache = {} + mr.extract_content(tdir, parse_cache) if mr.embedded_mi is not None: mi = mr.embedded_mi - if hasattr(mh.exth, 'cover_offset'): cover_index = mh.first_image_index + mh.exth.cover_offset data = mh.section_data(int(cover_index)) @@ -674,9 +669,5 @@ def get_metadata(stream): im.convert('RGBA').save(obuf, format='JPEG') mi.cover_data = ('jpg', obuf.getvalue()) except: - import traceback - traceback.print_exc() - + log.exception() return mi - - diff --git a/src/calibre/ebooks/oeb/iterator.py b/src/calibre/ebooks/oeb/iterator.py index 8672d42e2b..df4f3b88f1 100644 --- a/src/calibre/ebooks/oeb/iterator.py +++ b/src/calibre/ebooks/oeb/iterator.py @@ -1,3 +1,4 @@ +from __future__ import with_statement __license__ = 'GPL v3' __copyright__ = '2008 Kovid Goyal ' diff --git a/src/calibre/gui2/dialogs/config.py b/src/calibre/gui2/dialogs/config.py index 831d44251e..1b2a2b8702 100644 --- a/src/calibre/gui2/dialogs/config.py +++ b/src/calibre/gui2/dialogs/config.py @@ -18,7 +18,7 @@ from calibre.utils.config import prefs from calibre.gui2.widgets import FilenamePattern from calibre.gui2.library import BooksModel from calibre.ebooks import BOOK_EXTENSIONS -from calibre.ebooks.epub.iterator import is_supported +from calibre.ebooks.oeb.iterator import is_supported from calibre.library import server_config from calibre.customize.ui import initialized_plugins, is_disabled, enable_plugin, \ disable_plugin, customize_plugin, \ diff --git a/src/calibre/gui2/dialogs/config.ui b/src/calibre/gui2/dialogs/config.ui index 9afcac8914..ac432c52c0 100644 --- a/src/calibre/gui2/dialogs/config.ui +++ b/src/calibre/gui2/dialogs/config.ui @@ -1,9 +1,8 @@ - - + Kovid Goyal Dialog - - + + 0 0 @@ -11,108 +10,111 @@ 557 - + Configuration - - + + :/images/config.svg:/images/config.svg - - - + + + - - - + + + 1 0 - + 75 true - + + QAbstractItemView::NoEditTriggers + + true - + false - + 48 48 - + QAbstractItemView::ScrollPerItem - + QAbstractItemView::ScrollPerPixel - + QListView::TopToBottom - + 20 - + QListView::ListMode - - - + + + 100 0 - + 0 - - + + - + - - + + 16777215 70 - + &Location of ebooks (The ebooks are stored in folders sorted by author and metadata is stored in the file metadata.db) - + true - + location - + - + - - + + Browse for the new database location - + ... - - + + :/images/mimetypes/dir.svg:/images/mimetypes/dir.svg @@ -122,107 +124,107 @@ - - + + Show notification when &new version is available - - + + If you disable this setting, metadata is guessed from the filename instead. This can be configured in the Advanced section. - + Read &metadata from files - + true - - - - + + + + Format for &single file save: - + single_format - - + + - - - + + + Default network &timeout: - + timeout - - - + + + Set the default timeout for network fetches (i.e. anytime we go out to the internet to get information) - + seconds - + 2 - + 120 - + 5 - - + + - - - + + + Choose &language (requires restart): - + language - - + + - + Normal - + High - + Low - - - + + + Job &priority: - + priority @@ -230,19 +232,19 @@ - - + + Frequently used directories - - - + + + - - + + true - + 22 22 @@ -251,13 +253,13 @@ - + - + Qt::Vertical - + 20 40 @@ -266,25 +268,25 @@ - - + + Add a directory to the frequently used directories list - + ... - - + + :/images/plus.svg:/images/plus.svg - + Qt::Vertical - + 20 40 @@ -293,25 +295,25 @@ - - + + Remove a directory from the frequently used directories list - + ... - - + + :/images/list_remove.svg:/images/list_remove.svg - + Qt::Vertical - + 20 40 @@ -328,111 +330,111 @@ - - + + - - + + Use &Roman numerals for series number - + true - - + + Enable system &tray icon (needs restart) - - + + Show &notifications in system tray - - + + Show cover &browser in a separate window (needs restart) - - + + Automatically send downloaded &news to ebook reader - - + + &Delete news from library when it is automatically sent to reader - + - - + + &Number of covers to show in browse mode (needs restart): - + cover_browse - + - - + + Toolbar - - - + + + - + Large - + Medium - + Small - - - + + + &Button size in toolbar - + toolbar_button_size - - - + + + Show &text in toolbar buttons - + true @@ -441,44 +443,44 @@ - + - - + + Select visible &columns in library view - + - + - - + + true - + QAbstractItemView::SelectRows - + - - + + ... - - + + :/images/arrow-up.svg:/images/arrow-up.svg - - + + Qt::Vertical - + 20 40 @@ -487,12 +489,12 @@ - - + + ... - - + + :/images/arrow-down.svg:/images/arrow-down.svg @@ -505,17 +507,17 @@ - - + + Use internal &viewer for: - - - - + + + + true - + QAbstractItemView::NoSelection @@ -536,99 +538,99 @@ - - - - - + + + + + calibre can send your books to you (or your reader) by email - + true - - + + - - + + Send email &from: - + email_from - - - <p>This is what will be present in the From: field of emails sent by calibre.<br> Set it to your email address + + + <p>This is what will be present in the From: field of emails sent by calibre.<br> Set it to your email address - - + + - - + + QAbstractItemView::SingleSelection - + QAbstractItemView::SelectRows - + - - + + Add an email address to which to send books - + &Add email - - + + :/images/plus.svg:/images/plus.svg - + 24 24 - + Qt::ToolButtonTextUnderIcon - - + + Make &default - - + + &Remove email - - + + :/images/minus.svg:/images/minus.svg - + 24 24 - + Qt::ToolButtonTextUnderIcon @@ -637,155 +639,155 @@ - - - - <p>A mail server is useful if the service you are sending mail to only accepts email from well know mail services. + + + + <p>A mail server is useful if the service you are sending mail to only accepts email from well know mail services. - + Mail &Server - - - - - calibre can <b>optionally</b> use a server to send mail + + + + + calibre can <b>optionally</b> use a server to send mail - + true - - - + + + &Hostname: - + relay_host - - - + + + The hostname of your mail server. For e.g. smtp.gmail.com - - + + - - + + &Port: - + relay_port - - + + The port your mail server listens for connections on. The default is 25 - + 1 - + 65555 - + 25 - - - + + + &Username: - + relay_username - - - + + + Your username on the mail server - - - + + + &Password: - + relay_password - - - + + + Your password on the mail server - + QLineEdit::Password - - - + + + &Show - - - + + + &Encryption: - + relay_tls - - - + + + Use TLS encryption when connecting to the mail server. This is the most common. - + &TLS - + true - - - + + + Use SSL encryption when connecting to the mail server. - + &SSL - - - + + + Qt::Horizontal - + 40 20 @@ -796,31 +798,31 @@ - - + + - - + + Use Gmail - - + + :/images/gmail_logo.png:/images/gmail_logo.png - + 48 48 - + Qt::ToolButtonTextUnderIcon - - + + &Test email @@ -829,16 +831,16 @@ - - + + - + - + Qt::Horizontal - + 40 20 @@ -847,21 +849,21 @@ - - + + Free unused diskspace from the database - + &Compact database - + Qt::Horizontal - + 40 20 @@ -872,17 +874,17 @@ - - + + &Metadata from file name - + - + Qt::Vertical - + 20 40 @@ -895,96 +897,96 @@ - - + + - - + + calibre contains a network server that allows you to access your book collection using a browser from anywhere in the world. Any changes to the settings will only take effect after a server restart. - + true - - - - + + + + Server &port: - + port - - - + + + 1025 - + 16000 - + 8080 - - - + + + &Username: - + username - - + + - - - + + + &Password: - + password - - - + + + If you leave the password blank, anyone will be able to access your book collection using the web interface. - - - + + + &Show password - - - + + + The maximum size (widthxheight) for displayed covers. Larger covers are resized. - + - - - + + + Max. &cover size: - + max_cover_size @@ -992,27 +994,27 @@ - + - - + + &Start Server - - + + St&op Server - - + + Qt::Horizontal - + 40 20 @@ -1021,8 +1023,8 @@ - - + + &Test Server @@ -1030,25 +1032,25 @@ - - + + Run server &automatically on startup - - + + View &server logs - - + + Qt::Vertical - + 20 40 @@ -1057,21 +1059,21 @@ - - + + If you want to use the content server to access your ebook collection on your iphone with Stanza, you will need to add the URL http://myhostname:8080/stanza as a new catalog in the stanza reader on your iphone. Here myhostname should be the fully qualified hostname or the IP address of this computer. - + true - - + + Qt::Vertical - + 20 40 @@ -1081,53 +1083,53 @@ - - + + - - + + Here you can customize the behavior of Calibre by controlling what plugins it uses. - + true - - + + 32 32 - + true - + true - + - - + + Enable/&Disable plugin - - + + &Customize plugin - - + + &Remove plugin @@ -1135,33 +1137,33 @@ - - + + Add new plugin - + - + - - + + Plugin &file: - + plugin_path - + - - + + ... - - + + :/images/document_open.svg:/images/document_open.svg @@ -1169,13 +1171,13 @@ - + - - + + Qt::Horizontal - + 40 20 @@ -1184,8 +1186,8 @@ - - + + &Add @@ -1201,12 +1203,12 @@ - - - + + + Qt::Horizontal - + QDialogButtonBox::Cancel|QDialogButtonBox::Ok @@ -1214,7 +1216,7 @@ - + @@ -1223,11 +1225,11 @@ Dialog accept() - + 239 558 - + 157 274 @@ -1239,11 +1241,11 @@ Dialog reject() - + 307 558 - + 286 274