andy vt's tools & blog

automating lazy

About this Page

  • Title:
  • Moderated By:
  • Created:
  • Modified:
  • Modified By: babgvant
  • Revision:

  • Internal Url:

Common Tasks

Track Processed Files

As I do all of my commercial scans overnight using a batch (.bat) file, I miss that DVRMSToolbox.exe no longer tracks processed files (from version 1.1.0.4).  This now means that a folder scan will re-check by default all files in the chosen folder.  If the xml file already exists for it, the show isn't actually re-scanned for commercials from scratch, but it does take a little time to check every file for a matching profile and copy the existing xml files, etc.  To avoid this, a batch file can use DVRMStoMPEG.exe instead.  In its simplest form,  it consists of just one command (all on one line):

for %%f in ("R:\Recorded TV\*.dvr-ms") do (if not exist "C:\Program Files\DVRMSToolbox\CommercialsXml\%%~nf.xml" ("C:\Program Files\DVRMSToolbox\DVRMStoMPEG.exe" /if="%%f" /of="%%f" /act=nativecommdetect))

This command checks which dvr-ms files in the watched folder don't have a corresponding xml file, and scans these for commercials using the nativecommdetect profile.  A more involved batch file can use  a separate file list that tracks the already processed files, and logs any scans. In the example below, the batch saves a list of the dvr-ms files that have already been scanned for commercials; then it processes any dvr-ms that doesn't have an entry in the list (again with nativecommdetect); finally, it outputs a revised list, and reports on the result.  To use the batch file, just copy the code below, changing only the folder information at the top, paste it into a new text file, then Save As > "commscan.bat" (with the quotation marks).  Set the 'Every File' profile to 'Do Nothing', and run the batch file overnight:

------------------
 
 @echo off

set recfolder=R:\Recorded TV\
set logfolder=C:\

:process_recfolder
echo %DATE% %TIME% Starting commercials scan
call :processed_list
for %%f in ("%recfolder%*.dvr-ms") do (call :scan_comms "%%f")
if not exist "%logfolder%completed.txt" goto :end
type "%logfolder%completed.txt"
del /q "%logfolder%completed.txt"
call :processed_list
goto :end

:scan_comms
find /I %1 "%logfolder%processed_list.log" >nul
if %ERRORLEVEL%==0 goto :eof
"C:\Program Files\DVRMSToolbox\DVRMStoMPEG.exe" /if=%1 /of=%1 /act=nativecommdetect >nul
echo Completed: %~dpnx1>>"%logfolder%completed.txt"
goto :eof

:processed_list
echo PROCESSED FILE LIST>"%logfolder%processed_list.log"
echo %DATE% %TIME%>>"%logfolder%\processed_list.log"
for %%f in ("C:\Program Files\DVRMSToolbox\CommercialsXml\*.xml") do (echo %recfolder%%%~nf.dvr-ms>>"%logfolder%processed_list.log")
goto :eof

:end
echo %DATE% %TIME% Finished commercials scan
goto :eof

------------------

For fuller logging information, delete ">nul" ( or you can divert the DTb log to another file by replacing >nul with e.g. >>"C:\dtb.log").  The batch file can also be adapted to run any action, or series of actions, by just adding new blocks of code.  For example, to remove commercials first from all episodes of Lost using the cutcommovedvrms action, then scan the remaining files for commercials, change the :process_recfolder block to the following:

:process_recfolder
echo %DATE% %TIME% Starting commercials scan
call :processed_list
rem ## Remove comms from all files with 'lost' in the title ##
for %%f in ("%recfolder%*lost*.dvr-ms") do (call :remove_comms "%%f")
rem ## Scan all other files for commercials ##
for %%f in ("%recfolder%*.dvr-ms") do (call :scan_comms "%%f")
if not exist "%logfolder%completed.txt" goto :end
type "%logfolder%completed.txt"
del /q "%logfolder%completed.txt"
call :processed_list
goto :end

Then add this new block:

:remove_comms
find /I %1 "%logfolder%processed_list.log" >nul
if %ERRORLEVEL%==0 goto :eof
"C:\Program Files\DVRMSToolbox\DVRMStoMPEG.exe" /if=%1 /of=%1 /act=cutcommovedvrms >nul
echo Completed: %~dpnx1>>"%logfolder%completed.txt"
echo %~dpnx1>>"%logfolder%processed_list.log"
goto :eof

------------------

This code can be written a bit more simply (to avoid the duplication, for example), but it's usually best to make everything as explicit as possible when using batch files. :)  

-Hecks

@2008 andy vt
Powered by Community Server (Non-Commercial Edition), by Telligent Systems