#cs TV TS->AVI Conversion Script Ben Evans for Killarney Heights High School - 2010 Script Function: Copies *.TS files from a remote location Converts TS files into AVI using StaxRip Automatically Deletes Old TS File and associated Temp directories Copies over converted AVI back to remote location (in a folder called converted) Everything is logged to the Local location under the name "scripted_encoder.log" #ce #Include #Include Local $vTSArray[1] $mRemoteLocation = "\\server\share" $mLocalLocation = "C:\video" writeLog("STARTED Script") writeLog("Moving all TS Files from remote machine to local storage.") ;Cut all *.TS from LIB-TV01 FileMove($mRemoteLocation & "*.ts", $mLocalLocation, 1) ;Get each .TS (Local) into Array $Files=_FileListToArray($mLocalLocation) For $vFile in $Files $vFound = StringInStr($vFile,'.ts') if $vFound <> 0 Then ;Firstly check to see if the TS exists at the remote location (eg. Script copied it rather than moved it because it was in use) If FileExists($mRemoteLocation&$vFile) Then writeLog("Ignoring TS file: " & $vFile & ". Reason: In use") FileDelete($mLocalLocation&"\"&$vFile) Else _ArrayAdd($vTSArray, $vFile) EndIf EndIf Next writeLog("Looking for *.TS files. Found "& (ubound($vTSArray)-1)) ;Open StaxRip for encoding For $vFile in $vTSArray If StringLen($vFile)>3 Then ;DOes the AVI file of this exist already? $vAvi = StringLeft($vFile,(StringLen($vFile)-3))&".avi" If Not FileExists($mLocalLocation&"\"&$vAvi) Then $vCommand = 'C:\staxrip\staxrip.exe -template:XviD "'&$mLocalLocation&'\'&$vFile&'" -encode -exit' writeLog("Executing Command: " & $vCommand) RunWait($vCommand) Else writeLog($vAvi & ' already exists. SKIPPING') EndIf EndIf Next ;Check to see if the converted AVI file exists for each correspoinding TS File For $vFile in $vTSArray If StringLen($vFile)>3 Then ;DOes the AVI file of this exist already? $vAvi = StringLeft($vFile,(StringLen($vFile)-3))&".avi" If Not FileExists($mLocalLocation&"\"&$vAvi) Then writeLog("ERROR: File " & $vAvi & " SHOULD exist, but doesn't. Encoding probably failed") Else If FileGetSize($mLocalLocation&"\"&$vAvi) < 10048576 Then writeLog("ERROR: " &$vAvi& " is <10MB.") Else writeLog($vAvi & ' Exists and is >10MB. Deleting corresp TS and temp folder') FileDelete($mLocalLocation&"\"&$vFile) If FileExists($mLocalLocation&"\" & StringLeft($vFile,(StringLen($vFile)-3))&" temp files") Then ;$vCommand = 'rmdir "'&$mLocalLocation&'\' & StringLeft($vFile,(StringLen($vFile)-3))&' temp files"' DirRemove($mLocalLocation&"\" & StringLeft($vFile,(StringLen($vFile)-3))&" temp files",1) ;writeLog($vCommand) ;Run($vCommand) Else writeLog("WARNING: Folder "&StringLeft($vFile,(StringLen($vFile)-3))&" temp files doesn't appear to exist. Cannot delete") EndIf EndIf EndIf EndIf Next ;Cut the file from local location and put in CONVERTED folder in LIB-TV01 writeLog('Moving all AVI files to Remote Location') FileMove($mLocalLocation&"\*.avi", $mRemoteLocation & "converted", 1) writeLog('FINISHED script') Func writeLog($vInfo) $file = FileOpen($mLocalLocation&'\scripted_encoder.log',1) If $file = -1 Then Exit EndIf FileWriteLine($file, @YEAR&"-"&@MON&"-"&@MDAY&" "&@HOUR&":"&@MIN&":"&@SEC&" - "&$vInfo) FileClose($file) EndFunc