Catalogs: Fix AZW3 output not properly indexed

This commit is contained in:
Kovid Goyal 2012-09-16 20:12:20 +05:30
commit ac59059083
2 changed files with 79 additions and 51 deletions

View File

@ -360,13 +360,14 @@ class EPUB_MOBI(CatalogPlugin):
recommendations.append(('debug_pipeline', dp, recommendations.append(('debug_pipeline', dp,
OptionRecommendation.HIGH)) OptionRecommendation.HIGH))
if opts.fmt == 'mobi' and opts.output_profile and opts.output_profile.startswith("kindle"): if opts.output_profile and opts.output_profile.startswith("kindle"):
recommendations.append(('output_profile', opts.output_profile, recommendations.append(('output_profile', opts.output_profile,
OptionRecommendation.HIGH)) OptionRecommendation.HIGH))
recommendations.append(('no_inline_toc', True,
OptionRecommendation.HIGH))
recommendations.append(('book_producer',opts.output_profile, recommendations.append(('book_producer',opts.output_profile,
OptionRecommendation.HIGH)) OptionRecommendation.HIGH))
if opts.fmt == 'mobi':
recommendations.append(('no_inline_toc', True,
OptionRecommendation.HIGH))
# Use existing cover or generate new cover # Use existing cover or generate new cover
cpath = None cpath = None

View File

@ -33,6 +33,12 @@ class CatalogBuilder(object):
catalog = Catalog(notification=Reporter()) catalog = Catalog(notification=Reporter())
catalog.build_sources() catalog.build_sources()
Options managed in gui2.catalog.catalog_epub_mobi.py Options managed in gui2.catalog.catalog_epub_mobi.py
Turned off fetch_bookmarks as of 0.8.70
self.generate_recently_read = True if (_opts.generate_recently_added and
_opts.connected_kindle and
self.generate_for_kindle_mobi) else False
Does not work with AZW3, interferes with new prefix handling
''' '''
DEBUG = False DEBUG = False
@ -85,9 +91,9 @@ class CatalogBuilder(object):
@property @property
def SYMBOL_READING(self): def SYMBOL_READING(self):
if self.generate_for_kindle_mobi: if self.generate_for_kindle_mobi:
return self.format_prefix('▷') return '▷'
else: else:
return self.format_prefix(' ') return ' '
def __init__(self, db, _opts, plugin, def __init__(self, db, _opts, plugin,
@ -123,9 +129,7 @@ class CatalogBuilder(object):
self.content_dir = os.path.join(self.catalog_path, "content") self.content_dir = os.path.join(self.catalog_path, "content")
self.current_step = 0.0 self.current_step = 0.0
self.error = [] self.error = []
self.generate_recently_read = True if (_opts.generate_recently_added and self.generate_recently_read = False
_opts.connected_kindle and
self.generate_for_kindle_mobi) else False
self.genres = [] self.genres = []
self.genre_tags_dict = None self.genre_tags_dict = None
self.html_filelist_1 = [] self.html_filelist_1 = []
@ -460,8 +464,9 @@ class CatalogBuilder(object):
catalog_resources = P("catalog") catalog_resources = P("catalog")
files_to_copy = [('','DefaultCover.jpg'), files_to_copy = [('','DefaultCover.jpg'),
('content','stylesheet.css'), ('content','stylesheet.css')]
('images','mastheadImage.gif')] if self.generate_for_kindle_mobi:
files_to_copy.extend([('images','mastheadImage.gif')])
for file in files_to_copy: for file in files_to_copy:
if file[0] == '': if file[0] == '':
@ -958,7 +963,7 @@ class CatalogBuilder(object):
""" """
from calibre.devices.usbms.device import Device from calibre.devices.usbms.device import Device
from calibre.devices.kindle.driver import Bookmark from calibre.devices.kindle.bookmark import Bookmark
from calibre.ebooks.metadata import MetaInformation from calibre.ebooks.metadata import MetaInformation
MBP_FORMATS = [u'azw', u'mobi', u'prc', u'txt'] MBP_FORMATS = [u'azw', u'mobi', u'prc', u'txt']
@ -984,7 +989,10 @@ class CatalogBuilder(object):
file_fmts.add(fmt) file_fmts.add(fmt)
bookmark_extension = None bookmark_extension = None
if file_fmts.intersection(mbp_formats): if file_fmts.intersection(han_formats):
book_extension = list(file_fmts.intersection(han_formats))[0]
bookmark_extension = 'han'
elif file_fmts.intersection(mbp_formats):
book_extension = list(file_fmts.intersection(mbp_formats))[0] book_extension = list(file_fmts.intersection(mbp_formats))[0]
bookmark_extension = 'mbp' bookmark_extension = 'mbp'
elif file_fmts.intersection(tan_formats): elif file_fmts.intersection(tan_formats):
@ -1011,6 +1019,7 @@ class CatalogBuilder(object):
path_map.pop(id) path_map.pop(id)
return path_map, book_ext return path_map, book_ext
self.bookmarked_books = {}
if self.generate_recently_read: if self.generate_recently_read:
self.opts.log.info(" Collecting Kindle bookmarks matching catalog entries") self.opts.log.info(" Collecting Kindle bookmarks matching catalog entries")
@ -1045,8 +1054,6 @@ class CatalogBuilder(object):
bookmarks[id] = ((myBookmark,book)) bookmarks[id] = ((myBookmark,book))
self.bookmarked_books = bookmarks self.bookmarked_books = bookmarks
else:
self.bookmarked_books = {}
def filter_db_tags(self): def filter_db_tags(self):
""" Remove excluded tags from data set, return normalized genre list. """ Remove excluded tags from data set, return normalized genre list.
@ -2781,6 +2788,7 @@ class CatalogBuilder(object):
ncx = soup.find('ncx') ncx = soup.find('ncx')
navMapTag = Tag(soup, 'navMap') navMapTag = Tag(soup, 'navMap')
navPointTag = Tag(soup, 'navPoint') navPointTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointTag['class'] = "periodical" navPointTag['class'] = "periodical"
navPointTag['id'] = "title" navPointTag['id'] = "title"
navPointTag['playOrder'] = self.play_order navPointTag['playOrder'] = self.play_order
@ -2820,12 +2828,13 @@ class CatalogBuilder(object):
contentTag['src'] = "content/book_%d.html" % int(sort_descriptions_by[0]['id']) contentTag['src'] = "content/book_%d.html" % int(sort_descriptions_by[0]['id'])
navPointTag.insert(1, contentTag) navPointTag.insert(1, contentTag)
if self.generate_for_kindle_mobi:
cmiTag = Tag(soup, '%s' % 'calibre:meta-img') cmiTag = Tag(soup, '%s' % 'calibre:meta-img')
cmiTag['id'] = "mastheadImage" cmiTag['id'] = "mastheadImage"
cmiTag['src'] = "images/mastheadImage.gif" cmiTag['src'] = "images/mastheadImage.gif"
navPointTag.insert(2,cmiTag) navPointTag.insert(2,cmiTag)
navMapTag.insert(0,navPointTag)
navMapTag.insert(0,navPointTag)
ncx.insert(0,navMapTag) ncx.insert(0,navMapTag)
self.ncx_soup = soup self.ncx_soup = soup
@ -2846,15 +2855,19 @@ class CatalogBuilder(object):
self.update_progress_full_step(_("NCX for Descriptions")) self.update_progress_full_step(_("NCX for Descriptions"))
# --- Construct the 'Books by Title' section --- sort_descriptions_by = self.books_by_author if self.opts.sort_descriptions_by_author \
else self.books_by_title
# --- Construct the 'Descriptions' section ---
ncx_soup = self.ncx_soup ncx_soup = self.ncx_soup
body = ncx_soup.find("navPoint") body = ncx_soup.find("navPoint")
btc = len(body.contents) btc = len(body.contents)
# Add the section navPoint # Add the section navPoint
navPointTag = Tag(ncx_soup, 'navPoint') navPointTag = Tag(ncx_soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointTag['class'] = "section" navPointTag['class'] = "section"
navPointTag['id'] = "bytitle-ID" navPointTag['id'] = "bydescription-ID"
navPointTag['playOrder'] = self.play_order navPointTag['playOrder'] = self.play_order
self.play_order += 1 self.play_order += 1
navLabelTag = Tag(ncx_soup, 'navLabel') navLabelTag = Tag(ncx_soup, 'navLabel')
@ -2865,16 +2878,15 @@ class CatalogBuilder(object):
navPointTag.insert(nptc, navLabelTag) navPointTag.insert(nptc, navLabelTag)
nptc += 1 nptc += 1
contentTag = Tag(ncx_soup,"content") contentTag = Tag(ncx_soup,"content")
contentTag['src'] = "content/book_%d.html" % int(self.books_by_title[0]['id']) contentTag['src'] = "content/book_%d.html" % int(sort_descriptions_by[0]['id'])
navPointTag.insert(nptc, contentTag) navPointTag.insert(nptc, contentTag)
nptc += 1 nptc += 1
# Loop over the titles # Loop over the titles
sort_descriptions_by = self.books_by_author if self.opts.sort_descriptions_by_author \
else self.books_by_title
for book in sort_descriptions_by: for book in sort_descriptions_by:
navPointVolumeTag = Tag(ncx_soup, 'navPoint') navPointVolumeTag = Tag(ncx_soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointVolumeTag['class'] = "article" navPointVolumeTag['class'] = "article"
navPointVolumeTag['id'] = "book%dID" % int(book['id']) navPointVolumeTag['id'] = "book%dID" % int(book['id'])
navPointVolumeTag['playOrder'] = self.play_order navPointVolumeTag['playOrder'] = self.play_order
@ -2979,6 +2991,7 @@ class CatalogBuilder(object):
# --- Construct the 'Books By Series' section --- # --- Construct the 'Books By Series' section ---
navPointTag = Tag(soup, 'navPoint') navPointTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointTag['class'] = "section" navPointTag['class'] = "section"
navPointTag['id'] = "byseries-ID" navPointTag['id'] = "byseries-ID"
navPointTag['playOrder'] = self.play_order navPointTag['playOrder'] = self.play_order
@ -3035,6 +3048,7 @@ class CatalogBuilder(object):
# Add *article* entries for each populated series title letter # Add *article* entries for each populated series title letter
for (i,books) in enumerate(series_by_letter): for (i,books) in enumerate(series_by_letter):
navPointByLetterTag = Tag(soup, 'navPoint') navPointByLetterTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointByLetterTag['class'] = "article" navPointByLetterTag['class'] = "article"
navPointByLetterTag['id'] = "%sSeries-ID" % (title_letters[i].upper()) navPointByLetterTag['id'] = "%sSeries-ID" % (title_letters[i].upper())
navPointTag['playOrder'] = self.play_order navPointTag['playOrder'] = self.play_order
@ -3102,6 +3116,7 @@ class CatalogBuilder(object):
# --- Construct the 'Books By Title' section --- # --- Construct the 'Books By Title' section ---
navPointTag = Tag(soup, 'navPoint') navPointTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointTag['class'] = "section" navPointTag['class'] = "section"
navPointTag['id'] = "byalphatitle-ID" navPointTag['id'] = "byalphatitle-ID"
navPointTag['playOrder'] = self.play_order navPointTag['playOrder'] = self.play_order
@ -3160,6 +3175,7 @@ class CatalogBuilder(object):
# Add *article* entries for each populated title letter # Add *article* entries for each populated title letter
for (i,books) in enumerate(books_by_letter): for (i,books) in enumerate(books_by_letter):
navPointByLetterTag = Tag(soup, 'navPoint') navPointByLetterTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointByLetterTag['class'] = "article" navPointByLetterTag['class'] = "article"
navPointByLetterTag['id'] = "%sTitles-ID" % (title_letters[i].upper()) navPointByLetterTag['id'] = "%sTitles-ID" % (title_letters[i].upper())
navPointTag['playOrder'] = self.play_order navPointTag['playOrder'] = self.play_order
@ -3225,6 +3241,7 @@ class CatalogBuilder(object):
# --- Construct the 'Books By Author' *section* --- # --- Construct the 'Books By Author' *section* ---
navPointTag = Tag(soup, 'navPoint') navPointTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointTag['class'] = "section" navPointTag['class'] = "section"
file_ID = "%s" % tocTitle.lower() file_ID = "%s" % tocTitle.lower()
file_ID = file_ID.replace(" ","") file_ID = file_ID.replace(" ","")
@ -3275,6 +3292,7 @@ class CatalogBuilder(object):
# master_author_list{}: [0]:author list [1]:Initial letter # master_author_list{}: [0]:author list [1]:Initial letter
for authors_by_letter in master_author_list: for authors_by_letter in master_author_list:
navPointByLetterTag = Tag(soup, 'navPoint') navPointByLetterTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointByLetterTag['class'] = "article" navPointByLetterTag['class'] = "article"
navPointByLetterTag['id'] = "%sauthors-ID" % (authors_by_letter[1]) navPointByLetterTag['id'] = "%sauthors-ID" % (authors_by_letter[1])
navPointTag['playOrder'] = self.play_order navPointTag['playOrder'] = self.play_order
@ -3346,6 +3364,7 @@ class CatalogBuilder(object):
# --- Construct the 'Recently Added' *section* --- # --- Construct the 'Recently Added' *section* ---
navPointTag = Tag(soup, 'navPoint') navPointTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointTag['class'] = "section" navPointTag['class'] = "section"
file_ID = "%s" % tocTitle.lower() file_ID = "%s" % tocTitle.lower()
file_ID = file_ID.replace(" ","") file_ID = file_ID.replace(" ","")
@ -3390,6 +3409,7 @@ class CatalogBuilder(object):
# master_date_range_list{}: [0]:titles list [1]:datestr # master_date_range_list{}: [0]:titles list [1]:datestr
for books_by_date_range in master_date_range_list: for books_by_date_range in master_date_range_list:
navPointByDateRangeTag = Tag(soup, 'navPoint') navPointByDateRangeTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointByDateRangeTag['class'] = "article" navPointByDateRangeTag['class'] = "article"
navPointByDateRangeTag['id'] = "%s-ID" % books_by_date_range[1].replace(' ','') navPointByDateRangeTag['id'] = "%s-ID" % books_by_date_range[1].replace(' ','')
navPointTag['playOrder'] = self.play_order navPointTag['playOrder'] = self.play_order
@ -3449,6 +3469,7 @@ class CatalogBuilder(object):
for books_by_month in master_month_list: for books_by_month in master_month_list:
datestr = strftime(u'%B %Y', books_by_month[1].timetuple()) datestr = strftime(u'%B %Y', books_by_month[1].timetuple())
navPointByMonthTag = Tag(soup, 'navPoint') navPointByMonthTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointByMonthTag['class'] = "article" navPointByMonthTag['class'] = "article"
navPointByMonthTag['id'] = "bda_%s-%s-ID" % (books_by_month[1].year,books_by_month[1].month ) navPointByMonthTag['id'] = "bda_%s-%s-ID" % (books_by_month[1].year,books_by_month[1].month )
navPointTag['playOrder'] = self.play_order navPointTag['playOrder'] = self.play_order
@ -3524,6 +3545,7 @@ class CatalogBuilder(object):
# --- Construct the 'Recently Read' *section* --- # --- Construct the 'Recently Read' *section* ---
navPointTag = Tag(soup, 'navPoint') navPointTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointTag['class'] = "section" navPointTag['class'] = "section"
file_ID = "%s" % tocTitle.lower() file_ID = "%s" % tocTitle.lower()
file_ID = file_ID.replace(" ","") file_ID = file_ID.replace(" ","")
@ -3594,6 +3616,7 @@ class CatalogBuilder(object):
for books_by_day in master_day_list: for books_by_day in master_day_list:
datestr = strftime(u'%A, %B %d', books_by_day[1].timetuple()) datestr = strftime(u'%A, %B %d', books_by_day[1].timetuple())
navPointByDayTag = Tag(soup, 'navPoint') navPointByDayTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointByDayTag['class'] = "article" navPointByDayTag['class'] = "article"
navPointByDayTag['id'] = "bdr_%s-%s-%sID" % (books_by_day[1].year, navPointByDayTag['id'] = "bdr_%s-%s-%sID" % (books_by_day[1].year,
books_by_day[1].month, books_by_day[1].month,
@ -3662,6 +3685,7 @@ class CatalogBuilder(object):
# --- Construct the 'Books By Genre' *section* --- # --- Construct the 'Books By Genre' *section* ---
navPointTag = Tag(ncx_soup, 'navPoint') navPointTag = Tag(ncx_soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointTag['class'] = "section" navPointTag['class'] = "section"
file_ID = "%s" % tocTitle.lower() file_ID = "%s" % tocTitle.lower()
file_ID = file_ID.replace(" ","") file_ID = file_ID.replace(" ","")
@ -3684,6 +3708,7 @@ class CatalogBuilder(object):
for genre in self.genres: for genre in self.genres:
# Add an article for each genre # Add an article for each genre
navPointVolumeTag = Tag(ncx_soup, 'navPoint') navPointVolumeTag = Tag(ncx_soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointVolumeTag['class'] = "article" navPointVolumeTag['class'] = "article"
navPointVolumeTag['id'] = "genre-%s-ID" % genre['tag'] navPointVolumeTag['id'] = "genre-%s-ID" % genre['tag']
navPointVolumeTag['playOrder'] = self.play_order navPointVolumeTag['playOrder'] = self.play_order
@ -3823,6 +3848,7 @@ class CatalogBuilder(object):
manifest.insert(mtc, itemTag) manifest.insert(mtc, itemTag)
mtc += 1 mtc += 1
if self.generate_for_kindle_mobi:
itemTag = Tag(soup, "item") itemTag = Tag(soup, "item")
itemTag['id'] = 'mastheadimage-image' itemTag['id'] = 'mastheadimage-image'
itemTag['href'] = "images/mastheadImage.gif" itemTag['href'] = "images/mastheadImage.gif"
@ -3914,6 +3940,7 @@ class CatalogBuilder(object):
stc += 1 stc += 1
# Guide # Guide
if self.generate_for_kindle_mobi:
referenceTag = Tag(soup, "reference") referenceTag = Tag(soup, "reference")
referenceTag['type'] = 'masthead' referenceTag['type'] = 'masthead'
referenceTag['title'] = 'mastheadimage-image' referenceTag['title'] = 'mastheadimage-image'