def total_pages(soup):
    """
    Given an artist's parsed BeautifulSoup page, determine how many
    pages there are (there's a predictable pattern).
    """
    pager_items = soup.find('div', {'class': 'pager-items'})
    pager_links = pager_items.find_all('a')
    for pager, next_pager in zip(pager_links, pager_links[1:]):
        # There's always a "next" link before the last page
        if next_pager.text == 'Next':
            return int(pager.text)

    # If here, we haven't found a last page
    canonical = soup.find('link', {'rel': 'canonical'})['href']
    raise ValueError("Couldn't find last page for {}".format(canonical))