INNER CODE UNIT · Python
check_link
SuperAB123/Free-Official-Youtube-Content · Find broken links in the list.py:20
async def check_link(session: aiohttp.ClientSession, link: str) -> bool:
try:
async with session.get(link, allow_redirects=True, timeout=ClientTimeout(total=8)) as r:
if r.status != 200:
return False
text = await r.text()
return not any(p in text.lower() for p in BROKEN_PHRASES)
except:
return False
async def check_all(links: list[str], concurrency: int = 40):
broken = []
connector = aiohttp.TCPConnector(limit_per_host=concurrency, ssl=False)
async with aiohttp.ClientSession(connector=connector) as session:
sem = asyncio.Semaphore(concurrency)
async def worker(link):
async with sem: