super slow and keep reaching full pool:

import os
import requests
from bs4 import BeautifulSoup, SoupStrainer
from concurrent.futures import ThreadPoolExecutor
from urllib.parse import urljoin, urlparse

ALLOWED_EXTENSIONS = {"jpg", "jpeg", "png", "gif", "bmp", "tiff"}


def has_allowed_extension(image_url):
    return any(image_url.lower().endswith("." + ext) for ext in ALLOWED_EXTENSIONS)


def is_likely_ad_or_icon(image_url, image_headers, minimum_size_kb=10):
    common_ad_indicators = ["ad", "banner", "sponsor"]
    common_icon_indicators = ["favicon", "logo", "icon"]

    # Check if image URL contains ad or icon indicators
    if any(
        indicator in image_url.lower()
        for indicator in common_ad_indicators + common_icon_indicators
    ):
        return True

    # Fetch image content size from the headers and check if it is smaller than the minimum size
    content_length = image_headers.get("content-length", None)
    if content_length and int(content_length) < minimum_size_kb * 1024:
        return True

    return False


def download_image(image_url, destination_folder, session):
    try:
        image_ext = os.path.splitext(urlparse(image_url).path)[1][1:].strip().lower()
        if image_ext not in ALLOWED_EXTENSIONS:
            print(f"Skipping {image_url}: Unsupported extension {image_ext}")
            return
        response = session.head(image_url, timeout=5)
        if not is_likely_ad_or_icon(
            image_url, response.headers
        ) and has_allowed_extension(image_url):
            with session.get(image_url, stream=True) as r:
                r.raise_for_status()
                img_name = os.path.basename(urlparse(image_url).path)
                img_path = os.path.join(destination_folder, img_name)
                with open(img_path, "wb") as f:
                    for chunk in r.iter_content(chunk_size=8192):
                        f.write(chunk)
            print(f"Downloaded {img_name} to {destination_folder}")
    except Exception as e:
        print(f"Could not download {image_url}: {e}")


def download_images(url, destination_folder, session):
    if not os.path.isdir(destination_folder):
        os.makedirs(destination_folder)

    response = session.get(url)
    soup = BeautifulSoup(response.text, "html.parser", parse_only=SoupStrainer("img"))
    images = [
        urljoin(url, img.get("src") or img.get("data-src"))
        for img in soup
        if img.get("src") or img.get("data-src")
    ]

    with ThreadPoolExecutor(max_workers=15) as executor:
        for image_url in images:
            executor.submit(download_image, image_url, destination_folder, session)


def remove_files(directory):
    for file_name in os.listdir(directory):
        file_path = os.path.join(directory, file_name)
        if os.path.isfile(file_path):
            os.remove(file_path)


def get_images(links):
    fixed_urls = [BeautifulSoup(tag, "html.parser").a["href"] for tag in links if tag]
    with requests.Session() as session:
        destination_dir = "downloaded_images"
        remove_files(
            destination_dir
        )  # Ensure directory is empty before downloading new images
        with ThreadPoolExecutor(max_workers=15) as executor:
            for link in fixed_urls:
                executor.submit(download_images, link, destination_dir, session)