Skip to content

Commit 15936b4

Browse files
authored
Update start.bat
1 parent d34ef66 commit 15936b4

File tree

1 file changed

+146
-62
lines changed

1 file changed

+146
-62
lines changed

start.bat

Lines changed: 146 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,167 @@
11
@echo off
2+
title Minecraft Video Sync Manager
3+
color 0a
24
setlocal enabledelayedexpansion
35

4-
REM ╔══════════════════════════════════════════════╗
5-
REM ║ WebDisplays Video Player Starter ║
6-
REM ╚══════════════════════════════════════════════╝
6+
:: =================================================================
7+
:: Get script location and set working directory
8+
:: =================================================================
9+
set "batchdir=%~dp0"
10+
cd /d "%batchdir%"
11+
echo Running from: %cd%
712

8-
REM === Auto-locate current folder ===
9-
set "base_dir=%~dp0"
10-
cd /d "%base_dir%"
13+
:: =================================================================
14+
:: Check Node.js installation
15+
:: =================================================================
16+
echo Checking Node.js installation...
17+
where node >nul 2>&1
18+
if %errorlevel% neq 0 (
19+
echo.
20+
echo ERROR: Node.js is not installed or not in PATH!
21+
echo Please download and install Node.js from:
22+
echo https://nodejs.org/
23+
echo.
24+
pause
25+
exit /b 1
26+
)
1127

12-
REM === Read config.txt (if present) ===
13-
set "port=3000"
14-
if exist "config.txt" (
15-
for /f "usebackq tokens=1,2 delims==" %%A in ("config.txt") do (
16-
if /I "%%A"=="port" set "port=%%B"
17-
)
28+
:: =================================================================
29+
:: Initialize configuration
30+
:: =================================================================
31+
if not exist config.txt (
32+
echo Creating default configuration...
33+
echo max_clients: 4 > config.txt
34+
echo video_file: filmeva.mp4 >> config.txt
35+
echo chunk_size: 10 >> config.txt
36+
echo port: 3000 >> config.txt
37+
echo volume_step: 5 >> config.txt
38+
echo skip_seconds: 10 >> config.txt
39+
echo Default config created
1840
)
1941

20-
REM === Check for Node.js ===
21-
where node >nul 2>nul
22-
if errorlevel 1 (
23-
echo.
24-
echo Node.js is NOT installed. Please install Node.js from https://nodejs.org/
25-
pause
26-
exit /b
42+
:: =================================================================
43+
:: Create folders if needed
44+
:: =================================================================
45+
if not exist videos (
46+
mkdir videos
47+
echo Created videos directory
2748
)
2849

29-
REM === Auto-install modules if not present ===
30-
if not exist "%base_dir%node_modules" (
31-
echo.
32-
echo Installing required modules...
50+
:: =================================================================
51+
:: Install dependencies
52+
:: =================================================================
53+
if not exist node_modules (
54+
echo Installing Node.js dependencies...
3355
call npm install
56+
echo Dependencies installed
3457
)
3558

36-
REM === Detect Hamachi IPv4 ===
37-
set "hamachi=Not Found"
38-
set "foundHamachi="
39-
for /f "tokens=*" %%L in ('ipconfig 2^>nul') do (
40-
echo %%L | findstr /I "Hamachi" >nul && set "foundHamachi=1"
41-
if defined foundHamachi (
42-
echo %%L | findstr /C:"IPv4 Address" >nul && (
43-
for /f "tokens=2 delims=:" %%A in ("%%L") do (
44-
set "hamachi=%%A"
45-
set "hamachi=!hamachi: =!"
46-
set "foundHamachi="
47-
)
48-
)
49-
)
59+
:: =================================================================
60+
:: Read configuration
61+
:: =================================================================
62+
set MAX_CLIENTS=4
63+
set VIDEO_FILE=filmeva.mp4
64+
set CHUNK_SIZE=10
65+
set PORT=3000
66+
set VOLUME_STEP=5
67+
set SKIP_SECONDS=10
68+
69+
for /f "tokens=1,* delims=: " %%a in ('type config.txt ^| findstr /v "^#"') do (
70+
if "%%a"=="max_clients" set MAX_CLIENTS=%%b
71+
if "%%a"=="video_file" set VIDEO_FILE=%%b
72+
if "%%a"=="chunk_size" set CHUNK_SIZE=%%b
73+
if "%%a"=="port" set PORT=%%b
74+
if "%%a"=="volume_step" set VOLUME_STEP=%%b
75+
if "%%a"=="skip_seconds" set SKIP_SECONDS=%%b
5076
)
5177

52-
REM === Determine which IP to show ===
53-
if not "!hamachi!"=="Not Found" (
54-
set "displayType=Hamachi"
55-
set "displayIP=!hamachi!"
78+
:: =================================================================
79+
:: Check FFmpeg installation
80+
:: =================================================================
81+
echo Checking FFmpeg installation...
82+
where ffmpeg >nul 2>&1
83+
if %errorlevel% neq 0 (
84+
echo.
85+
echo [WARNING]: FFMPEG IS NOT INSTALLED!
86+
echo Some video formats may not play correctly.
87+
echo Install FFmpeg from: https://ffmpeg.org/
88+
echo.
89+
timeout /t 5 >nul
90+
)
91+
92+
:: =================================================================
93+
:: Check firewall rule status
94+
:: =================================================================
95+
echo Checking firewall rule for port %PORT%...
96+
set FIREWALL_RULE_EXISTS=0
97+
netsh advfirewall firewall show rule name="Node.js WebDisplay" >nul 2>&1 && set FIREWALL_RULE_EXISTS=1
98+
99+
if %FIREWALL_RULE_EXISTS% equ 1 (
100+
echo Firewall rule exists
56101
) else (
57-
REM Fetch Local IP
58-
set "localip=Not Found"
59-
for /f "tokens=2 delims=:" %%f in ('ipconfig ^| findstr /c:"IPv4 Address" 2^>nul') do (
60-
set "localip=%%f"
61-
goto :gotLocal
102+
echo Firewall rule does not exist
103+
net session >nul 2>&1
104+
if %errorlevel% equ 0 (
105+
echo Adding firewall rule...
106+
netsh advfirewall firewall add rule name="Node.js WebDisplay" dir=in action=allow protocol=TCP localport=%PORT%
107+
echo Rule added for port %PORT%
108+
) else (
109+
echo.
110+
echo [WARNING]: ADMIN PRIVILEGES REQUIRED FOR FIREWALL CONFIGURATION!
111+
echo No firewall rule exists for port %PORT%.
112+
echo Server may not be accessible from other devices.
113+
echo.
114+
echo To fix: Run this script as Administrator
115+
echo.
116+
timeout /t 5 >nul
62117
)
63-
:gotLocal
64-
set "localip=!localip: =!"
65-
set "displayType=Local"
66-
set "displayIP=!localip!"
67118
)
68119

69-
REM === Fetch Public IP ===
70-
set "publicip=Unavailable"
71-
for /f "tokens=* delims=" %%i in ('powershell -Command "(Invoke-RestMethod -Uri 'https://api.ipify.org')" 2^>nul') do set publicip=%%i
120+
:: =================================================================
121+
:: Verify video file exists
122+
:: =================================================================
123+
if not exist "videos\%VIDEO_FILE%" (
124+
echo.
125+
echo ERROR: Video file not found!
126+
echo Expected: videos\%VIDEO_FILE%
127+
dir /b videos
128+
echo.
129+
pause
130+
exit /b 1
131+
)
132+
133+
:: =================================================================
134+
:: Get local IP address
135+
:: =================================================================
136+
echo Getting local IP address...
137+
set LOCAL_IP=
138+
for /f "tokens=2 delims=:" %%a in ('ipconfig ^| findstr /C:"IPv4 Address"') do (
139+
set "LOCAL_IP=%%a"
140+
set LOCAL_IP=!LOCAL_IP: =!
141+
goto :ip_found
142+
)
143+
144+
:ip_found
145+
if "%LOCAL_IP%"=="" set LOCAL_IP=localhost
72146

73-
REM === Output simplified message ===
147+
:: =================================================================
148+
:: Display server information
149+
:: =================================================================
74150
echo.
75-
echo %displayType% IP : http://%displayIP%:%port%
76-
echo Public IP : http://%publicip%:%port%
151+
echo Minecraft Video Sync Server
152+
echo ==========================
77153
echo.
78-
79-
REM === Start the server ===
80-
echo Starting server on port %port%...
81-
node server.js
82-
pause
83-
exit /b
154+
echo Settings:
155+
echo - Max Clients: %MAX_CLIENTS%
156+
echo - Video File: videos\%VIDEO_FILE%
157+
echo - Chunk Size: %CHUNK_SIZE% MB
158+
echo - Server Port: %PORT%
159+
echo - Volume Step: %VOLUME_STEP%%
160+
echo - Skip Seconds: %SKIP_SECONDS%s
161+
echo.
162+
echo Access URLs:
163+
echo - This computer: http://localhost:%PORT%
164+
echo - Your network: http://%LOCAL_IP%:%PORT%
165+
echo.
166+
echo Starting Server...
167+
node server.js %MAX_CLIENTS% %CHUNK_SIZE% %PORT% %VOLUME_STEP% %SKIP_SECONDS% "%VIDEO_FILE%"

0 commit comments

Comments
 (0)