home *** CD-ROM | disk | FTP | other *** search
- '==========================================================================
- ' NAME: Encode360 PreProcess Script - Matroska Subtitle Extractor
- ' AUTHOR: Dan Cunningham
- ' DATE: 13/08/2007
- ' COMMENT: This script does the following:
- ' Uses MKVExtract to find and extract subtitles
- '==========================================================================
- Dim oAppShell, oShell, oFSO, oNet
-
- Set oAppShell = CreateObject("Shell.Application")
- Set oShell = CreateObject("WScript.Shell")
- Set oFSO = CreateObject("Scripting.FileSystemObject")
- Set oNet = CreateObject("WScript.Network")
-
- sScriptPath = Left(WSH.ScriptFullName, Len(WSH.ScriptFullName)-Len(WSH.ScriptName)-1)
- sTempFolder = oShell.ExpandEnvironmentStrings("%TEMP%")
- ' -------------------------------------------------------------------------
- ' Get the name of the file to process
- If WScript.Arguments.Count >= 1 Then
- sFileToProcess = UCase(WScript.Arguments(0))
- WScript.Echo "File to process: " & sFileToProcess
- If WScript.Arguments.Count >= 2 Then
- sLanguage = UCase(WScript.Arguments(1))
- Else
- sLanguage = "ENG"
- End If
- Else
- WScript.Echo "No file to process specified on command-line"
- WScript.Quit(10)
- End If
-
- ' Verify our file exists
- If Not oFSO.FileExists(sFileToProcess) Then
- WScript.Echo "File to process was not found"
- WScript.Quit(11)
- End If
- ' -------------------------------------------------------------------------
- ' MAIN CODE
-
- WScript.Echo "Running MKVInfo..."
- sOutputFile = oShell.ExpandEnvironmentStrings("%TEMP%") & "\OutputFile.Txt"
- oShell.Run """" & sScriptPath & "\mkvinfo.exe"" """ & sFileToProcess & """ -r " & sOutputFile,0,True
- 'Read temp file into an Array
- aOutputString = Split(UCase(oFSO.OpenTextFile(sOutputFile,1,False).ReadAll),vbCrlf)
- 'Delete temp file
- oFSO.DeleteFile sOutputFile
-
- GetSubtitles
-
- Dim iSubtitleTrackNumber, sSubtitleTrackName
-
- If iSubtitleTrackNumber = 0 And sLanguage <> "ENG" Then
- WScript.Echo "No subtitles found for language: " & sLanguage & ". Defaulting to ENG..."
- sLanguage = "ENG"
- GetSubtitles
- If iSubtitleTrackNumber = 0 Then
- WScript.Echo "No subtitles found!"
- WScript.Quit (2)
- End If
- ElseIf iSubtitleTrackNumber = 0 Then
- WScript.Echo "No subtitles found!"
- WScript.Quit (2)
- End If
-
- sOutputFile = Left(sFileToProcess, Len(sFileToProcess) - 4) & "." & sSubtitleTrackName
- WScript.Echo "Output File: " & sOutputFile
-
- WScript.Echo "Running MKVExtract..."
- oShell.Run """" & sScriptPath & "\mkvextract.exe"" tracks """ & sFileToProcess & """ " & iSubtitleTrackNumber & ":""" & sOutputfile & """",0,True
-
- WScript.Echo "Finished!"
- WScript.Quit(0)
-
- Sub GetSubtitles
- 'Find the relevant lines
- Dim sCurTrackNumber, sCurTrackType, sCurTrackName, bDetected
- For Each sCurOutputString in aOutputString
- If Instr(1,sCurOutputString,"TRACK NUMBER:",vbTextCompare) <> 0 Then
- sCurTrackNumber = Trim(Replace(sCurOutputString, "| + TRACK NUMBER:", ""))
- sCurTrackType = "" : sCurTrackLanguage = "" : sCurTrackName = ""
- bDetected = False
- End If
- If Instr(1,sCurOutputString,"TRACK TYPE:",vbTextCompare) <> 0 Then
- sCurTrackType = Trim(Replace(sCurOutputString, "| + TRACK TYPE:", ""))
- End If
- If Instr(1,sCurOutputString,"LANGUAGE:",vbTextCompare) <> 0 Then
- sCurTrackLanguage = Trim(Replace(sCurOutputString, "| + LANGUAGE:", ""))
- End If
- If Instr(1,sCurOutputString,"CODEC ID:",vbTextCompare) <> 0 Then
- sCurTrackCodecID = Trim(Replace(sCurOutputString, "| + CODEC ID:", ""))
- End If
- If Instr(1,sCurOutputString,"NAME:",vbTextCompare) <> 0 Then
- sCurTrackName = Trim(Replace(sCurOutputString, "| + NAME:", ""))
- bDetected = True
- End If
- If bDetected = True And sCurTrackType = "SUBTITLES" And sCurTrackLanguage = sLanguage Then
- If Instr(1, sCurTrackName, sLanguage, vbTextCompare) Then
- sCurTrackName = Replace(sCurTrackCodecID, "S_TEXT/", "")
- sCurTrackName = Replace(sCurTrackName, "UTF8", "SRT")
- End If
- WScript.Echo "Subtitle Track Number: " & sCurTrackNumber
- WScript.Echo "Subtitle Language: " & sCurTrackLanguage
- WScript.Echo "Subtitle Codec ID: " & sCurTrackCodecID
- WScript.Echo "Subtitle Type: " & sCurTrackName
- iSubtitleTrackNumber = sCurTrackNumber
- sSubtitleTrackName = sCurTrackName
- Exit For
- Else
- bDetected = False
- End If
- Next
- End Sub
-