home *** CD-ROM | disk | FTP | other *** search
- '==========================================================================
- ' NAME: Encode360 PreProcess Script - OGM Subtitle Extractor
- ' AUTHOR: Dan Cunningham
- ' DATE: 13/08/2007
- ' COMMENT: This script does the following:
- ' Uses OGMDemuxer 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
- ' -------------------------------------------------------------------------
- ' MAIN CODE
-
- WScript.Echo "Running OGMInfo..."
- sOutputFile = oShell.ExpandEnvironmentStrings("%TEMP%") & "\OutputFile.Txt"
- oShell.Run """" & sScriptPath & "\ogminfo.exe"" """ & sFileToProcess & """ -l " & sOutputFile,0,True
- 'Read temp file into an Array
- aOutputString = Split(UCase(oFSO.OpenTextFile(sOutputFile,1,False).ReadAll),vblf)
- '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 OGMDemuxer..."
- oShell.Run """" & sScriptPath & "\ogmdemuxer.exe"" tracks """ & sFileToProcess & """ " & iSubtitleTrackNumber & ":""" & sOutputfile & """ --dos-eol",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,"=== STREAM",vbTextCompare) <> 0 Then
- sCurTrackNumber = Left(Trim(Replace(sCurOutputString, "=== STREAM", "")), 1)
- sCurTrackType = "" : sCurTrackLanguage = "" : sCurTrackName = ""
- bDetected = False
- End If
- If Instr(1,sCurOutputString," TYPE :",vbTextCompare) <> 0 Then
- sCurTrackType = Trim(Replace(sCurOutputString, "TYPE : [", ""))
- sCurTrackType = Trim(Replace(sCurTrackType, "]", ""))
- End If
- If Instr(1,sCurOutputString,"LANGUAGE=",vbTextCompare) <> 0 Then
- sCurTrackLanguage = Trim(Mid(sCurOutputString, 15))
- sCurTrackLanguage = Trim(Replace(sCurTrackLanguage, "LANGUAGE=", ""))
- sCurTrackLanguage = Trim(Replace(sCurTrackLanguage, "]", ""))
- End If
- If Ucase(sCurTrackType) = "TEXT" Then
- sCurTrackName = "SRT"
- bDetected = True
- End If
- If bDetected = True And Instr(1, sCurTrackLanguage, sLanguage, vbTextCompare) Then
- WScript.Echo "Subtitle Track Number: " & sCurTrackNumber
- WScript.Echo "Subtitle Language: " & sCurTrackLanguage
- WScript.Echo "Subtitle Type: " & sCurTrackName
- iSubtitleTrackNumber = sCurTrackNumber
- sSubtitleTrackName = sCurTrackName
- Exit For
- Else
- bDetected = False
- End If
- Next
- End Sub