def METHOD_NAME(url, use_whitelist, hosts_whitelist):
    try:
        p = urllib.parse.urlparse(url)
        if p.scheme in ["http", "https"]:
            if use_whitelist:
                for host in hosts_whitelist:
                    h = host.strip().lower()
                    if h and p.netloc.lower().find(h) >= 0:
                        return True
            else:
                return p.path.lower().endswith((".jpg", ".jpeg", ".png", ".tiff", ".avif"))
                # skip gif - they are usually small images
        return False
    except Exception:
        return False