From 05cf311555df62c4a2191617e0bc6e0e42e5373d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 29 Sep 2010 18:48:17 -0600 Subject: [PATCH] Cleanup ISBNdb metadata plugin --- src/calibre/ebooks/metadata/isbndb.py | 38 ++++++++++++++++++--------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/calibre/ebooks/metadata/isbndb.py b/src/calibre/ebooks/metadata/isbndb.py index 6c321bf9d3..6416dcdc39 100644 --- a/src/calibre/ebooks/metadata/isbndb.py +++ b/src/calibre/ebooks/metadata/isbndb.py @@ -47,29 +47,43 @@ class ISBNDBMetadata(Metadata): def __init__(self, book): Metadata.__init__(self, None, []) + def tostring(e): + if not hasattr(e, 'string'): + return None + ans = e.string + if ans is not None: + ans = unicode(ans).strip() + if not ans: + ans = None + return ans + self.isbn = unicode(book.get('isbn13', book.get('isbn'))) - self.title = unicode(book.find('titlelong').string) + self.title = tostring(book.find('titlelong')) if not self.title: - self.title = unicode(book.find('title').string) + self.title = tostring(book.find('title')) + if not self.title: + self.title = _('Unknown') self.title = unicode(self.title).strip() - au = unicode(book.find('authorstext').string).strip() - temp = au.split(',') self.authors = [] - for au in temp: - if not au: continue - self.authors.extend([a.strip() for a in au.split('&')]) + au = tostring(book.find('authorstext')) + if au: + au = au.strip() + temp = au.split(',') + for au in temp: + if not au: continue + self.authors.extend([a.strip() for a in au.split('&')]) try: - self.author_sort = book.find('authors').find('person').string + self.author_sort = tostring(book.find('authors').find('person')) if self.authors and self.author_sort == self.authors[0]: self.author_sort = None except: pass - self.publisher = unicode(book.find('publishertext').string) + self.publisher = tostring(book.find('publishertext')) - summ = book.find('summary') - if summ and hasattr(summ, 'string') and summ.string: - self.comments = 'SUMMARY:\n'+unicode(summ.string) + summ = tostring(book.find('summary')) + if summ: + self.comments = 'SUMMARY:\n'+summ.string def build_isbn(base_url, opts):