86 lines
2.7 KiB
Batchfile
86 lines
2.7 KiB
Batchfile
@echo off
|
|
setlocal EnableExtensions
|
|
set "PATH=%SystemRoot%\System32;%PATH%"
|
|
cd /d "%~dp0"
|
|
set "COLLECTOR_GUI=1"
|
|
|
|
if exist "%SystemRoot%\System32\chcp.com" (
|
|
"%SystemRoot%\System32\chcp.com" 65001 >nul 2>&1
|
|
)
|
|
|
|
title 抖音 IM 凭证采集器
|
|
|
|
if exist ".browser_ready" del /f /q ".browser_ready" >nul 2>&1
|
|
|
|
echo.
|
|
echo ========================================
|
|
echo 抖音 IM 凭证采集器
|
|
echo ========================================
|
|
echo 正在启动,请稍候...
|
|
echo ========================================
|
|
echo.
|
|
|
|
if not exist ".venv\Scripts\pythonw.exe" (
|
|
echo 首次使用,正在安装环境(约 1~3 分钟)...
|
|
echo.
|
|
call "%~dp0setup.bat" silent
|
|
if not exist ".venv\Scripts\pythonw.exe" (
|
|
echo.
|
|
echo [错误] 安装失败,请先安装 Python 3.10+ 并勾选 Add to PATH
|
|
pause
|
|
exit /b 1
|
|
)
|
|
)
|
|
|
|
if not exist "%~dp0.first_run_done" (
|
|
set "DESKTOP=%USERPROFILE%\Desktop"
|
|
set "LNK=%DESKTOP%\DouyinIMCollector.lnk"
|
|
if not exist "%LNK%" (
|
|
powershell -NoProfile -ExecutionPolicy Bypass -Command "$s=(New-Object -ComObject WScript.Shell).CreateShortcut('%LNK%');$s.TargetPath='%~dp0一键采集.bat';$s.WorkingDirectory='%~dp0';$s.Description='Douyin IM Collector';$s.Save()" >nul 2>&1
|
|
)
|
|
echo ok> "%~dp0.first_run_done"
|
|
)
|
|
|
|
set "PYW=.venv\Scripts\pythonw.exe"
|
|
set "PLAYWRIGHT_BROWSERS_PATH=%~dp0playwright-browsers"
|
|
if not exist "%PLAYWRIGHT_BROWSERS_PATH%" mkdir "%PLAYWRIGHT_BROWSERS_PATH%"
|
|
|
|
powershell -NoProfile -ExecutionPolicy Bypass -Command "8765..8770|ForEach-Object{Get-NetTCPConnection -LocalPort $_ -State Listen -ErrorAction SilentlyContinue|ForEach-Object{Stop-Process -Id $_.OwningProcess -Force -ErrorAction SilentlyContinue}}" >nul 2>&1
|
|
|
|
set "HAS_CHROME=0"
|
|
for /d %%D in ("%PLAYWRIGHT_BROWSERS_PATH%\chromium-*") do (
|
|
if exist "%%D\chrome-win64\chrome.exe" set "HAS_CHROME=1"
|
|
if exist "%%D\chrome-win\chrome.exe" set "HAS_CHROME=1"
|
|
)
|
|
if "%HAS_CHROME%"=="0" (
|
|
echo 首次需下载浏览器(约 130MB),请稍候...
|
|
".venv\Scripts\python.exe" -m playwright install chromium
|
|
)
|
|
|
|
echo 正在打开无痕浏览器...
|
|
start "" "%PYW%" "%~dp0run_douyin_collector.py"
|
|
|
|
set /a WAIT_SEC=0
|
|
:wait_browser
|
|
if exist ".browser_ready" goto browser_ok
|
|
set /a WAIT_SEC+=1
|
|
if %WAIT_SEC% GEQ 120 (
|
|
echo.
|
|
echo [错误] 启动超时(120 秒),请检查是否被安全软件拦截。
|
|
pause
|
|
exit /b 1
|
|
)
|
|
if %WAIT_SEC%==5 echo 仍在启动中,首次可能较慢...
|
|
if %WAIT_SEC%==15 echo 仍在启动中,请继续等待...
|
|
if %WAIT_SEC%==30 echo 仍在启动中,请继续等待...
|
|
timeout /t 1 /nobreak >nul
|
|
goto wait_browser
|
|
|
|
:browser_ok
|
|
echo.
|
|
echo 浏览器已启动,请在新窗口中操作。
|
|
echo 本窗口 2 秒后自动关闭...
|
|
timeout /t 2 /nobreak >nul
|
|
endlocal
|
|
exit /b 0
|