- Add Free_Proxy_Website-style fpw_* plugins and register them - Per-plugin crawl timeout (crawl_timeout_seconds=120); remove global crawl_timeout setting - Validator: fix connect vs total timeout on save; SOCKS session LRU cache; drop redundant semaphore - Validation handler uses single DB connection; batch upsert after crawl; WorkerPool put_nowait - Remove unused max_retries from settings API/UI; settings maintenance SQL + init_db cleanup of deprecated keys - WebSocket dashboard stats; ProxyList pool_filter and API alignment - POST /api/proxies/delete-one for IPv6-safe deletes; task poll stops on 404 - pytest uses PROXYPOOL_DB_PATH=db/proxies.test.sqlite so tests do not wipe production DB - .gitignore: explicit proxies.test.sqlite patterns; fix plugin_service ValidationException import Made-with: Cursor
55 lines
2.6 KiB
Python
55 lines
2.6 KiB
Python
"""www.proxy-list.download 公开 API(README: Free_Proxy_Website)。"""
|
||
from typing import List
|
||
|
||
from app.core.plugin_system import ProxyRaw
|
||
from app.plugins.base import BaseHTTPPlugin
|
||
from app.core.log import logger
|
||
|
||
|
||
class FpwProxyListDownloadPlugin(BaseHTTPPlugin):
|
||
name = "fpw_proxy_list_download"
|
||
display_name = "Proxy-List.download"
|
||
description = "proxy-list.download 官方 API(http/https/socks4/socks5)"
|
||
|
||
def __init__(self):
|
||
super().__init__()
|
||
self.max_concurrency = 8
|
||
self.api_pairs = [
|
||
("http", "https://www.proxy-list.download/api/v1/get?type=http"),
|
||
("https", "https://www.proxy-list.download/api/v1/get?type=https"),
|
||
("socks4", "https://www.proxy-list.download/api/v1/get?type=socks4"),
|
||
("socks5", "https://www.proxy-list.download/api/v1/get?type=socks5"),
|
||
]
|
||
self.fallback_pairs = [
|
||
("http", "https://api.proxyscrape.com/v2/?request=get&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all"),
|
||
("https", "https://api.proxyscrape.com/v2/?request=get&protocol=https&timeout=10000&country=all&ssl=all&anonymity=all"),
|
||
("socks4", "https://api.proxyscrape.com/v2/?request=get&protocol=socks4&timeout=10000&country=all&ssl=all&anonymity=all"),
|
||
("socks5", "https://api.proxyscrape.com/v2/?request=get&protocol=socks5&timeout=10000&country=all&ssl=all&anonymity=all"),
|
||
]
|
||
|
||
async def crawl(self) -> List[ProxyRaw]:
|
||
results: List[ProxyRaw] = []
|
||
urls = [u for _, u in self.api_pairs]
|
||
htmls = await self.fetch_all(urls, timeout=10, retries=1)
|
||
for (protocol, _), text in zip(self.api_pairs, htmls):
|
||
if not text:
|
||
continue
|
||
batch = self.parse_text_proxies(text, protocol)
|
||
if batch:
|
||
results.extend(batch)
|
||
logger.info(f"{self.display_name} {protocol}: {len(batch)} 条")
|
||
if not results:
|
||
logger.warning(f"{self.display_name} 主 API 无数据,尝试 ProxyScrape 备用")
|
||
fb_urls = [u for _, u in self.fallback_pairs]
|
||
fb_htmls = await self.fetch_all(fb_urls, timeout=10, retries=1)
|
||
for (protocol, _), text in zip(self.fallback_pairs, fb_htmls):
|
||
if not text:
|
||
continue
|
||
batch = self.parse_text_proxies(text, protocol)
|
||
if batch:
|
||
results.extend(batch)
|
||
logger.info(f"{self.display_name} fallback {protocol}: {len(batch)} 条")
|
||
if results:
|
||
logger.info(f"{self.display_name} 合计 {len(results)} 条")
|
||
return results
|