Skip to content

Commit a273b72

Browse files
committed
Changed file length checker. Also added ffmpeg location checks
File length checker now compares the two file lengths. If there is a more than 1 second disparity, it kicks into an error. Fixes #36.
1 parent 062a35b commit a273b72

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

batch encoder.bat

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,20 @@ if defined par_updated-from (
160160
)
161161
)
162162
set /p "LOCATION=%icongray% ? %formatend% Where is FFMPEG.exe located? (paste full path): "
163+
if not exist "%LOCATION%" (
164+
if not exist "%cd%\%LOCATION%" (
165+
echo.
166+
echo Error: Provided filepath "%LOCATION%" does not exist.
167+
call:GrayPause
168+
goto FFMPEGLocation
169+
)
170+
)
163171

164172
:Count
173+
set "LOC_TEST=%LOCATION:\=%"
174+
set "LOC_TEST=%LOC_TEST:/=%"
175+
if "%LOC_TEST%"=="%LOCATION%" (set "pwsh_prefix=.\")
176+
set "LOCATION_pwsh=%pwsh_prefix%%LOCATION%
165177
set /a "COUNTER=-1"
166178
for %%f in (.\*) do set /a "COUNTER+=1"
167179
set "TOTAL=%COUNTER%"
@@ -233,15 +245,18 @@ if defined par_updated-from (
233245
echo.
234246

235247
echo %icongray% ^| %formatend% Checking output file length...
236-
for /F "tokens=*" %%g in (
237-
'powershell -Command "$Shell = New-Object -ComObject Shell.Application; $Folder = $Shell.Namespace('%cd%'); $Folder.GetDetailsOf($Folder.ParseName('!INPUTFILE!'), 27)"'
248+
for /F "tokens=*" %%g in ( 'powershell -Command "(%LOCATION_pwsh% -i '!INPUTFILE!' 2>&1 | select-String 'Duration: (.*), s').Matches.Groups[1].Value"'
238249
) do (set LEN_INP=%%g)
239-
for /F "tokens=*" %%g in (
240-
'powershell -Command "$Shell = New-Object -ComObject Shell.Application; $Folder = $Shell.Namespace('%cd%'); $Folder.GetDetailsOf($Folder.ParseName('!OUTPUTFILE!'), 27)"'
250+
for /F "tokens=*" %%g in ( 'powershell -Command "(%LOCATION_pwsh% -i '!OUTPUTFILE!' 2>&1 | select-String 'Duration: (.*), s').Matches.Groups[1].Value"'
241251
) do (set LEN_OUT=%%g)
252+
for /F "tokens=*" %%g in ( 'powershell -Command "[Math]::Abs(((Get-Date !LEN_INP!) - (Get-Date !LEN_OUT!)).TotalSeconds)"'
253+
) do (set LEN_DIFF=%%g)
254+
242255
echo Input file: !LEN_INP! - Output file: !LEN_OUT!
243-
if /i not "!LEN_INP!"=="!LEN_OUT!" (goto CritError)
244-
echo - File lengths match^^!
256+
if !LEN_DIFF! gtr 1 (
257+
call:CritError "File length disparity outside of acceptable range ^(was !LEN_DIFF! seconds^^^)
258+
)
259+
echo - File lengths within range^^!
245260
echo.
246261
echo %icongreen% ^| %formatend% Safely proceeding with input file recycling...
247262
timeout /nobreak /t 1 > nul
@@ -264,14 +279,16 @@ if %TOTAL% equ 0 (echo  No files found. %formatend%)
264279
265280
:EndPause
266281
call:GrayPause
267-
exit /b 0
282+
(goto) 2>nul || exit /b 0
268283
269284
:CritError
270-
timeout /t 1
285+
timeout /t 1 > nul
271286
echo.
272287
call:ErrorLine
273288
echo.
274289
echo A critical error occurred. The latest file has not been modified.
290+
set errmsg=%~1
291+
if defined errmsg (echo Error message provided: %errmsg%)
275292
if /i "%par_silent%"=="true" (exit /b 3)
276293
goto EndPause
277294

0 commit comments

Comments
 (0)