feat: add protocol-prefix parsers for socks5://ip:port format
This commit is contained in:
parent
51f6cfb4b4
commit
be438420d5
54
src/proxy_pool/plugins/builtin/parsers/protocol_prefix.py
Normal file
54
src/proxy_pool/plugins/builtin/parsers/protocol_prefix.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import re
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from proxy_pool.config import Settings
|
||||||
|
from proxy_pool.plugins.protocols import DiscoveredProxy
|
||||||
|
|
||||||
|
_PROTOCOL_LINE_RE = re.compile(
|
||||||
|
r"^(https?|socks[45])://(\d{1,3}(?:\.\d{1,3}){3}):(\d{2,5})$"
|
||||||
|
)
|
||||||
|
|
||||||
|
SUPPORTED_PROTOCOLS = {"http", "https", "socks4", "socks5"}
|
||||||
|
|
||||||
|
|
||||||
|
class ProtocolPrefixParser:
|
||||||
|
name = "protocol_prefix"
|
||||||
|
|
||||||
|
def supports(self, url: str) -> bool:
|
||||||
|
return False # Must be explicitly configured
|
||||||
|
|
||||||
|
async def parse(
|
||||||
|
self,
|
||||||
|
raw: bytes,
|
||||||
|
source_url: str,
|
||||||
|
source_id: Any,
|
||||||
|
default_protocol: str,
|
||||||
|
) -> list[DiscoveredProxy]:
|
||||||
|
results: list[DiscoveredProxy] = []
|
||||||
|
text = raw.decode("utf-8", errors="ignore")
|
||||||
|
|
||||||
|
for line in text.splitlines():
|
||||||
|
line = line.strip().lower()
|
||||||
|
match = _PROTOCOL_LINE_RE.match(line)
|
||||||
|
if match:
|
||||||
|
protocol = match.group(1)
|
||||||
|
if protocol in SUPPORTED_PROTOCOLS:
|
||||||
|
results.append(
|
||||||
|
DiscoveredProxy(
|
||||||
|
ip=match.group(2),
|
||||||
|
port=int(match.group(3)),
|
||||||
|
protocol=protocol,
|
||||||
|
source_id=source_id,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
def default_schedule(self) -> str | None:
|
||||||
|
return "*/30 * * * *"
|
||||||
|
|
||||||
|
|
||||||
|
def create_plugin(settings: Settings) -> ProtocolPrefixParser:
|
||||||
|
return ProtocolPrefixParser()
|
||||||
Loading…
x
Reference in New Issue
Block a user