Image previews: handle no-image case

Previously, if we didn't find a thumbnail url for a link, we'd encounter errors
at a few places in the `scraper_q` pipeline.  Now we short-circuit those
sections of code.
This commit is contained in:
xiongchiamiov
2015-03-17 15:57:00 -07:00
parent d3f9e1e1ce
commit 5415934008

View File

@@ -349,8 +349,9 @@ def _set_media(link, force=False, **kwargs):
link._commit()
image_uid = media.preview_object['uid']
LinksByImage.add_link(image_uid, link)
if media.preview_object:
image_uid = media.preview_object['uid']
LinksByImage.add_link(image_uid, link)
hooks.get_hook("scraper.set_media").call(link=link)
@@ -471,9 +472,12 @@ class _ThumbnailOnlyScraper(Scraper):
def scrape(self):
thumbnail_url, image_data = self._find_thumbnail_image()
if not thumbnail_url:
return None, None, None, None
# When isolated from the context of a webpage, protocol-relative URLs
# are ambiguous, so let's absolutify them now.
if thumbnail_url and thumbnail_url.startswith('//'):
if thumbnail_url.startswith('//'):
thumbnail_url = coerce_url_to_protocol(thumbnail_url, self.protocol)
if not image_data: