'Find what we think is the best thumbnail image for a link.
Returns a 2-tuple of image url and, as an optimization, the raw image
data.  A value of None for the former means we couldn\'t find an image;
None for the latter just means we haven\'t already fetched the image.'

def _find_thumbnail_image(self):

    (content_type, content) = _fetch_url(self.url)
    if (content_type and ('image' in content_type) and content):
        return (self.url, content)
    if (content_type and ('html' in content_type) and content):
        soup = BeautifulSoup.BeautifulSoup(content)
    else:
        return (None, None)
    og_image = (soup.find('meta', property='og:image') or soup.find('meta', attrs={'name': 'og:image'}))
    if (og_image and og_image.get('content')):
        return (og_image['content'], None)
    og_image = (soup.find('meta', property='og:image:url') or soup.find('meta', attrs={'name': 'og:image:url'}))
    if (og_image and og_image.get('content')):
        return (og_image['content'], None)
    thumbnail_spec = soup.find('link', rel='image_src')
    if (thumbnail_spec and thumbnail_spec['href']):
        return (thumbnail_spec['href'], None)
    max_area = 0
    max_url = None
    for image_url in self._extract_image_urls(soup):
        if image_url.startswith('//'):
            image_url = coerce_url_to_protocol(image_url, self.protocol)
        size = _fetch_image_size(image_url, referer=self.url)
        if (not size):
            continue
        area = (size[0] * size[1])
        if (area < 5000):
            g.log.debug(('ignore    little    %s' % image_url))
            continue
        if ((max(size) / min(size)) > 1.5):
            g.log.debug(('ignore    dimensions    %s' % image_url))
            continue
        if ('sprite' in image_url.lower()):
            g.log.debug(('penalizing    sprite    %s' % image_url))
            area /= 10
        if (area > max_area):
            max_area = area
            max_url = image_url
    return (max_url, None)
