mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Content server:Set metadata in EPUB files before sending. Fixes #2734 (Wrong ebook title/author)
This commit is contained in:
parent
065e647076
commit
48d01abb6c
@ -192,6 +192,7 @@ class OEBReader(object):
|
|||||||
if not scheme and href not in known:
|
if not scheme and href not in known:
|
||||||
new.add(href)
|
new.add(href)
|
||||||
unchecked.clear()
|
unchecked.clear()
|
||||||
|
warned = set([])
|
||||||
for href in new:
|
for href in new:
|
||||||
known.add(href)
|
known.add(href)
|
||||||
is_invalid = False
|
is_invalid = False
|
||||||
@ -202,9 +203,13 @@ class OEBReader(object):
|
|||||||
if is_invalid:
|
if is_invalid:
|
||||||
continue
|
continue
|
||||||
if not self.oeb.container.exists(href):
|
if not self.oeb.container.exists(href):
|
||||||
|
if href not in warned:
|
||||||
self.logger.warn('Referenced file %r not found' % href)
|
self.logger.warn('Referenced file %r not found' % href)
|
||||||
|
warned.add(href)
|
||||||
continue
|
continue
|
||||||
|
if href not in warned:
|
||||||
self.logger.warn('Referenced file %r not in manifest' % href)
|
self.logger.warn('Referenced file %r not in manifest' % href)
|
||||||
|
warned.add(href)
|
||||||
id, _ = manifest.generate(id='added')
|
id, _ = manifest.generate(id='added')
|
||||||
guessed = guess_type(href)[0]
|
guessed = guess_type(href)[0]
|
||||||
media_type = guessed or BINARY_MIME
|
media_type = guessed or BINARY_MIME
|
||||||
|
@ -15,6 +15,7 @@ from PyQt4.QtCore import QAbstractTableModel, QVariant, Qt, QString, \
|
|||||||
|
|
||||||
from calibre import strftime
|
from calibre import strftime
|
||||||
from calibre.ptempfile import PersistentTemporaryFile
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
|
from calibre.utils.pyparsing import ParseException
|
||||||
from calibre.library.database2 import FIELD_MAP
|
from calibre.library.database2 import FIELD_MAP
|
||||||
from calibre.gui2 import NONE, TableView, qstring_to_unicode, config, \
|
from calibre.gui2 import NONE, TableView, qstring_to_unicode, config, \
|
||||||
error_dialog
|
error_dialog
|
||||||
@ -240,7 +241,11 @@ class BooksModel(QAbstractTableModel):
|
|||||||
self.count_changed()
|
self.count_changed()
|
||||||
|
|
||||||
def search(self, text, refinement, reset=True):
|
def search(self, text, refinement, reset=True):
|
||||||
|
try:
|
||||||
self.db.search(text)
|
self.db.search(text)
|
||||||
|
except ParseException:
|
||||||
|
self.emit(SIGNAL('parse_exception()'))
|
||||||
|
return
|
||||||
self.last_search = text
|
self.last_search = text
|
||||||
if reset:
|
if reset:
|
||||||
self.clear_caches()
|
self.clear_caches()
|
||||||
@ -856,7 +861,12 @@ class DeviceBooksModel(BooksModel):
|
|||||||
if not text or not text.strip():
|
if not text or not text.strip():
|
||||||
self.map = list(range(len(self.db)))
|
self.map = list(range(len(self.db)))
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
matches = self.search_engine.parse(text)
|
matches = self.search_engine.parse(text)
|
||||||
|
except ParseException:
|
||||||
|
self.emit(SIGNAL('parse_exception()'))
|
||||||
|
return
|
||||||
|
|
||||||
self.map = []
|
self.map = []
|
||||||
for i in range(len(self.db)):
|
for i in range(len(self.db)):
|
||||||
if i in matches:
|
if i in matches:
|
||||||
|
@ -221,9 +221,20 @@ class LibraryServer(object):
|
|||||||
|
|
||||||
def get_format(self, id, format):
|
def get_format(self, id, format):
|
||||||
format = format.upper()
|
format = format.upper()
|
||||||
fmt = self.db.format(id, format, index_is_id=True, as_file=True, mode='rb')
|
fmt = self.db.format(id, format, index_is_id=True, as_file=True,
|
||||||
|
mode='r+b')
|
||||||
if fmt is None:
|
if fmt is None:
|
||||||
raise cherrypy.HTTPError(404, 'book: %d does not have format: %s'%(id, format))
|
raise cherrypy.HTTPError(404, 'book: %d does not have format: %s'%(id, format))
|
||||||
|
if format == 'EPUB':
|
||||||
|
from tempfile import TemporaryFile
|
||||||
|
from calibre.ebooks.metadata.meta import set_metadata
|
||||||
|
raw = fmt.read()
|
||||||
|
fmt = TemporaryFile()
|
||||||
|
fmt.write(raw)
|
||||||
|
fmt.seek(0)
|
||||||
|
set_metadata(fmt, self.db.get_metadata(id, index_is_id=True),
|
||||||
|
'epub')
|
||||||
|
fmt.seek(0)
|
||||||
mt = guess_type('dummy.'+format.lower())[0]
|
mt = guess_type('dummy.'+format.lower())[0]
|
||||||
if mt is None:
|
if mt is None:
|
||||||
mt = 'application/octet-stream'
|
mt = 'application/octet-stream'
|
||||||
|
@ -10,17 +10,31 @@ from calibre.web.feeds.news import BasicNewsRecipe
|
|||||||
class WallStreetJournal(BasicNewsRecipe):
|
class WallStreetJournal(BasicNewsRecipe):
|
||||||
|
|
||||||
title = 'The Wall Street Journal'
|
title = 'The Wall Street Journal'
|
||||||
__author__ = 'Kovid Goyal'
|
__author__ = 'Kovid Goyal and Sujata Raman'
|
||||||
description = 'News and current affairs.'
|
description = 'News and current affairs.'
|
||||||
needs_subscription = True
|
needs_subscription = True
|
||||||
language = _('English')
|
language = _('English')
|
||||||
max_articles_per_feed = 10
|
max_articles_per_feed = 10
|
||||||
timefmt = ' [%a, %b %d, %Y]'
|
timefmt = ' [%a, %b %d, %Y]'
|
||||||
no_stylesheets = True
|
no_stylesheets = True
|
||||||
|
|
||||||
|
extra_css = '''h1{color:#093D72 ; font-size:large ; font-family:Georgia,"Century Schoolbook","Times New Roman",Times,serif; }
|
||||||
|
h2{color:gray; font-family:Georgia,"Century Schoolbook","Times New Roman",Times,serif; font-size:small; font-style:italic;}
|
||||||
|
.subhead{color:gray; font-family:Georgia,"Century Schoolbook","Times New Roman",Times,serif; font-size:small; font-style:italic;}
|
||||||
|
.insettipUnit {color:#666666; font-family:Arial,Sans-serif;font-size:xx-small }
|
||||||
|
.targetCaption{ font-size:x-small; color:#333333; font-family:Arial,Helvetica,sans-serif}
|
||||||
|
.article{font-family :Arial,Helvetica,sans-serif; font-size:x-small}
|
||||||
|
.tagline {color:#333333; font-size:xx-small}
|
||||||
|
.dateStamp {color:#666666; font-family:Arial,Helvetica,sans-serif}
|
||||||
|
h3{color:blue ;font-family:Arial,Helvetica,sans-serif; font-size:xx-small}
|
||||||
|
.byline{color:blue;font-family:Arial,Helvetica,sans-serif; font-size:xx-small}
|
||||||
|
h6{color:#333333; font-family:Georgia,"Century Schoolbook","Times New Roman",Times,serif; font-size:small;font-style:italic; }
|
||||||
|
.paperLocation{color:#666666; font-size:xx-small}'''
|
||||||
|
|
||||||
remove_tags_before = dict(name='h1')
|
remove_tags_before = dict(name='h1')
|
||||||
remove_tags = [
|
remove_tags = [
|
||||||
dict(id=["articleTabs_tab_article", "articleTabs_tab_comments", "articleTabs_tab_interactive"]),
|
dict(id=["articleTabs_tab_article", "articleTabs_tab_comments", "articleTabs_tab_interactive","articleTabs_tab_video","articleTabs_tab_map","articleTabs_tab_slideshow"]),
|
||||||
{'class':['more_in', "insetContent", 'articleTools_bottom', 'aTools', "tooltip", "adSummary", "nav-inline"]},
|
{'class':['footer_columns','network','insetCol3wide','interactive','video','slideshow','map','insettip','more_in', "insetContent", 'articleTools_bottom', 'aTools', "tooltip", "adSummary", "nav-inline"]},
|
||||||
dict(rel='shortcut icon'),
|
dict(rel='shortcut icon'),
|
||||||
]
|
]
|
||||||
remove_tags_after = [dict(id="article_story_body"), {'class':"article story"},]
|
remove_tags_after = [dict(id="article_story_body"), {'class':"article story"},]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user