Catalog: Handle embedded series number in title correctly

This commit is contained in:
Kovid Goyal 2010-01-26 14:52:49 -07:00
commit 5fa5974f8e

View File

@ -338,7 +338,7 @@ class EPUB_MOBI(CatalogPlugin):
elif hundredsComponent and tensComponent: elif hundredsComponent and tensComponent:
result = hundredsComponentString + " " + tensComponentString result = hundredsComponentString + " " + tensComponentString
else: else:
prints(" NumberToText.stringFromInt(): empty result translating %d" % intToTranslate) prints(" NumberToText.stringFromInt(): empty result translating %d" % intToTranslate)
return result return result
def numberTranslate(self): def numberTranslate(self):
@ -1879,7 +1879,7 @@ class EPUB_MOBI(CatalogPlugin):
# 'tag', 'file', 'authors' # 'tag', 'file', 'authors'
self.opts.log.info(self.updateProgressFullStep("generateNCXByTags()")) self.opts.log.info(self.updateProgressFullStep("generateNCXByTags()"))
if not len(self.genres): if not len(self.genres):
self.opts.log.warn(" No genres found in tags.\n" self.opts.log.warn(" No genres found in tags.\n"
" No Genre section added to Catalog") " No Genre section added to Catalog")
@ -2296,18 +2296,21 @@ class EPUB_MOBI(CatalogPlugin):
# Convert the actual title to a string suitable for sorting. # Convert the actual title to a string suitable for sorting.
# Convert numbers to strings, ignore leading stop words # Convert numbers to strings, ignore leading stop words
# The 21-Day Consciousness Cleanse # The 21-Day Consciousness Cleanse
# Scan for numbers in each word clump.
from calibre.ebooks.metadata import title_sort
title_words = title.split(' ') title_words = title_sort(title).split()
# Scan for numbers in each word clump
translated = [] translated = []
for (i,word) in enumerate(title_words): for (i,word) in enumerate(title_words):
hit = re.search('[0-9]+',word) # Initial numbers translated to text equivalent
if hit : if i==0 and re.search('[0-9]+',word):
translated.append(EPUB_MOBI.NumberToText(word).text) translated.append(EPUB_MOBI.NumberToText(word).text)
else: else:
if re.search('[0-9]+',word):
# Coerce standard-width strings for numbers
word = '%03d' % int(re.sub('\D','',word))
translated.append(word) translated.append(word)
return ' '.join(translated) return ' '.join(translated)
def generateThumbnail(self, title, image_dir, thumb_file): def generateThumbnail(self, title, image_dir, thumb_file):