import re


def get_book_ids(book_urls):
    """
    Return a list of unique book ids from a list of book urls
    """

    # Check if books are duplicated
    unique_list = {}
    num_processed = 0

    for url in book_urls:
        # print('url=', url)
        all_nums = re.findall('[0-9]+', url)
        # if all_nums[-1] == all_nums[-2] or all_nums[-2] == all_nums[-3]:
        unique_list[all_nums[-2]] = unique_list.get(all_nums[-2], 0) + 1
        num_processed += 1

    # Get the list of unique book ids
    book_ids = list(unique_list.keys())

    print('Number of links before removing duplicates:', len(book_urls))
    print('Number of links processed:', num_processed)
    print('Number of unique books retained:', len(unique_list.keys()))

    return book_ids