Cleanup ISBNdb metadata plugin

This commit is contained in:
Kovid Goyal 2010-09-29 18:48:17 -06:00
parent 93d92ee250
commit 05cf311555

View File

@ -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 = []
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):