mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-06 07:56:52 +08:00
fix: support Windows collector console encoding
This commit is contained in:
@@ -39,10 +39,10 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v7
|
||||||
|
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v6
|
||||||
with:
|
with:
|
||||||
python-version: '3.12'
|
python-version: '3.12'
|
||||||
cache: pip
|
cache: pip
|
||||||
@@ -94,14 +94,14 @@ jobs:
|
|||||||
python -c "import hashlib, os; from pathlib import Path; path = Path('dist') / os.environ['ASSET_NAME']; path.with_name(path.name + '.sha256').write_text(f'{hashlib.sha256(path.read_bytes()).hexdigest()} {path.name}\n', encoding='utf-8')"
|
python -c "import hashlib, os; from pathlib import Path; path = Path('dist') / os.environ['ASSET_NAME']; path.with_name(path.name + '.sha256').write_text(f'{hashlib.sha256(path.read_bytes()).hexdigest()} {path.name}\n', encoding='utf-8')"
|
||||||
|
|
||||||
- name: Upload collector artifact
|
- name: Upload collector artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: ${{ matrix.artifact_name }}
|
name: ${{ matrix.artifact_name }}
|
||||||
path: |
|
path: |
|
||||||
dist/${{ matrix.asset_name }}
|
dist/${{ matrix.asset_name }}
|
||||||
dist/${{ matrix.asset_name }}.sha256
|
dist/${{ matrix.asset_name }}.sha256
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
retention-days: 14
|
retention-days: 3
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
name: Upload collectors to release
|
name: Upload collectors to release
|
||||||
@@ -114,7 +114,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Download collector artifacts
|
- name: Download collector artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v8
|
||||||
with:
|
with:
|
||||||
pattern: site-adapter-collector-*
|
pattern: site-adapter-collector-*
|
||||||
path: release-assets
|
path: release-assets
|
||||||
|
|||||||
@@ -1409,8 +1409,21 @@ def _parse_args() -> argparse.Namespace:
|
|||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def _configure_standard_streams() -> None:
|
||||||
|
"""将可重配置的标准输出流统一为 UTF-8,避免 Windows 本地代码页无法输出中文。"""
|
||||||
|
for stream in (sys.stdout, sys.stderr):
|
||||||
|
reconfigure = getattr(stream, "reconfigure", None)
|
||||||
|
if not callable(reconfigure):
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
reconfigure(encoding="utf-8", errors="replace")
|
||||||
|
except (LookupError, OSError):
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
"""交互式读取采集参数并生成站点适配 ZIP。"""
|
"""交互式读取采集参数并生成站点适配 ZIP。"""
|
||||||
|
_configure_standard_streams()
|
||||||
args = _parse_args()
|
args = _parse_args()
|
||||||
print("MoviePilot 站点适配采集器")
|
print("MoviePilot 站点适配采集器")
|
||||||
print("原始页面不会落盘;临时浏览器关闭后会清理登录状态,输出前会裁剪并脱敏。")
|
print("原始页面不会落盘;临时浏览器关闭后会清理登录状态,输出前会裁剪并脱敏。")
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
import zipfile
|
import zipfile
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -467,3 +470,20 @@ def test_browser_capture_builds_archive_without_manual_cookie_input(monkeypatch,
|
|||||||
assert manifest["collector_version"] == "1.0.1"
|
assert manifest["collector_version"] == "1.0.1"
|
||||||
assert request["params"]["search"] == "{keyword}"
|
assert request["params"]["search"] == "{keyword}"
|
||||||
assert b"very-secret-cookie-value" not in combined
|
assert b"very-secret-cookie-value" not in combined
|
||||||
|
|
||||||
|
|
||||||
|
def test_help_uses_utf8_when_parent_forces_legacy_code_page() -> None:
|
||||||
|
"""父进程强制 cp1252 时,中文 argparse 帮助仍应以 UTF-8 正常输出。"""
|
||||||
|
environment = os.environ.copy()
|
||||||
|
environment["PYTHONIOENCODING"] = "cp1252"
|
||||||
|
|
||||||
|
result = subprocess.run(
|
||||||
|
[sys.executable, str(Path(collector.__file__)), "--help"],
|
||||||
|
check=False,
|
||||||
|
capture_output=True,
|
||||||
|
env=environment,
|
||||||
|
timeout=30,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result.returncode == 0, result.stderr.decode("utf-8", errors="replace")
|
||||||
|
assert "站点适配" in result.stdout.decode("utf-8")
|
||||||
|
|||||||
Reference in New Issue
Block a user