mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
KG updates
This commit is contained in:
commit
a24714b030
@ -7,7 +7,6 @@ __copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import posixpath
|
|
||||||
|
|
||||||
from calibre import guess_type, walk
|
from calibre import guess_type, walk
|
||||||
from calibre.customize.conversion import InputFormatPlugin
|
from calibre.customize.conversion import InputFormatPlugin
|
||||||
@ -74,22 +73,23 @@ class HTMLZInput(InputFormatPlugin):
|
|||||||
meta_info_to_oeb_metadata(mi, oeb.metadata, log)
|
meta_info_to_oeb_metadata(mi, oeb.metadata, log)
|
||||||
|
|
||||||
# Get the cover path from the OPF.
|
# Get the cover path from the OPF.
|
||||||
cover_href = None
|
cover_path = None
|
||||||
opf = None
|
opf = None
|
||||||
for x in walk('.'):
|
for x in walk('.'):
|
||||||
if os.path.splitext(x)[1].lower() in ('.opf'):
|
if os.path.splitext(x)[1].lower() in ('.opf'):
|
||||||
opf = x
|
opf = x
|
||||||
break
|
break
|
||||||
if opf:
|
if opf:
|
||||||
opf = OPF(opf)
|
opf = OPF(opf, basedir=os.getcwd())
|
||||||
cover_href = posixpath.relpath(opf.cover, os.path.dirname(stream.name))
|
cover_path = opf.raster_cover
|
||||||
# Set the cover.
|
# Set the cover.
|
||||||
if cover_href:
|
if cover_path:
|
||||||
cdata = None
|
cdata = None
|
||||||
with open(cover_href, 'rb') as cf:
|
with open(os.path.join(os.getcwd(), cover_path), 'rb') as cf:
|
||||||
cdata = cf.read()
|
cdata = cf.read()
|
||||||
id, href = oeb.manifest.generate('cover', cover_href)
|
cover_name = os.path.basename(cover_path)
|
||||||
oeb.manifest.add(id, href, guess_type(cover_href)[0], data=cdata)
|
id, href = oeb.manifest.generate('cover', cover_name)
|
||||||
|
oeb.manifest.add(id, href, guess_type(cover_name)[0], data=cdata)
|
||||||
oeb.guide.add('cover', 'Cover', href)
|
oeb.guide.add('cover', 'Cover', href)
|
||||||
|
|
||||||
return oeb
|
return oeb
|
||||||
|
@ -8,12 +8,11 @@ Read meta information from extZ (TXTZ, HTMLZ...) files.
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import posixpath
|
|
||||||
|
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
|
||||||
from calibre.ebooks.metadata import MetaInformation
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
from calibre.ebooks.metadata.opf2 import OPF, metadata_to_opf
|
from calibre.ebooks.metadata.opf2 import OPF
|
||||||
from calibre.ptempfile import PersistentTemporaryFile
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
from calibre.utils.zipfile import ZipFile, safe_replace
|
from calibre.utils.zipfile import ZipFile, safe_replace
|
||||||
|
|
||||||
@ -31,9 +30,9 @@ def get_metadata(stream, extract_cover=True):
|
|||||||
opf = OPF(opf_stream)
|
opf = OPF(opf_stream)
|
||||||
mi = opf.to_book_metadata()
|
mi = opf.to_book_metadata()
|
||||||
if extract_cover:
|
if extract_cover:
|
||||||
cover_href = posixpath.relpath(opf.cover, os.path.dirname(stream.name))
|
cover_href = opf.raster_cover
|
||||||
if cover_href:
|
if cover_href:
|
||||||
mi.cover_data = ('jpg', zf.read(cover_href))
|
mi.cover_data = (os.path.splitext(cover_href)[1], zf.read(cover_href))
|
||||||
except:
|
except:
|
||||||
return mi
|
return mi
|
||||||
return mi
|
return mi
|
||||||
@ -59,18 +58,15 @@ def set_metadata(stream, mi):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
if new_cdata:
|
if new_cdata:
|
||||||
cover = opf.cover
|
cpath = opf.raster_cover
|
||||||
if not cover:
|
if not cpath:
|
||||||
cover = 'cover.jpg'
|
cpath = 'cover.jpg'
|
||||||
cpath = posixpath.join(posixpath.dirname(opf_path), cover)
|
|
||||||
new_cover = _write_new_cover(new_cdata, cpath)
|
new_cover = _write_new_cover(new_cdata, cpath)
|
||||||
replacements[cpath] = open(new_cover.name, 'rb')
|
replacements[cpath] = open(new_cover.name, 'rb')
|
||||||
mi.cover = cover
|
mi.cover = cpath
|
||||||
|
|
||||||
# Update the metadata.
|
# Update the metadata.
|
||||||
old_mi = opf.to_book_metadata()
|
opf.smart_update(mi, replace_metadata=True)
|
||||||
old_mi.smart_update(mi)
|
|
||||||
opf.smart_update(metadata_to_opf(old_mi), replace_metadata=True)
|
|
||||||
newopf = StringIO(opf.render())
|
newopf = StringIO(opf.render())
|
||||||
safe_replace(stream, opf_path, newopf, extra_replacements=replacements, add_missing=True)
|
safe_replace(stream, opf_path, newopf, extra_replacements=replacements, add_missing=True)
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ class MetadataSingleDialogBase(ResizableDialog):
|
|||||||
view_format = pyqtSignal(object, object)
|
view_format = pyqtSignal(object, object)
|
||||||
cc_two_column = tweaks['metadata_single_use_2_cols_for_custom_fields']
|
cc_two_column = tweaks['metadata_single_use_2_cols_for_custom_fields']
|
||||||
one_line_comments_toolbar = False
|
one_line_comments_toolbar = False
|
||||||
|
use_toolbutton_for_config_metadata = True
|
||||||
|
|
||||||
def __init__(self, db, parent=None):
|
def __init__(self, db, parent=None):
|
||||||
self.db = db
|
self.db = db
|
||||||
@ -71,7 +72,9 @@ class MetadataSingleDialogBase(ResizableDialog):
|
|||||||
self.l.addWidget(self.scroll_area)
|
self.l.addWidget(self.scroll_area)
|
||||||
ll = self.button_box_layout = QHBoxLayout()
|
ll = self.button_box_layout = QHBoxLayout()
|
||||||
self.l.addLayout(ll)
|
self.l.addLayout(ll)
|
||||||
|
ll.addSpacing(10)
|
||||||
ll.addWidget(self.button_box)
|
ll.addWidget(self.button_box)
|
||||||
|
ll.addSpacing(10)
|
||||||
|
|
||||||
self.setWindowIcon(QIcon(I('edit_input.png')))
|
self.setWindowIcon(QIcon(I('edit_input.png')))
|
||||||
self.setWindowTitle(_('Edit Metadata'))
|
self.setWindowTitle(_('Edit Metadata'))
|
||||||
@ -191,7 +194,12 @@ class MetadataSingleDialogBase(ResizableDialog):
|
|||||||
font.setBold(True)
|
font.setBold(True)
|
||||||
self.fetch_metadata_button.setFont(font)
|
self.fetch_metadata_button.setFont(font)
|
||||||
|
|
||||||
self.config_metadata_button = QToolButton(self)
|
if self.use_toolbutton_for_config_metadata:
|
||||||
|
self.config_metadata_button = QToolButton(self)
|
||||||
|
self.config_metadata_button.setIcon(QIcon(I('config.png')))
|
||||||
|
else:
|
||||||
|
self.config_metadata_button = QPushButton(self)
|
||||||
|
self.config_metadata_button.setText(_('Configure download metadata'))
|
||||||
self.config_metadata_button.setIcon(QIcon(I('config.png')))
|
self.config_metadata_button.setIcon(QIcon(I('config.png')))
|
||||||
self.config_metadata_button.clicked.connect(self.configure_metadata)
|
self.config_metadata_button.clicked.connect(self.configure_metadata)
|
||||||
self.config_metadata_button.setToolTip(
|
self.config_metadata_button.setToolTip(
|
||||||
@ -614,6 +622,7 @@ class MetadataSingleDialogAlt1(MetadataSingleDialogBase): # {{{
|
|||||||
|
|
||||||
cc_two_column = False
|
cc_two_column = False
|
||||||
one_line_comments_toolbar = True
|
one_line_comments_toolbar = True
|
||||||
|
use_toolbutton_for_config_metadata = False
|
||||||
|
|
||||||
on_drag_enter = pyqtSignal()
|
on_drag_enter = pyqtSignal()
|
||||||
|
|
||||||
@ -649,10 +658,8 @@ class MetadataSingleDialogAlt1(MetadataSingleDialogBase): # {{{
|
|||||||
self.tabs[0].l.addWidget(gb, 0, 0, 1, 1)
|
self.tabs[0].l.addWidget(gb, 0, 0, 1, 1)
|
||||||
gb.setLayout(tl)
|
gb.setLayout(tl)
|
||||||
|
|
||||||
self.button_box_layout.insertWidget(0, self.fetch_metadata_button)
|
self.button_box_layout.insertWidget(1, self.fetch_metadata_button)
|
||||||
self.config_metadata_button.setToolButtonStyle(Qt.ToolButtonTextOnly)
|
self.button_box_layout.insertWidget(2, self.config_metadata_button)
|
||||||
self.config_metadata_button.setText(_('Configure metadata downloading'))
|
|
||||||
self.button_box_layout.insertWidget(1, self.config_metadata_button)
|
|
||||||
sto(self.button_box, self.fetch_metadata_button)
|
sto(self.button_box, self.fetch_metadata_button)
|
||||||
sto(self.fetch_metadata_button, self.config_metadata_button)
|
sto(self.fetch_metadata_button, self.config_metadata_button)
|
||||||
sto(self.config_metadata_button, self.title)
|
sto(self.config_metadata_button, self.title)
|
||||||
@ -767,6 +774,7 @@ class MetadataSingleDialogAlt2(MetadataSingleDialogBase): # {{{
|
|||||||
|
|
||||||
cc_two_column = False
|
cc_two_column = False
|
||||||
one_line_comments_toolbar = True
|
one_line_comments_toolbar = True
|
||||||
|
use_toolbutton_for_config_metadata = False
|
||||||
|
|
||||||
def do_layout(self):
|
def do_layout(self):
|
||||||
self.central_widget.clear()
|
self.central_widget.clear()
|
||||||
@ -785,10 +793,8 @@ class MetadataSingleDialogAlt2(MetadataSingleDialogBase): # {{{
|
|||||||
l.addWidget(gb, 0, 0, 1, 1)
|
l.addWidget(gb, 0, 0, 1, 1)
|
||||||
gb.setLayout(tl)
|
gb.setLayout(tl)
|
||||||
|
|
||||||
self.button_box_layout.insertWidget(0, self.fetch_metadata_button)
|
self.button_box_layout.insertWidget(1, self.fetch_metadata_button)
|
||||||
self.config_metadata_button.setToolButtonStyle(Qt.ToolButtonTextOnly)
|
self.button_box_layout.insertWidget(2, self.config_metadata_button)
|
||||||
self.config_metadata_button.setText(_('Configure metadata downloading'))
|
|
||||||
self.button_box_layout.insertWidget(1, self.config_metadata_button)
|
|
||||||
sto(self.button_box, self.fetch_metadata_button)
|
sto(self.button_box, self.fetch_metadata_button)
|
||||||
sto(self.fetch_metadata_button, self.config_metadata_button)
|
sto(self.fetch_metadata_button, self.config_metadata_button)
|
||||||
sto(self.config_metadata_button, self.title)
|
sto(self.config_metadata_button, self.title)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user