News download: Add list of articles in the downloaded issue to the comments metadata of the generated ebook. Makes it possible to search for a particular article in the calibre library. Fixes #851717 ([enhancement] News downloading options for search)

This commit is contained in:
Kovid Goyal 2011-09-25 13:17:40 -06:00
parent e62826e1b2
commit bebe2467cc

View File

@ -13,7 +13,7 @@ from functools import partial
from contextlib import nested, closing from contextlib import nested, closing
from calibre import (browser, __appname__, iswindows, from calibre import (browser, __appname__, iswindows, force_unicode,
strftime, preferred_encoding, as_unicode) strftime, preferred_encoding, as_unicode)
from calibre.ebooks.BeautifulSoup import BeautifulSoup, NavigableString, CData, Tag from calibre.ebooks.BeautifulSoup import BeautifulSoup, NavigableString, CData, Tag
from calibre.ebooks.metadata.opf2 import OPFCreator from calibre.ebooks.metadata.opf2 import OPFCreator
@ -49,7 +49,7 @@ class BasicNewsRecipe(Recipe):
#: A couple of lines that describe the content this recipe downloads. #: A couple of lines that describe the content this recipe downloads.
#: This will be used primarily in a GUI that presents a list of recipes. #: This will be used primarily in a GUI that presents a list of recipes.
description = '' description = u''
#: The author of this recipe #: The author of this recipe
__author__ = __appname__ __author__ = __appname__
@ -112,8 +112,6 @@ class BasicNewsRecipe(Recipe):
#: If set to "optional" the use of a username and password becomes optional #: If set to "optional" the use of a username and password becomes optional
needs_subscription = False needs_subscription = False
#:
#: If True the navigation bar is center aligned, otherwise it is left aligned #: If True the navigation bar is center aligned, otherwise it is left aligned
center_navbar = True center_navbar = True
@ -1205,12 +1203,22 @@ class BasicNewsRecipe(Recipe):
mi.author_sort = __appname__ mi.author_sort = __appname__
mi.publication_type = 'periodical:'+self.publication_type+':'+self.short_title() mi.publication_type = 'periodical:'+self.publication_type+':'+self.short_title()
mi.timestamp = nowf() mi.timestamp = nowf()
article_titles, aseen = [], set()
for f in feeds:
for a in f:
if a.title and a.title not in aseen:
aseen.add(a.title)
article_titles.append(force_unicode(a.title, 'utf-8'))
mi.comments = self.description mi.comments = self.description
if not isinstance(mi.comments, unicode):
mi.comments = mi.comments.decode('utf-8', 'replace')
mi.comments += ('\n\n' + _('Articles in this issue: ') + '\n' +
'\n\n'.join(article_titles))
language = canonicalize_lang(self.language) language = canonicalize_lang(self.language)
if language is not None: if language is not None:
mi.language = language mi.language = language
if not isinstance(mi.comments, unicode):
mi.comments = mi.comments.decode('utf-8', 'replace')
mi.pubdate = nowf() mi.pubdate = nowf()
opf_path = os.path.join(dir, 'index.opf') opf_path = os.path.join(dir, 'index.opf')
ncx_path = os.path.join(dir, 'index.ncx') ncx_path = os.path.join(dir, 'index.ncx')
@ -1256,6 +1264,7 @@ class BasicNewsRecipe(Recipe):
self.play_order_counter = 0 self.play_order_counter = 0
self.play_order_map = {} self.play_order_map = {}
def feed_index(num, parent): def feed_index(num, parent):
f = feeds[num] f = feeds[num]
for j, a in enumerate(f): for j, a in enumerate(f):