Skip to content

Commit 4cf5af4

Browse files
authored
Merging adding-arguments branch
Adding launch arguments for v1.6.0
2 parents 88a9316 + 29da8e4 commit 4cf5af4

1 file changed

Lines changed: 74 additions & 19 deletions

File tree

batch encoder.bat

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
@echo off
22
setlocal enabledelayedexpansion
33

4-
set CurrentVersion=v1.5.2
5-
4+
set CurrentVersion=v1.6.0
65
cls
7-
if /i "%1"=="--updated-from" (
8-
echo Just updated^^! Running cleanup...
9-
timeout 1
10-
del %2
11-
)
126

137
set "icongray="
148
set "iconyellow="
@@ -18,8 +12,44 @@ set "textgreen="
1812
set "textred="
1913
set "formatend="
2014

15+
:ArgParser
16+
set "FLAG=0"
17+
for %%G in (%*) DO (
18+
set ARG=%%G
19+
rem if FLAG, record the flag name
20+
echo !ARG! | findstr "\--" > nul && (
21+
if not ["!FLAG!"]==["0"] ( rem Check if FLAG is set - if it is, then previous was a boolean.
22+
set "par_!FLAG!=true"
23+
echo %iconyellow%par_!FLAG!=TRUE%formatend%
24+
)
25+
set ARG_NAME=!ARG:~2!
26+
set "FLAG=!ARG_NAME!"
27+
echo %iconyellow%FLAG=!ARG_NAME!%formatend%
28+
) || (
29+
set "par_!FLAG!=!ARG!"
30+
echo %iconyellow%par_!FLAG!=!ARG!%formatend%
31+
set "FLAG=0"
32+
)
33+
)
34+
35+
if not ["!FLAG!"]==["0"] ( rem Final boolean catch
36+
set "par_!FLAG!=true"
37+
echo %iconyellow%par_!FLAG!=TRUE%formatend%
38+
)
39+
40+
41+
if defined par_updated-from (
42+
echo %icongray% ^^! %formatend% Just updated^^! Running cleanup...
43+
timeout /nobreak 2 > nul
44+
rem ↓ special format to remove " from string
45+
del "%par_updated-from:"=%"
46+
)
47+
48+
rem pause
49+
2150
:AskProceed
2251
call:ClearAndTitle
52+
if "%par_silent%"=="true" (goto AskUpdate)
2353
echo %icongray% i %formatend% This program will aim to encode all .mp4 files in the folder it's placed in and delete the originals.
2454
set /p "startconfirmation=Do you want to proceed? %textgray%[Y/N]%formatend%: "
2555
if /i "%startconfirmation%"=="n" exit
@@ -28,6 +58,13 @@ set "formatend="
2858

2959
:AskUpdate
3060
call:ClearAndTitle
61+
if /i "%par_silent%"=="true" (
62+
if not defined par_update (echo Error: --silent switch used but --update [true/false] not provided. & exit /b 1)
63+
set "par_update=%par_update:"=%"
64+
if /i "%par_update%"=="false" (goto FFMPEGLocation)
65+
if /i "%par_update%"=="true" (goto AutoUpdate)
66+
echo Error: --update argument invalid ^(should be [true/false]^). & exit /b 1
67+
)
3168
set /p "updateconfirmation=%icongray% ^ %formatend% Would you like to check for an update? %textgray%[Y/N]%formatend%: "
3269
if /i "%updateconfirmation%"=="n" (goto FFMPEGLocation)
3370
if /i "%updateconfirmation%"=="y" (goto AutoUpdate)
@@ -38,7 +75,6 @@ set "formatend="
3875
echo %icongray% i %formatend% Downloading information...
3976
set "updateFileName=batch_update.json"
4077
curl --silent -L -H "Accept: application/vnd.github+json" -o %updateFileName% https://api.github.com/repos/Adam-Kay/Batch-Encoder/releases/latest
41-
rem curl --silent -o batch_update.txt https://gist.githubusercontent.com/Adam-Kay/ec5da0ff40e8eb14beee2242161f5191/raw
4278

4379
>%TEMP%\batch_update.tmp findstr "tag_name" %updateFileName%
4480
<%TEMP%\batch_update.tmp set /p "ver_entry="
@@ -61,7 +97,11 @@ set "formatend="
6197
echo The program will now restart.
6298
call:GrayPause
6399
del "%updateFileName%"
64-
goto AskProceed
100+
if /i "%par_silent%"=="true" (
101+
(goto) 2>nul & "%~f0" --silent --update false --ffmpegloc "%par_ffmpegloc%"
102+
) else (
103+
(goto) 2>nul & "%~f0"
104+
)
65105
) else (
66106
echo %iconyellow% ^^! %formatend% Differing version found^^! ^(%textred%%CurrentVersion%%formatend% -^> %textgreen%%UpdateVersion%%formatend%^)
67107
echo Proceeding with update in 5 seconds; close window to cancel.
@@ -70,25 +110,38 @@ set "formatend="
70110
echo Downloading files...
71111
curl --silent -L -H "Accept: application/octet-stream" -o "batch encoder %UpdateVersion%%append%.bat" %UpdateAPIURL%
72112
echo.
73-
echo %icongreen% i %formatend% Download complete. The program will now clean up and restart.
113+
echo %icongreen% i %formatend% Download complete. The program will now clean up and restart.
74114
call:GrayPause
75115
del "%updateFileName%"
76-
(goto) 2>nul & "batch encoder %UpdateVersion%%append%.bat" --updated-from "%~f0"
116+
if /i "%par_silent%"=="true" (
117+
(goto) 2>nul & "batch encoder %UpdateVersion%%append%.bat" --updated-from "%~f0" --silent --update false --ffmpegloc "%par_ffmpegloc%"
118+
) else (
119+
(goto) 2>nul & "batch encoder %UpdateVersion%%append%.bat" --updated-from "%~f0"
120+
)
77121
)
78122

79123
:FFMPEGLocation
80124
call:ClearAndTitle
81-
rem TODO: detect FFMPEG if in same folder
125+
if /i "%par_silent%"=="true" (
126+
if not defined par_ffmpegloc (echo Error: --silent switch used but --ffmpegloc [path] not provided. & exit /b 1)
127+
set "par_ffmpegloc=%par_ffmpegloc:"=%"
128+
if not exist "%par_ffmpegloc%" (
129+
echo Error: --ffmpegloc path "%par_ffmpegloc%" provided does not exist.
130+
exit /b 1
131+
) else (
132+
set "LOCATION=%par_ffmpegloc%"
133+
goto Count
134+
)
135+
)
82136
set /p "LOCATION=%icongray% ? %formatend% Where is FFMPEG.exe located? (paste full path): "
83-
84-
set /a "COUNTER=-1"
85137

86138
:Count
139+
set /a "COUNTER=-1"
87140
for %%f in (.\*) do set /a "COUNTER+=1"
88141
set "TOTAL=%COUNTER%"
89142

90-
set /a "COUNTER=0"
91-
set "INPUTFILE="
143+
set /a "COUNTER=0"
144+
set "INPUTFILE="
92145

93146
:Conversion
94147
for %%f in (.\*) do (
@@ -173,6 +226,7 @@ echo  Completed encoding %TOTAL% files. %formatend%
173226
call:ErrorLine
174227
echo.
175228
echo A critical error occurred. The latest file has not been modified.
229+
if /i "%par_silent%"=="true" (exit /b 3)
176230
goto EndPause
177231

178232
:AutoUpdateError
@@ -183,13 +237,14 @@ echo  Completed encoding %TOTAL% files. %formatend%
183237
echo There was a problem with the auto-updater. You can download the latest version of the program at:
184238
echo https://github.com/Adam-Kay/Batch-Encoder/releases
185239
echo.
240+
if /i "%par_silent%"=="true" (exit /b 2)
186241
echo The program will now restart.
187242
call:GrayPause
188-
goto AskProceed
243+
(goto) 2>nul & "%~f0"
189244

190245
:GrayPause
191246
echo %textgray%
192-
pause
247+
if /i not "%par_silent%"=="true" (pause)
193248
echo %formatend%
194249
goto:eof
195250

@@ -214,4 +269,4 @@ echo  Completed encoding %TOTAL% files. %formatend%
214269
cls
215270
echo  Batch Encoder %CurrentVersion% %formatend%
216271
echo.
217-
goto:eof
272+
goto:eof

0 commit comments

Comments
 (0)