mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix for AZW3 catalogs - remove calibre <meta> tag
This commit is contained in:
parent
1cc0a6861d
commit
9b6c88a2ab
@ -9,6 +9,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import os, shutil
|
import os, shutil
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
from copy import deepcopy
|
||||||
|
|
||||||
from calibre import strftime
|
from calibre import strftime
|
||||||
from calibre.customize import CatalogPlugin
|
from calibre.customize import CatalogPlugin
|
||||||
@ -328,6 +329,9 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
# Launch the Catalog builder
|
# Launch the Catalog builder
|
||||||
catalog = CatalogBuilder(db, opts, self, report_progress=notification)
|
catalog = CatalogBuilder(db, opts, self, report_progress=notification)
|
||||||
|
|
||||||
|
# Save the output profile for the plumber
|
||||||
|
output_profile = deepcopy(catalog.output_profile)
|
||||||
|
|
||||||
if opts.verbose:
|
if opts.verbose:
|
||||||
log.info(" Begin catalog source generation")
|
log.info(" Begin catalog source generation")
|
||||||
|
|
||||||
@ -346,6 +350,8 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
recommendations.append(('remove_fake_margins', False,
|
recommendations.append(('remove_fake_margins', False,
|
||||||
OptionRecommendation.HIGH))
|
OptionRecommendation.HIGH))
|
||||||
recommendations.append(('comments', '', OptionRecommendation.HIGH))
|
recommendations.append(('comments', '', OptionRecommendation.HIGH))
|
||||||
|
recommendations.append(('output_profile', output_profile,
|
||||||
|
OptionRecommendation.HIGH))
|
||||||
|
|
||||||
"""
|
"""
|
||||||
>>> Use to debug generated catalog code before pipeline conversion <<<
|
>>> Use to debug generated catalog code before pipeline conversion <<<
|
||||||
@ -360,9 +366,7 @@ 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,
|
|
||||||
OptionRecommendation.HIGH))
|
|
||||||
recommendations.append(('no_inline_toc', True,
|
recommendations.append(('no_inline_toc', True,
|
||||||
OptionRecommendation.HIGH))
|
OptionRecommendation.HIGH))
|
||||||
recommendations.append(('book_producer',opts.output_profile,
|
recommendations.append(('book_producer',opts.output_profile,
|
||||||
|
@ -69,7 +69,7 @@ class CatalogBuilder(object):
|
|||||||
@property
|
@property
|
||||||
def SYMBOL_PROGRESS_READ(self):
|
def SYMBOL_PROGRESS_READ(self):
|
||||||
psr = '+'
|
psr = '+'
|
||||||
if self.generate_for_kindle:
|
if self.generate_for_kindle_mobi:
|
||||||
psr = '▪'
|
psr = '▪'
|
||||||
return psr
|
return psr
|
||||||
|
|
||||||
@ -77,14 +77,14 @@ class CatalogBuilder(object):
|
|||||||
@property
|
@property
|
||||||
def SYMBOL_PROGRESS_UNREAD(self):
|
def SYMBOL_PROGRESS_UNREAD(self):
|
||||||
psu = '-'
|
psu = '-'
|
||||||
if self.generate_for_kindle:
|
if self.generate_for_kindle_mobi:
|
||||||
psu = '▫'
|
psu = '▫'
|
||||||
return psu
|
return psu
|
||||||
|
|
||||||
''' device-specific symbol for reading progress '''
|
''' device-specific symbol for reading progress '''
|
||||||
@property
|
@property
|
||||||
def SYMBOL_READING(self):
|
def SYMBOL_READING(self):
|
||||||
if self.generate_for_kindle:
|
if self.generate_for_kindle_mobi:
|
||||||
return self.format_prefix('▷')
|
return self.format_prefix('▷')
|
||||||
else:
|
else:
|
||||||
return self.format_prefix(' ')
|
return self.format_prefix(' ')
|
||||||
@ -103,7 +103,7 @@ class CatalogBuilder(object):
|
|||||||
self.cache_dir = os.path.join(config_dir, 'caches', 'catalog')
|
self.cache_dir = os.path.join(config_dir, 'caches', 'catalog')
|
||||||
self.catalog_path = PersistentTemporaryDirectory("_epub_mobi_catalog", prefix='')
|
self.catalog_path = PersistentTemporaryDirectory("_epub_mobi_catalog", prefix='')
|
||||||
self.excluded_tags = self.get_excluded_tags()
|
self.excluded_tags = self.get_excluded_tags()
|
||||||
self.generate_for_kindle = True if (_opts.fmt == 'mobi' and
|
self.generate_for_kindle_mobi = True if (_opts.fmt == 'mobi' and
|
||||||
_opts.output_profile and
|
_opts.output_profile and
|
||||||
_opts.output_profile.startswith("kindle")) else False
|
_opts.output_profile.startswith("kindle")) else False
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ class CatalogBuilder(object):
|
|||||||
self.error = []
|
self.error = []
|
||||||
self.generate_recently_read = True if (_opts.generate_recently_added and
|
self.generate_recently_read = True if (_opts.generate_recently_added and
|
||||||
_opts.connected_kindle and
|
_opts.connected_kindle and
|
||||||
self.generate_for_kindle) else False
|
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 = []
|
||||||
@ -130,7 +130,6 @@ class CatalogBuilder(object):
|
|||||||
self.merge_comments_rule = dict(zip(['field','position','hr'],
|
self.merge_comments_rule = dict(zip(['field','position','hr'],
|
||||||
_opts.merge_comments_rule.split(':')))
|
_opts.merge_comments_rule.split(':')))
|
||||||
self.ncx_soup = None
|
self.ncx_soup = None
|
||||||
self.output_profile = None
|
|
||||||
self.output_profile = self.get_output_profile(_opts)
|
self.output_profile = self.get_output_profile(_opts)
|
||||||
self.play_order = 1
|
self.play_order = 1
|
||||||
self.prefix_rules = self.get_prefix_rules()
|
self.prefix_rules = self.get_prefix_rules()
|
||||||
@ -469,7 +468,7 @@ class CatalogBuilder(object):
|
|||||||
shutil.copy(os.path.join(catalog_resources,file[1]),
|
shutil.copy(os.path.join(catalog_resources,file[1]),
|
||||||
os.path.join(self.catalog_path, file[0]))
|
os.path.join(self.catalog_path, file[0]))
|
||||||
|
|
||||||
if self.generate_for_kindle:
|
if self.generate_for_kindle_mobi:
|
||||||
try:
|
try:
|
||||||
self.generate_masthead_image(os.path.join(self.catalog_path,
|
self.generate_masthead_image(os.path.join(self.catalog_path,
|
||||||
'images/mastheadImage.gif'))
|
'images/mastheadImage.gif'))
|
||||||
@ -1421,7 +1420,7 @@ class CatalogBuilder(object):
|
|||||||
pTag.insert(ptc, aTag)
|
pTag.insert(ptc, aTag)
|
||||||
ptc += 1
|
ptc += 1
|
||||||
|
|
||||||
if not self.generate_for_kindle:
|
if not self.generate_for_kindle_mobi:
|
||||||
# Kindle don't need this because it shows section titles in Periodical format
|
# Kindle don't need this because it shows section titles in Periodical format
|
||||||
aTag = Tag(soup, "a")
|
aTag = Tag(soup, "a")
|
||||||
anchor_name = friendly_name.lower()
|
anchor_name = friendly_name.lower()
|
||||||
@ -1629,7 +1628,7 @@ class CatalogBuilder(object):
|
|||||||
pTag.insert(ptc, aTag)
|
pTag.insert(ptc, aTag)
|
||||||
ptc += 1
|
ptc += 1
|
||||||
|
|
||||||
if not self.generate_for_kindle:
|
if not self.generate_for_kindle_mobi:
|
||||||
# Kindle don't need this because it shows section titles in Periodical format
|
# Kindle don't need this because it shows section titles in Periodical format
|
||||||
aTag = Tag(soup, "a")
|
aTag = Tag(soup, "a")
|
||||||
anchor_name = friendly_name.lower()
|
anchor_name = friendly_name.lower()
|
||||||
@ -2258,7 +2257,7 @@ class CatalogBuilder(object):
|
|||||||
pTag.insert(ptc, aTag)
|
pTag.insert(ptc, aTag)
|
||||||
ptc += 1
|
ptc += 1
|
||||||
|
|
||||||
if not self.generate_for_kindle:
|
if not self.generate_for_kindle_mobi:
|
||||||
# Insert the <h2> tag with book_count at the head
|
# Insert the <h2> tag with book_count at the head
|
||||||
aTag = Tag(soup, "a")
|
aTag = Tag(soup, "a")
|
||||||
anchor_name = friendly_name.lower()
|
anchor_name = friendly_name.lower()
|
||||||
@ -2304,7 +2303,7 @@ class CatalogBuilder(object):
|
|||||||
pTag.insert(ptc, aTag)
|
pTag.insert(ptc, aTag)
|
||||||
ptc += 1
|
ptc += 1
|
||||||
|
|
||||||
if not self.generate_for_kindle:
|
if not self.generate_for_kindle_mobi:
|
||||||
# Kindle don't need this because it shows section titles in Periodical format
|
# Kindle don't need this because it shows section titles in Periodical format
|
||||||
aTag = Tag(soup, "a")
|
aTag = Tag(soup, "a")
|
||||||
aTag['id'] = "bytitle"
|
aTag['id'] = "bytitle"
|
||||||
@ -2883,7 +2882,7 @@ class CatalogBuilder(object):
|
|||||||
series_index = str(book['series_index'])
|
series_index = str(book['series_index'])
|
||||||
if series_index.endswith('.0'):
|
if series_index.endswith('.0'):
|
||||||
series_index = series_index[:-2]
|
series_index = series_index[:-2]
|
||||||
if self.generate_for_kindle:
|
if self.generate_for_kindle_mobi:
|
||||||
# Don't include Author for Kindle
|
# Don't include Author for Kindle
|
||||||
textTag.insert(0, NavigableString(self.format_ncx_text('%s (%s [%s])' %
|
textTag.insert(0, NavigableString(self.format_ncx_text('%s (%s [%s])' %
|
||||||
(book['title'], book['series'], series_index), dest='title')))
|
(book['title'], book['series'], series_index), dest='title')))
|
||||||
@ -2892,7 +2891,7 @@ class CatalogBuilder(object):
|
|||||||
textTag.insert(0, NavigableString(self.format_ncx_text('%s (%s [%s]) · %s ' %
|
textTag.insert(0, NavigableString(self.format_ncx_text('%s (%s [%s]) · %s ' %
|
||||||
(book['title'], book['series'], series_index, book['author']), dest='title')))
|
(book['title'], book['series'], series_index, book['author']), dest='title')))
|
||||||
else:
|
else:
|
||||||
if self.generate_for_kindle:
|
if self.generate_for_kindle_mobi:
|
||||||
# Don't include Author for Kindle
|
# Don't include Author for Kindle
|
||||||
title_str = self.format_ncx_text('%s' % (book['title']), dest='title')
|
title_str = self.format_ncx_text('%s' % (book['title']), dest='title')
|
||||||
if self.opts.connected_kindle and book['id'] in self.bookmarked_books:
|
if self.opts.connected_kindle and book['id'] in self.bookmarked_books:
|
||||||
@ -2915,7 +2914,7 @@ class CatalogBuilder(object):
|
|||||||
contentTag['src'] = "content/book_%d.html#book%d" % (int(book['id']), int(book['id']))
|
contentTag['src'] = "content/book_%d.html#book%d" % (int(book['id']), int(book['id']))
|
||||||
navPointVolumeTag.insert(1, contentTag)
|
navPointVolumeTag.insert(1, contentTag)
|
||||||
|
|
||||||
if self.generate_for_kindle:
|
if self.generate_for_kindle_mobi:
|
||||||
# Add the author tag
|
# Add the author tag
|
||||||
cmTag = Tag(ncx_soup, '%s' % 'calibre:meta')
|
cmTag = Tag(ncx_soup, '%s' % 'calibre:meta')
|
||||||
cmTag['name'] = "author"
|
cmTag['name'] = "author"
|
||||||
@ -3056,7 +3055,7 @@ class CatalogBuilder(object):
|
|||||||
|
|
||||||
navPointByLetterTag.insert(1,contentTag)
|
navPointByLetterTag.insert(1,contentTag)
|
||||||
|
|
||||||
if self.generate_for_kindle:
|
if self.generate_for_kindle_mobi:
|
||||||
cmTag = Tag(soup, '%s' % 'calibre:meta')
|
cmTag = Tag(soup, '%s' % 'calibre:meta')
|
||||||
cmTag['name'] = "description"
|
cmTag['name'] = "description"
|
||||||
cmTag.insert(0, NavigableString(self.format_ncx_text(books, dest='description')))
|
cmTag.insert(0, NavigableString(self.format_ncx_text(books, dest='description')))
|
||||||
@ -3179,7 +3178,7 @@ class CatalogBuilder(object):
|
|||||||
contentTag['src'] = "content/%s.html#%s_titles" % (output, self.generate_unicode_name(title_letters[i]))
|
contentTag['src'] = "content/%s.html#%s_titles" % (output, self.generate_unicode_name(title_letters[i]))
|
||||||
navPointByLetterTag.insert(1,contentTag)
|
navPointByLetterTag.insert(1,contentTag)
|
||||||
|
|
||||||
if self.generate_for_kindle:
|
if self.generate_for_kindle_mobi:
|
||||||
cmTag = Tag(soup, '%s' % 'calibre:meta')
|
cmTag = Tag(soup, '%s' % 'calibre:meta')
|
||||||
cmTag['name'] = "description"
|
cmTag['name'] = "description"
|
||||||
cmTag.insert(0, NavigableString(self.format_ncx_text(books, dest='description')))
|
cmTag.insert(0, NavigableString(self.format_ncx_text(books, dest='description')))
|
||||||
@ -3293,7 +3292,7 @@ class CatalogBuilder(object):
|
|||||||
contentTag['src'] = "%s#%s_authors" % (HTML_file, self.generate_unicode_name(authors_by_letter[1]))
|
contentTag['src'] = "%s#%s_authors" % (HTML_file, self.generate_unicode_name(authors_by_letter[1]))
|
||||||
navPointByLetterTag.insert(1,contentTag)
|
navPointByLetterTag.insert(1,contentTag)
|
||||||
|
|
||||||
if self.generate_for_kindle:
|
if self.generate_for_kindle_mobi:
|
||||||
cmTag = Tag(soup, '%s' % 'calibre:meta')
|
cmTag = Tag(soup, '%s' % 'calibre:meta')
|
||||||
cmTag['name'] = "description"
|
cmTag['name'] = "description"
|
||||||
cmTag.insert(0, NavigableString(authors_by_letter[0]))
|
cmTag.insert(0, NavigableString(authors_by_letter[0]))
|
||||||
@ -3403,7 +3402,7 @@ class CatalogBuilder(object):
|
|||||||
|
|
||||||
navPointByDateRangeTag.insert(1,contentTag)
|
navPointByDateRangeTag.insert(1,contentTag)
|
||||||
|
|
||||||
if self.generate_for_kindle:
|
if self.generate_for_kindle_mobi:
|
||||||
cmTag = Tag(soup, '%s' % 'calibre:meta')
|
cmTag = Tag(soup, '%s' % 'calibre:meta')
|
||||||
cmTag['name'] = "description"
|
cmTag['name'] = "description"
|
||||||
cmTag.insert(0, NavigableString(books_by_date_range[0]))
|
cmTag.insert(0, NavigableString(books_by_date_range[0]))
|
||||||
@ -3462,7 +3461,7 @@ class CatalogBuilder(object):
|
|||||||
|
|
||||||
navPointByMonthTag.insert(1,contentTag)
|
navPointByMonthTag.insert(1,contentTag)
|
||||||
|
|
||||||
if self.generate_for_kindle:
|
if self.generate_for_kindle_mobi:
|
||||||
cmTag = Tag(soup, '%s' % 'calibre:meta')
|
cmTag = Tag(soup, '%s' % 'calibre:meta')
|
||||||
cmTag['name'] = "description"
|
cmTag['name'] = "description"
|
||||||
cmTag.insert(0, NavigableString(books_by_month[0]))
|
cmTag.insert(0, NavigableString(books_by_month[0]))
|
||||||
@ -3611,7 +3610,7 @@ class CatalogBuilder(object):
|
|||||||
|
|
||||||
navPointByDayTag.insert(1,contentTag)
|
navPointByDayTag.insert(1,contentTag)
|
||||||
|
|
||||||
if self.generate_for_kindle:
|
if self.generate_for_kindle_mobi:
|
||||||
cmTag = Tag(soup, '%s' % 'calibre:meta')
|
cmTag = Tag(soup, '%s' % 'calibre:meta')
|
||||||
cmTag['name'] = "description"
|
cmTag['name'] = "description"
|
||||||
cmTag.insert(0, NavigableString(books_by_day[0]))
|
cmTag.insert(0, NavigableString(books_by_day[0]))
|
||||||
@ -3702,7 +3701,7 @@ class CatalogBuilder(object):
|
|||||||
contentTag['src'] = "content/Genre_%s.html#Genre_%s" % (normalized_tag, normalized_tag)
|
contentTag['src'] = "content/Genre_%s.html#Genre_%s" % (normalized_tag, normalized_tag)
|
||||||
navPointVolumeTag.insert(1, contentTag)
|
navPointVolumeTag.insert(1, contentTag)
|
||||||
|
|
||||||
if self.generate_for_kindle:
|
if self.generate_for_kindle_mobi:
|
||||||
# Build the author tag
|
# Build the author tag
|
||||||
cmTag = Tag(ncx_soup, '%s' % 'calibre:meta')
|
cmTag = Tag(ncx_soup, '%s' % 'calibre:meta')
|
||||||
cmTag['name'] = "author"
|
cmTag['name'] = "author"
|
||||||
@ -3772,7 +3771,6 @@ class CatalogBuilder(object):
|
|||||||
<package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="calibre_id">
|
<package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="calibre_id">
|
||||||
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf" xmlns:calibre="http://calibre.kovidgoyal.net/2009/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf" xmlns:calibre="http://calibre.kovidgoyal.net/2009/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
<dc:language>en-US</dc:language>
|
<dc:language>en-US</dc:language>
|
||||||
<meta name="calibre:publication_type" content="periodical:default"/>
|
|
||||||
</metadata>
|
</metadata>
|
||||||
<manifest></manifest>
|
<manifest></manifest>
|
||||||
<spine toc="ncx"></spine>
|
<spine toc="ncx"></spine>
|
||||||
@ -3780,7 +3778,7 @@ class CatalogBuilder(object):
|
|||||||
</package>
|
</package>
|
||||||
'''
|
'''
|
||||||
# Add the supplied metadata tags
|
# Add the supplied metadata tags
|
||||||
soup = BeautifulStoneSoup(header, selfClosingTags=['item','itemref', 'reference'])
|
soup = BeautifulStoneSoup(header, selfClosingTags=['item','itemref', 'meta', 'reference'])
|
||||||
metadata = soup.find('metadata')
|
metadata = soup.find('metadata')
|
||||||
mtc = 0
|
mtc = 0
|
||||||
|
|
||||||
@ -3794,6 +3792,13 @@ class CatalogBuilder(object):
|
|||||||
metadata.insert(mtc, creatorTag)
|
metadata.insert(mtc, creatorTag)
|
||||||
mtc += 1
|
mtc += 1
|
||||||
|
|
||||||
|
if self.generate_for_kindle_mobi:
|
||||||
|
periodicalTag = Tag(soup, "meta")
|
||||||
|
periodicalTag['name'] = "calibre:publication_type"
|
||||||
|
periodicalTag['content'] = "periodical:default"
|
||||||
|
metadata.insert(mtc, periodicalTag)
|
||||||
|
mtc += 1
|
||||||
|
|
||||||
# Create the OPF tags
|
# Create the OPF tags
|
||||||
manifest = soup.find('manifest')
|
manifest = soup.find('manifest')
|
||||||
mtc = 0
|
mtc = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user