def get_thumbnail_info(url, size):
    def get_thumb_url_for_short_photo_id(short_photo_id):
        return 'http://flic.kr/p/img/%s_%s.jpg' % (
            short_photo_id, size == SMALL_THUMBNAIL and 't' or 'm')

    def get_youtube_thumb_url(video_id):
        # See http://stackoverflow.com/questions/2068344
        return 'http://img.youtube.com/vi/%s/%s.jpg' % (
            video_id, need_small and 'default' or 'hqdefault')

    thumb_url = None
    thumb_width = None
    thumb_height = None
    need_small = size == SMALL_THUMBNAIL

    parsed_url = urlparse.urlparse(url)
    hostname = parsed_url.netloc
    path = parsed_url.path
    query = dict(parse_qsl(parsed_url.query))

    if hostname == 'yfrog.com':
        # See http://yfrog.com/page/api
        match = _YFROG_PATH_RE.match(path)
        if match:
            thumb_url = 'http://yfrog.com/%s' % match.group(1)
            if need_small:
                thumb_url += ':small'
            else:
                thumb_url += ':iphone'
    elif hostname in ('instagr.am', 'instagram.com', 'www.instagram.com'):
        # See http://instagram.com/developer/embedding/#media
        match = _INSTAGRAM_PATH_RE.match(path)
        if match:
            thumb_url = 'http://instagr.am/p/%s/media/' % match.group(1)
            if need_small:
                thumb_url += '?size=t'
                thumb_width = 150
                thumb_height = 150
            else:
                thumb_width = 306
                thumb_height = 306
    elif hostname == 'flic.kr':
        # See http://www.flickr.com/services/api/misc.urls.html ("Short URLs"
        # section) and http://www.flickr.com/groups/api/discuss/72157616713786392/#comment72157623145381402
        match = _FLICKR_SHORT_PATH_RE.match(path)
        if match:
            thumb_url = get_thumb_url_for_short_photo_id(match.group(1))
    elif _FLICKR_LONG_HOSTNAME_RE.match(hostname):
        # See http://www.flickr.com/services/api/misc.urls.html ("Photo Source
        # URLs" section).
        match = _FLICKR_LONG_PATH_RE.match(path)
        if match:
            path_prefix = match.group(1)
            size_suffix = match.group(2)
            extension = match.group(3)

            if size_suffix == '_o':
                # Original photos have their own secret, so so we can't generate
                # a thumbnail URL from them without doing an API call.
                thumb_url = url
            else:
                thumb_url = '%s://%s%s' % (parsed_url.scheme, hostname, path_prefix)
                if need_small:
                    thumb_url += '_t'
                thumb_url += extension
    elif hostname == 'www.flickr.com':
        # See http://www.flickr.com/services/api/misc.urls.html ("Web Page
        # URLs" section).
        match = _FLICKR_PHOTO_PAGE_PATH_RE.match(path)
        if match:
            photo_id = int(match.group(1))
            # Given a photo ID (but not its secret), all we can do is generate
            # a short URL-style thumbnail for it.
            short_photo_id = _get_short_flickr_photo_id(photo_id)
            thumb_url = get_thumb_url_for_short_photo_id(short_photo_id)
    elif hostname.startswith('i.') and hostname.endswith('.imgur.com'):
        # See http://webapps.stackexchange.com/questions/16103. We don't use
        # a strict hostname comparison so that we can handle "Pro" imgur
        # instances too (e.g. i.stack.imgur.com).
        match = _IMGUR_PATH_RE.match(path)
        if match:
            thumb_url = '%s://%s/%s%s%s' % (
                parsed_url.scheme, hostname, match.group(1),
                (need_small and 's' or 'l'), match.group(2))
    elif hostname == 'imgur.com':
        # See http://imgur.com/faq#gallery
        match = _IMGUR_GALLERY_PATH_RE.match(path)
        if match:
            thumb_url = 'http://i.imgur.com/%s%s.jpg' % (
                match.group(2), (need_small and 's' or 'l'))
    elif hostname == 'twitpic.com':
        # See http://dev.twitpic.com/docs/thumbnails/ (the 'large' size isn't
        # documented there, but it is what twitter.com seems to use).
        match = _TWITPIC_PATH_RE.match(path)
        if match:
            thumb_url = 'http://twitpic.com/show/%s/%s' % (
                need_small and 'thumb' or 'large',
                match.group(1))
            if need_small:
                thumb_width = 150
                thumb_height = 150
    elif hostname == 'lockerz.com':
        # See http://support.lockerz.com/entries/350297-image-from-url
        match = _LOCKERZ_PATH_RE.match(path)
        if match:
            thumb_url = 'http://api.plixi.com/api/tpapi.svc/imagefromurl?url=%s&size=%s' % (
                urllib.quote(url),
                need_small and 'small' or 'medium')
            if need_small:
                thumb_width = 150
                thumb_height = 150
    elif hostname == 'cl.ly':
        # See http://developer.getcloudapp.com/view-item
        thumb_url = 'http://thumbs.cl.ly%s' % path
    elif hostname == 'youtube.com' or hostname == 'www.youtube.com':
        if path == '/watch' and query in 'v':
            thumb_url = get_youtube_thumb_url(query['v'])
    elif hostname == 'youtu.be':
        thumb_url = get_youtube_thumb_url(path[1:])
    elif hostname == 'img.ly':
        # See http://web.archive.org/web/20100606214502/http://img.ly/api/docs
        # (current API docs have removed references to thumbnails)
        match = _IMGLY_FULL_PATH_RE.match(path)
        if match:
          thumb_url = 'http://s3.amazonaws.com/imgly_production/%s/%s.jpg' % (
              match.group(1),
              need_small and 'thumb' or 'large')
        else:
            match = _IMGLY_SHORT_PATH_RE.match(path)
            if match:
                thumb_url = 'http://img.ly/show/%s/%s' % (
                    need_small and 'thumb' or 'large',
                    match.group(1))
                if need_small:
                    thumb_width = 150
                    thumb_height = 150
    elif hostname == 'ow.ly':
        # No online docs, but these paths are shown in the embed codes that
        # appear in the sidebar of any image (e.g. see http://ow.ly/i/oKuW).
        match = _OWLY_PATH_RE.match(path)
        if match:
            thumb_url = 'http://static.ow.ly/photos/%s/%s.jpg' % (
                need_small and 'thumb' or 'normal',
                match.group(1))
            if need_small:
                thumb_width = 100
                thumb_height = 100

    return thumb_url, thumb_width, thumb_height
dataset/ETHPy150Open mihaip/streamspigot/app/datasources/thumbnails.py/get_thumbnail_info/swapped operands of `in`