mirror of
https://github.com/NanmiCoder/MediaCrawler.git
synced 2026-03-16 08:20:50 +08:00
i18n: translate all Chinese comments, docstrings, and logger messages to English
Comprehensive translation of Chinese text to English across the entire codebase: - api/: FastAPI server documentation and logger messages - cache/: Cache abstraction layer comments and docstrings - database/: Database models and MongoDB store documentation - media_platform/: All platform crawlers (Bilibili, Douyin, Kuaishou, Tieba, Weibo, Xiaohongshu, Zhihu) - model/: Data model documentation - proxy/: Proxy pool and provider documentation - store/: Data storage layer comments - tools/: Utility functions and browser automation - test/: Test file documentation Preserved: Chinese disclaimer header (lines 10-18) for legal compliance 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author : relakkes@gmail.com
|
||||
# @Time : 2025/7/31
|
||||
# @Desc : 豌豆HTTP 代理IP实现
|
||||
# @Desc : WanDou HTTP proxy IP implementation
|
||||
import os
|
||||
from typing import Dict, List
|
||||
from urllib.parse import urlencode
|
||||
@@ -36,9 +36,9 @@ class WanDouHttpProxy(ProxyProvider):
|
||||
|
||||
def __init__(self, app_key: str, num: int = 100):
|
||||
"""
|
||||
豌豆HTTP 代理IP实现
|
||||
:param app_key: 开放的app_key,可以通过用户中心获取
|
||||
:param num: 单次提取IP数量,最大100
|
||||
WanDou HTTP proxy IP implementation
|
||||
:param app_key: Open app_key, can be obtained through user center
|
||||
:param num: Number of IPs extracted at once, maximum 100
|
||||
"""
|
||||
self.proxy_brand_name = "WANDOUHTTP"
|
||||
self.api_path = "https://api.wandouapp.com/"
|
||||
@@ -54,16 +54,16 @@ class WanDouHttpProxy(ProxyProvider):
|
||||
:return:
|
||||
"""
|
||||
|
||||
# 优先从缓存中拿 IP
|
||||
# Prioritize getting IP from cache
|
||||
ip_cache_list = self.ip_cache.load_all_ip(
|
||||
proxy_brand_name=self.proxy_brand_name
|
||||
)
|
||||
if len(ip_cache_list) >= num:
|
||||
return ip_cache_list[:num]
|
||||
|
||||
# 如果缓存中的数量不够,从IP代理商获取补上,再存入缓存中
|
||||
# If the quantity in cache is insufficient, get from IP provider to supplement, then store in cache
|
||||
need_get_count = num - len(ip_cache_list)
|
||||
self.params.update({"num": min(need_get_count, 100)}) # 最大100
|
||||
self.params.update({"num": min(need_get_count, 100)}) # Maximum 100
|
||||
ip_infos = []
|
||||
async with httpx.AsyncClient() as client:
|
||||
url = self.api_path + "?" + urlencode(self.params)
|
||||
@@ -82,7 +82,7 @@ class WanDouHttpProxy(ProxyProvider):
|
||||
ip_info_model = IpInfoModel(
|
||||
ip=ip_item.get("ip"),
|
||||
port=ip_item.get("port"),
|
||||
user="", # 豌豆HTTP不需要用户名密码认证
|
||||
user="", # WanDou HTTP does not require username password authentication
|
||||
password="",
|
||||
expired_time_ts=utils.get_unix_time_from_time_str(
|
||||
ip_item.get("expire_time")
|
||||
@@ -96,27 +96,27 @@ class WanDouHttpProxy(ProxyProvider):
|
||||
)
|
||||
else:
|
||||
error_msg = res_dict.get("msg", "unknown error")
|
||||
# 处理具体错误码
|
||||
# Handle specific error codes
|
||||
error_code = res_dict.get("code")
|
||||
if error_code == 10001:
|
||||
error_msg = "通用错误,具体错误信息查看msg内容"
|
||||
error_msg = "General error, check msg content for specific error information"
|
||||
elif error_code == 10048:
|
||||
error_msg = "没有可用套餐"
|
||||
error_msg = "No available package"
|
||||
raise IpGetError(f"{error_msg} (code: {error_code})")
|
||||
return ip_cache_list + ip_infos
|
||||
|
||||
|
||||
def new_wandou_http_proxy() -> WanDouHttpProxy:
|
||||
"""
|
||||
构造豌豆HTTP实例
|
||||
支持两种环境变量命名格式:
|
||||
1. 大写格式:WANDOU_APP_KEY
|
||||
2. 小写格式:wandou_app_key
|
||||
优先使用大写格式,如果不存在则使用小写格式
|
||||
Construct WanDou HTTP instance
|
||||
Supports two environment variable naming formats:
|
||||
1. Uppercase format: WANDOU_APP_KEY
|
||||
2. Lowercase format: wandou_app_key
|
||||
Prioritize uppercase format, use lowercase format if not exists
|
||||
Returns:
|
||||
|
||||
"""
|
||||
# 支持大小写两种环境变量格式,优先使用大写
|
||||
app_key = os.getenv("WANDOU_APP_KEY") or os.getenv("wandou_app_key", "你的豌豆HTTP app_key")
|
||||
# Support both uppercase and lowercase environment variable formats, prioritize uppercase
|
||||
app_key = os.getenv("WANDOU_APP_KEY") or os.getenv("wandou_app_key", "your_wandou_http_app_key")
|
||||
|
||||
return WanDouHttpProxy(app_key=app_key)
|
||||
|
||||
Reference in New Issue
Block a user