def book_from_open_lib_result(self, result: Dict, image_size: CoverSize) -> Book: clean_result = {} source_id = result.get('key', None).split('/')[-1] cover_id = result.get('cover_i', None) isbns = result.get('isbn', []) title = result.get('title', None) author_names = result.get('author_name', []) publish_years = result.get('publish_year', []) clean_result['source_id'] = source_id clean_result['source'] = 'open library' clean_result['title'] = title.title() clean_result['author_name'] = author_names.pop( 0).title() if author_names else None clean_result['publish_year'] = publish_years.pop( 0) if publish_years else None if cover_id: clean_result['cover_url'] = self.get_cover_by_id( id=cover_id, id_type=IdType.COVER_ID, size=image_size) elif isbns: clean_result['cover_url'] = self.get_cover_by_id( id=isbns[0], id_type=IdType.ISBN, size=image_size) else: clean_result['cover_url'] = None return Book.from_dict(clean_result)
def book_from_google_books_result(result: Dict) -> Book: clean_result = {} info = result.get('volumeInfo') publish_year = info.get('publishedDate', None) image_links = info.get('imageLinks', None) clean_result['source_id'] = result.get('id', None) clean_result['source'] = 'google books api' clean_result['title'] = info.get('title', None) clean_result['author_names'] = info.get('authors', []) clean_result['publish_year'] = int( publish_year.split('-')[0].replace('*', '')) if publish_year else None clean_result['cover_url'] = image_links.get( 'thumbnail', None) if image_links else None return Book.from_dict(clean_result)