From ea4e23aa412a7a0d8ccc040361e3b8ebcf5c503a Mon Sep 17 00:00:00 2001 From: GRiker Date: Tue, 26 Jan 2010 14:40:57 -0700 Subject: [PATCH] Revised title sorting algorithm to handle series --- src/calibre/library/catalog.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/calibre/library/catalog.py b/src/calibre/library/catalog.py index 77e7230c20..9ed2406dbc 100644 --- a/src/calibre/library/catalog.py +++ b/src/calibre/library/catalog.py @@ -2297,23 +2297,20 @@ class EPUB_MOBI(CatalogPlugin): # Convert numbers to strings, ignore leading stop words # The 21-Day Consciousness Cleanse # Scan for numbers in each word clump. + from calibre.ebooks.metadata import title_sort - title_words = title.split() - stop_words = ['a','an','the'] + title_words = title_sort(title).split() translated = [] - # Remove the stop words - # GwR *** conform this with KG's stop word list - while title_words[0].lower() in stop_words: - stop_word = title_words.pop(0) - for (i,word) in enumerate(title_words): - # Don't translate numeric content after first title word + # Initial numbers translated to text equivalent if i==0 and re.search('[0-9]+',word): translated.append(EPUB_MOBI.NumberToText(word).text) else: + if re.search('[0-9]+',word): + # Coerce standard-width strings for numbers + word = '%03d' % int(re.sub('\D','',word)) translated.append(word) - return ' '.join(translated) def generateThumbnail(self, title, image_dir, thumb_file):