This is a rather straightforward batch script that I put together for use with Adobe's free FLVCheck command-line utility (available
here, put the exe file in the same directory as the below script). The script automates the process of checking directories with FLV/MP4 files for incompleteness (and other errors for that matter).
I wrote it primarily with downloaded Youtube playlists in mind, having far too often had the not so pleasant experience of downloading hundreds of Youtube videos in a specific playlist/series, only to notice months or even years later that a few of these files were incomplete. Of course, manually checking all the downloaded files would eliminate any such issued, but for serial downloaders of streamed Youtube (and other) media, such as myself, that's simply not a viable option due to the time it takes to manually go through every single file.
The script asks you for a directory path, it then formats the directory path and sends it to FLVCheck. When FLVCheck is done, the script then processes the output by filtering out a few irrelevant/misleading warnings (such as FLVCheck not recognizing Youtube's h264+aac codec combo as a valid one). Finally, the script displays the results on-screen in an easy-to-read format as well as storing it locally as a log file for future reference (so that you can refer to the list for the videos which need to be re-downloaded). The script currently only works with one directory at a time, but I guess it shouldn't be too difficult to also add to the script an option for recursive checking of subdirectories.
I haven't gone through the whole plethora of different warnings and errors that FLVCheck can report, I just sticked to the ones that most commonly occure with incomplete video downloads (read error, missing video footer). In case any other error pops up, this will be displayed but it won't be as nicely formatted on-screen, since I haven't included the appropriate lines in the code for the formatting of that particular message. For those who want to add more formatting to the error reporting, or just check out the various error codes, these are available
here.
BTW, Adobe's FLVCheck utility can also perform some basic repairs, but there are probably much better utilities for that and my purpose with this script was simply to verify whether the downloaded videos were ok - if not, I would simply re-download them and check the directory again with the script.
Quote:
@echo off
mode 180,40
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION
title FLVCheck Script for Youtube Playlists
set exefile="flvcheck.exe"
set tempfile1=%temp%\FLVCheck1.tmp
set tempfile2=%temp%\FLVCheck2.tmp
set logfile=%temp%\FLVCheck.log
:start
cls
echo.
echo FLVCheck Script for Youtube Playlists
echo =====================================
echo.
echo This script makes use of FLVCheck in order to scan all FLV/MP4 files in a directory for errors.
echo This can for instance be very useful for quickly locating incomplete Youtube video downloads.
echo Note: No modifications whatsoever will be made on any of the files, this is a strictly read-only operation!
echo.
echo Enter the full FLV/MP4 directory path to scan (or press RETURN to exit):
echo.
:dircheck
set dir=
set /p dir=^>
if "%dir%"=="" exit
if not "%dir:~-1%"=="\" set dir=%dir%\
if not exist "%dir%" echo. &echo Directory not found! &echo. &goto dircheck
echo.
echo Scanning directory, please wait...
echo.
if exist "%dir%\*.flv" goto startscan
if exist "%dir%\*.mp4" goto startscan
echo No files to scan found! >%logfile%
goto endscan
:startscan
set date1=%date:~2%
%exefile% -n -f "%dir%*.flv" "%dir%*.mp4">%tempfile1%
set date2=%date:~2%
find /V "Invalid video codec." %tempfile1%>%tempfile2%
find /V "File not found." %tempfile2%>%tempfile1%
find /V ".mp4 passed" %tempfile1%>%tempfile2%
find /V ".flv passed" %tempfile2%>%tempfile1%
findstr/c:"---------- %tempfile1%" /i /v %tempfile1% > %tempfile2%
findstr/c:"---------- %tempfile2%" /i /v %tempfile2% > %tempfile1%
findstr /v /r /c:"^$" /c:"^\ *$" /c:"^\ *$" %tempfile1% > %tempfile2%
@echo off>%tempfile1%
call :replacestr "%date1% " "" %tempfile2%
type %tempfile1%>%tempfile2%
@echo off>%tempfile1%
call :replacestr "%date2% " "" %tempfile2%
type %tempfile1%>%tempfile2%
@echo off>%tempfile1%
call :replacestr "%dir%" "" %tempfile2%
type %tempfile1%>%tempfile2%
@echo off>%tempfile1%
call :replacestr " " " " %tempfile2%
type %tempfile1%>%tempfile2%
@echo off>%tempfile1%
call :replacestr "File read error." " File read error. " %tempfile2%
type %tempfile1%>%tempfile2%
@echo off>%tempfile1%
call :replacestr "Invalid FLV message footer." " Invalid FLV message footer." %tempfile2%
type %tempfile1%>%tempfile2%
@echo off>%tempfile1%
call :replacestr "Missing FLV metadata." "Missing FLV metadata. " %tempfile2%
type %tempfile1%>%tempfile2%
for %%a in (%tempfile2%) do (
set length=%%~za
)
if %length%==0 echo No errors found in "%dir%"... >>%tempfile2%
if not %length%==0 echo Errors found in "%dir%": >%tempfile1% &echo.>>%tempfile1% &type %tempfile2%>>%tempfile1% &type %tempfile1%>%tempfile2%
type %tempfile2%>%logfile%
del %tempfile1%
del %tempfile2%
:endscan
cls
echo.
echo Listed below are the files that have some type of error...
echo.
echo Common error codes:
echo.
echo * Error (-5): Files with file read error need to be re-checked and re-downloaded if file read error persists.
echo * Error (-9): Files with invalid FLV message footer are incomplete and need to be re-downloaded.
echo * Error (-119): Some files with missing FLV metadata can be repaired, while others need to be re-downloaded.
echo.
echo.
echo -------------------------------------------------
echo FLVCHECK.LOG:
echo -------------------------------------------------
echo.
type %logfile%
echo.
echo -------------------------------------------------
echo.
echo.
echo Press any key to continue...
pause>nul
goto start
:replacestr
if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
set "line=%%B"
if defined line (
call set "line=echo.%%line:%~1=%~2%%"
for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X>>%tempfile1%
) ELSE echo.
)
|