home *** CD-ROM | disk | FTP | other *** search
/ PC User 2008 February / Australian_PC_User_2008-02.iso / magstuff / files / Encode360 / Encode360Installer.msi / Cabs.w1.cab / PreProcess.VBS1 < prev    next >
Encoding:
Text File  |  2007-08-13  |  3.8 KB  |  101 lines

  1. '==========================================================================
  2. ' NAME:     Encode360 PreProcess Script - OGM Subtitle Extractor
  3. ' AUTHOR:     Dan Cunningham
  4. ' DATE:     13/08/2007
  5. ' COMMENT:     This script does the following:
  6. '            Uses OGMDemuxer to find and extract subtitles
  7. '==========================================================================
  8. Dim oAppShell, oShell, oFSO, oNet
  9.  
  10. Set oAppShell        =    CreateObject("Shell.Application")
  11. Set oShell        =     CreateObject("WScript.Shell")
  12. Set oFSO         =     CreateObject("Scripting.FileSystemObject")
  13. Set oNet        =    CreateObject("WScript.Network")
  14.  
  15. sScriptPath        =     Left(WSH.ScriptFullName, Len(WSH.ScriptFullName)-Len(WSH.ScriptName)-1)
  16. sTempFolder        =    oShell.ExpandEnvironmentStrings("%TEMP%")
  17. ' -------------------------------------------------------------------------
  18. ' Get the name of the file to process
  19. If WScript.Arguments.Count >= 1 Then
  20.     sFileToProcess = UCase(WScript.Arguments(0))
  21.     WScript.Echo "File to process: " & sFileToProcess
  22.     If WScript.Arguments.Count >= 2 Then
  23.         sLanguage = UCase(WScript.Arguments(1))
  24.     Else
  25.         sLanguage = "ENG"
  26.     End If
  27. Else
  28.     WScript.Echo "No file to process specified on command-line"
  29.     WScript.Quit(10)
  30. End If
  31. ' -------------------------------------------------------------------------
  32. ' MAIN CODE
  33.  
  34. WScript.Echo "Running OGMInfo..."
  35. sOutputFile = oShell.ExpandEnvironmentStrings("%TEMP%") & "\OutputFile.Txt"
  36. oShell.Run """" & sScriptPath & "\ogminfo.exe"" """ & sFileToProcess & """ -l " & sOutputFile,0,True
  37. 'Read temp file into an Array
  38. aOutputString = Split(UCase(oFSO.OpenTextFile(sOutputFile,1,False).ReadAll),vblf) 
  39. 'Delete temp file
  40. oFSO.DeleteFile sOutputFile
  41.  
  42. GetSubtitles
  43.  
  44. Dim iSubtitleTrackNumber, sSubtitleTrackName
  45.  
  46. If iSubtitleTrackNumber = 0 And sLanguage <> "ENG" Then
  47.     WScript.Echo "No subtitles found for language: " & sLanguage & ". Defaulting to ENG..."
  48.     sLanguage = "ENG"
  49.     GetSubtitles
  50.     If iSubtitleTrackNumber = 0 Then
  51.         WScript.Echo "No subtitles found!"
  52.         WScript.Quit (2)
  53.     End If
  54. ElseIf iSubtitleTrackNumber = 0 Then
  55.     WScript.Echo "No subtitles found!"
  56.     WScript.Quit (2)
  57. End If
  58.  
  59. sOutputFile = Left(sFileToProcess, Len(sFileToProcess) - 4) & "." & sSubtitleTrackName
  60. WScript.Echo "Output File: " & sOutputFile
  61.  
  62. WScript.Echo "Running OGMDemuxer..."
  63. oShell.Run """" & sScriptPath & "\ogmdemuxer.exe"" tracks """ & sFileToProcess & """ " & iSubtitleTrackNumber & ":""" & sOutputfile & """ --dos-eol",0,True
  64.  
  65. WScript.Echo "Finished!"
  66. WScript.Quit(0)
  67.  
  68. Sub GetSubtitles
  69.     'Find the relevant lines
  70.     Dim sCurTrackNumber, sCurTrackType, sCurTrackName, bDetected
  71.     For Each sCurOutputString in aOutputString
  72.         If Instr(1,sCurOutputString,"=== STREAM",vbTextCompare) <> 0 Then
  73.             sCurTrackNumber = Left(Trim(Replace(sCurOutputString, "=== STREAM", "")), 1)
  74.             sCurTrackType = "" : sCurTrackLanguage = "" : sCurTrackName = ""
  75.             bDetected = False
  76.         End If
  77.         If Instr(1,sCurOutputString,"  TYPE :",vbTextCompare) <> 0 Then
  78.             sCurTrackType = Trim(Replace(sCurOutputString, "TYPE : [", ""))
  79.             sCurTrackType = Trim(Replace(sCurTrackType, "]", ""))
  80.         End If
  81.         If Instr(1,sCurOutputString,"LANGUAGE=",vbTextCompare) <> 0 Then
  82.             sCurTrackLanguage = Trim(Mid(sCurOutputString, 15))
  83.             sCurTrackLanguage = Trim(Replace(sCurTrackLanguage, "LANGUAGE=", ""))
  84.             sCurTrackLanguage = Trim(Replace(sCurTrackLanguage, "]", ""))
  85.         End If
  86.         If Ucase(sCurTrackType) = "TEXT" Then
  87.             sCurTrackName = "SRT"
  88.             bDetected = True
  89.         End If
  90.         If bDetected = True  And Instr(1, sCurTrackLanguage, sLanguage, vbTextCompare) Then
  91.             WScript.Echo "Subtitle Track Number: " & sCurTrackNumber
  92.             WScript.Echo "Subtitle Language: " & sCurTrackLanguage
  93.             WScript.Echo "Subtitle Type: " & sCurTrackName
  94.             iSubtitleTrackNumber = sCurTrackNumber
  95.             sSubtitleTrackName = sCurTrackName
  96.             Exit For
  97.         Else
  98.             bDetected = False
  99.         End If
  100.     Next
  101. End Sub