Procházet zdrojové kódy

feat(proxy): 增强代理配置支持并添加调试信息

- 在BasePublisher和WeixinPublisher中添加代理使用时的调试信息输出
- 优化WeixinPublisher和XiaohongshuPublisher的代理配置逻辑,确保在使用Playwright时正确应用代理设置
- 改进XiaohongshuPublisher的发布逻辑,支持通过代理发布
Ethanfly před 1 dnem
rodič
revize
eaa51f33f5

binární
server/python/platforms/__pycache__/base.cpython-313.pyc


binární
server/python/platforms/__pycache__/douyin.cpython-313.pyc


binární
server/python/platforms/__pycache__/weixin.cpython-313.pyc


binární
server/python/platforms/__pycache__/xiaohongshu.cpython-313.pyc


+ 1 - 0
server/python/platforms/base.py

@@ -229,6 +229,7 @@ class BasePublisher(ABC):
 
         proxy = proxy_config or self.proxy_config
         if proxy and isinstance(proxy, dict) and proxy.get('server'):
+            print(f"[{self.platform_name}] 使用代理: {proxy.get('server')}", flush=True)
             self.browser = await playwright.chromium.launch(headless=self.headless, proxy=proxy)
         else:
             self.browser = await playwright.chromium.launch(headless=self.headless)

+ 9 - 2
server/python/platforms/weixin.py

@@ -321,6 +321,9 @@ class WeixinPublisher(BasePublisher):
         from playwright.async_api import async_playwright
         
         playwright = await async_playwright().start()
+        proxy = self.proxy_config if isinstance(getattr(self, 'proxy_config', None), dict) else None
+        if proxy and proxy.get('server'):
+            print(f"[{self.platform_name}] 使用代理: {proxy.get('server')}", flush=True)
         
         # 参考 matrix: 使用系统内的 Chrome 浏览器,避免 H264 编码错误
         # 如果没有安装 Chrome,则使用默认 Chromium
@@ -328,12 +331,16 @@ class WeixinPublisher(BasePublisher):
             self.browser = await playwright.chromium.launch(
                 # headless=self.headless,
                 headless=False,
-                channel="chrome"  # 使用系统 Chrome
+                channel="chrome",  # 使用系统 Chrome
+                proxy=proxy if proxy and proxy.get('server') else None
             )
             print(f"[{self.platform_name}] 使用系统 Chrome 浏览器")
         except Exception as e:
             print(f"[{self.platform_name}] Chrome 不可用,使用 Chromium: {e}")
-            self.browser = await playwright.chromium.launch(headless=self.headless)
+            self.browser = await playwright.chromium.launch(
+                headless=self.headless,
+                proxy=proxy if proxy and proxy.get('server') else None
+            )
         
         # 设置 HTTP Headers 防止重定向
         headers = {

+ 5 - 1
server/python/platforms/xiaohongshu.py

@@ -252,7 +252,11 @@ class XiaohongshuPublisher(BasePublisher):
         print(f"[{self.platform_name}] 视频文件存在,大小: {os.path.getsize(params.video_path)} bytes")
         
         self.report_progress(5, "正在准备发布...")
-        
+
+        if isinstance(getattr(self, 'proxy_config', None), dict) and self.proxy_config.get('server'):
+            print(f"[{self.platform_name}] 检测到代理配置,跳过 SDK 方式,使用 Playwright 走代理发布", flush=True)
+            return await self.publish_via_playwright(cookies, params)
+
         # 参考 matrix: 优先使用 XHS SDK API 方式发布(更稳定)
         if XHS_SDK_AVAILABLE:
             try: