Audio/video stream recording forums

Attention Visitor:
You may have to register or log in before you can post:
  • Click the register link to sign up.
  • Registered members please fill in the form below and click the "Log in" button.
To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Audio/video stream recording forums > Media file management > Repairing, splitting and merging media files
Register FAQ Members List Calendar Mark Forums Read

Reply Post New Thread
 
Thread Tools Display Modes
  #1  
Old 05-15-2012, 05:35 AM
streamdumper streamdumper is offline
Junior Member
 
Join Date: Apr 2010
Posts: 7
streamdumper is on a distinguished road
Default

Script for checking "completeness" of downloaded Youtube videos


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.
)

Last edited by streamdumper : 05-16-2012 at 12:19 AM.
Reply With Quote
  #2  
Old 05-16-2012, 05:14 AM
evol evol is offline
Senior Member
 
Join Date: Jun 2011
Posts: 228
evol is on a distinguished road
Default

Re: Script for checking "completeness" of downloaded Youtube videos


Thanks for that tool from Adobe i never knew about it and of course your script.
Reply With Quote
  #3  
Old 05-16-2012, 06:14 AM
KSV KSV is offline
Senior Member
 
Join Date: Apr 2011
Posts: 853
KSV is on a distinguished road
Cool

Re: Script for checking "completeness" of downloaded Youtube videos


AFAIK FLVCheck doesn't support flv with H264+AAC streams which is most common these days.
Reply With Quote
  #4  
Old 05-16-2012, 11:03 PM
streamdumper streamdumper is offline
Junior Member
 
Join Date: Apr 2010
Posts: 7
streamdumper is on a distinguished road
Default

Re: Script for checking "completeness" of downloaded Youtube videos


Quote:
Originally Posted by KSV View Post
AFAIK FLVCheck doesn't support flv with H264+AAC streams which is most common these days.
I see... Well, that explains why FLVCheck keeps complaining about finding invalid codecs...

Though, this doesn't affect the main purpose of this particular script that I wrote, which is simply to check whether the files are complete or not (repairing them is a whole other issue, though)...
Reply With Quote
  #5  
Old 05-23-2012, 08:57 AM
streamdumper streamdumper is offline
Junior Member
 
Join Date: Apr 2010
Posts: 7
streamdumper is on a distinguished road
Default

Re: Script for checking "completeness" of downloaded Youtube videos


I thought I'd also give a recommendation for KCSoftware's VideoInspector utility. It's a freeware utility that can verify the completeness of AVI, MKV, MPEG1/2 and QT files. So, basically using VideoInspector in combination with this script of mine (for FLV and MP4 files) will pretty much cover all the relevant video formats.

Once installed, just select Extra Tools -> Batch Mode, click on Add Files to add all the files that you want to check and read the results on the "Complete" column. There's also an export to file option available as well for logging the results for later reference.

Just a word of warning, though, to those allergic to adware. You need to uncheck a number of pre-selected boxes for browser toolbar/homepage settings during the installation process. Also, you might want to uncheck and decline to participate in the "anonymous user statistics" participation, which is also pre-selected. Apart from these installation caveats, the program is 100% clean and free to use (if downloaded from their web page).
Reply With Quote
Reply Post New Thread
Tags: , , , , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -6. The time now is 02:09 AM.


Powered by All-streaming-media.com; 2006-2011
vB forum hacked with Zoints add-ons