diff --git a/src/calibre/gui2/catalog/catalog_epub_mobi.py b/src/calibre/gui2/catalog/catalog_epub_mobi.py
index 2037545bb4..12971528b2 100644
--- a/src/calibre/gui2/catalog/catalog_epub_mobi.py
+++ b/src/calibre/gui2/catalog/catalog_epub_mobi.py
@@ -18,10 +18,13 @@ class PluginWidget(QWidget,Ui_Form):
HELP = _('Options specific to')+' EPUB/MOBI '+_('output')
OPTION_FIELDS = [('exclude_genre','\[[\w ]*\]'),
('exclude_tags','~,'+_('Catalog')),
+ ('generate_titles', True),
+ ('generate_recently_added', True),
('note_tag','*'),
('numbers_as_text', False),
('read_tag','+')]
+
# Output synced to the connected device?
sync_enabled = True
@@ -37,7 +40,7 @@ class PluginWidget(QWidget,Ui_Form):
# Update dialog fields from stored options
for opt in self.OPTION_FIELDS:
opt_value = gprefs.get(self.name + '_' + opt[0], opt[1])
- if opt[0] == 'numbers_as_text':
+ if opt[0] in ['numbers_as_text','generate_titles','generate_recently_added']:
getattr(self, opt[0]).setChecked(opt_value)
else:
getattr(self, opt[0]).setText(opt_value)
@@ -45,19 +48,20 @@ class PluginWidget(QWidget,Ui_Form):
def options(self):
# Save/return the current options
# exclude_genre stores literally
- # numbers_as_text stores as True/False
+ # generate_titles, generate_recently_added, numbers_as_text stores as True/False
# others store as lists
opts_dict = {}
for opt in self.OPTION_FIELDS:
- if opt[0] == 'numbers_as_text':
+ if opt[0] in ['numbers_as_text','generate_titles','generate_recently_added']:
opt_value = getattr(self,opt[0]).isChecked()
else:
opt_value = unicode(getattr(self, opt[0]).text())
gprefs.set(self.name + '_' + opt[0], opt_value)
- if opt[0] == 'exclude_genre' or 'numbers_as_text':
+
+ if opt[0] in ['exclude_genre','numbers_as_text','generate_titles','generate_recently_added']:
opts_dict[opt[0]] = opt_value
else:
- opt_value = opt_value.split(',')
+ opts_dict[opt[0]] = opt_value.split(',')
opts_dict['output_profile'] = [load_defaults('page_setup')['output_profile']]
diff --git a/src/calibre/gui2/catalog/catalog_epub_mobi.ui b/src/calibre/gui2/catalog/catalog_epub_mobi.ui
index 044ecdaaec..91fcbdc364 100644
--- a/src/calibre/gui2/catalog/catalog_epub_mobi.ui
+++ b/src/calibre/gui2/catalog/catalog_epub_mobi.ui
@@ -14,63 +14,56 @@
Form
- -
+
-
'Don't include this book' tag:
- -
+
-
- -
+
-
'Mark this book as read' tag:
- -
+
-
- -
+
-
Additional note tag prefix:
- -
+
-
- -
-
-
- Sort numbers as text
-
-
-
- -
+
-
- -
+
-
Regex pattern describing tags to exclude as genres:
@@ -83,36 +76,19 @@
- -
-
-
-
- 14
- 75
- true
-
-
-
- Special marker tags for catalog generation
-
-
- Qt::AlignCenter
-
-
-
- -
+
-
Regex tips:
-- The default regex of '\[[\w]*\]' ignores tags of the form '[tag]', e.g., '[Amazon Freebie]'
-- A regex of '.' ignores all tags, generating no genre categories in the catalog
+- The default regex - \[[\w]*\] - excludes genre tags of the form [tag], e.g., [Amazon Freebie]
+- A regex pattern of a single dot excludes all genre tags, generating no Genre Section
true
- -
+
-
Qt::Vertical
@@ -125,6 +101,27 @@
+ -
+
+
+ Include 'Titles' Section
+
+
+
+ -
+
+
+ Include 'Recently Added' Section
+
+
+
+ -
+
+
+ Sort numbers as text
+
+
+
diff --git a/src/calibre/library/catalog.py b/src/calibre/library/catalog.py
index 3082dc07b1..045444b3dd 100644
--- a/src/calibre/library/catalog.py
+++ b/src/calibre/library/catalog.py
@@ -7,7 +7,7 @@ from xml.sax.saxutils import escape
from calibre import filesystem_encoding, prints, prepare_string_for_xml, strftime
from calibre.customize import CatalogPlugin
from calibre.customize.conversion import OptionRecommendation, DummyReporter
-from calibre.ebooks.BeautifulSoup import BeautifulSoup, BeautifulStoneSoup, Tag, NavigableString
+from calibre.ebooks.BeautifulSoup import BeautifulSoup, BeautifulStoneSoup, Tag, NavigableString, CData
from calibre.ptempfile import PersistentTemporaryDirectory
from calibre.utils.logging import Log
@@ -274,6 +274,18 @@ class EPUB_MOBI(CatalogPlugin):
"--exclude-tags=skip will match 'skip this book' and 'Skip will like this'.\n"
"Default: '%default'\n"
"Applies to: ePub, MOBI output formats")),
+ Option('--generate-titles',
+ default=True,
+ dest='generate_titles',
+ help=_("Include 'Titles' section in catalog.\n"
+ "Default: '%default'\n"
+ "Applies to: ePub, MOBI output formats")),
+ Option('--generate-recently-added',
+ default=True,
+ dest='generate_recently_added',
+ help=_("Include 'Recently Added' section in catalog.\n"
+ "Default: '%default'\n"
+ "Applies to: ePub, MOBI output formats")),
Option('--note-tag',
default='*',
dest='note_tag',
@@ -523,8 +535,8 @@ class EPUB_MOBI(CatalogPlugin):
'''
# Number of discrete steps to catalog creation
- current_step = 0.0
- total_steps = 14.0
+# current_step = 0.0
+# total_steps = 10.0
THUMB_WIDTH = 75
THUMB_HEIGHT = 100
@@ -549,6 +561,7 @@ class EPUB_MOBI(CatalogPlugin):
self.__booksByTitle = None
self.__catalogPath = PersistentTemporaryDirectory("_epub_mobi_catalog", prefix='')
self.__contentDir = os.path.join(self.catalogPath, "content")
+ self.__currentStep = 0.0
self.__creator = opts.creator
self.__db = db
self.__descriptionClip = opts.descriptionClip
@@ -570,8 +583,15 @@ class EPUB_MOBI(CatalogPlugin):
self.__stylesheet = stylesheet
self.__thumbs = None
self.__title = opts.catalog_title
+ self.__totalSteps = 10.0
self.__verbose = opts.verbose
+ # Tweak build steps based on optional sections
+ if self.opts.generate_titles:
+ self.__totalSteps += 2
+ if self.opts.generate_recently_added:
+ self.__totalSteps += 2
+
# Accessors
'''
@dynamic_property
@@ -626,6 +646,13 @@ class EPUB_MOBI(CatalogPlugin):
self.__contentDir = val
return property(fget=fget, fset=fset)
@dynamic_property
+ def currentStep(self):
+ def fget(self):
+ return self.__currentStep
+ def fset(self, val):
+ self.__currentStep = val
+ return property(fget=fget, fset=fset)
+ @dynamic_property
def creator(self):
def fget(self):
return self.__creator
@@ -765,6 +792,11 @@ class EPUB_MOBI(CatalogPlugin):
self.__title = val
return property(fget=fget, fset=fset)
@dynamic_property
+ def totalSteps(self):
+ def fget(self):
+ return self.__totalSteps
+ return property(fget=fget)
+ @dynamic_property
def verbose(self):
def fget(self):
return self.__verbose
@@ -803,8 +835,10 @@ class EPUB_MOBI(CatalogPlugin):
self.fetchBooksByAuthor()
self.generateHTMLDescriptions()
self.generateHTMLByAuthor()
- self.generateHTMLByTitle()
- self.generateHTMLByDateAdded()
+ if self.opts.generate_titles:
+ self.generateHTMLByTitle()
+ if self.opts.generate_recently_added:
+ self.generateHTMLByDateAdded()
self.generateHTMLByTags()
from calibre.utils.PythonMagickWand import ImageMagick
@@ -815,8 +849,10 @@ class EPUB_MOBI(CatalogPlugin):
self.generateNCXHeader()
self.generateNCXDescriptions("Descriptions")
self.generateNCXByAuthor("Authors")
- self.generateNCXByTitle("Titles")
- self.generateNCXByDateAdded("Recently Added")
+ if self.opts.generate_titles:
+ self.generateNCXByTitle("Titles")
+ if self.opts.generate_recently_added:
+ self.generateNCXByDateAdded("Recently Added")
self.generateNCXByGenre("Genres")
self.writeNCX()
return True
@@ -907,16 +943,14 @@ class EPUB_MOBI(CatalogPlugin):
this_title['date'] = strftime(u'%B %Y', record['pubdate'].timetuple())
this_title['timestamp'] = record['timestamp']
if record['comments']:
- #this_title['description'] = re.sub('&', '&', record['comments'])
- has_xml = re.search('<(?P.+)>.+(?P=tag)>||<.+/>',record['comments'])
- if has_xml and not re.search('
present, take a chance that the markup is valid
- this_title['description'] = record['comments']
- this_title['short_description'] = self.generateShortDescription(this_title['description'])
+ this_title['description'] = self.markdownComments(record['comments'])
+ paras = BeautifulSoup(this_title['description']).findAll('p')
+ tokens = []
+ for p in paras:
+ for token in p.contents:
+ if token.string is not None:
+ tokens.append(token.string)
+ this_title['short_description'] = self.generateShortDescription(' '.join(tokens))
else:
this_title['description'] = None
this_title['short_description'] = None
@@ -2552,9 +2586,7 @@ class EPUB_MOBI(CatalogPlugin):
-
-
-
+