'Add the book to the booklist, if needed. Return None if the book is
already there and not updated, otherwise return the book.'

def add_book_extended(self, book, replace_metadata, check_for_duplicates):

    try:
        b = (self.index(book) if check_for_duplicates else None)
    except (ValueError, IndexError):
        b = None
    if (b is None):
        self.append(book)
        return book
    if replace_metadata:
        self[b].smart_update(book, replace_metadata=True)
        return self[b]
    return None
