主頁(yè) > 知識(shí)庫(kù) > ass2srt.vbs(ass/ssa批量轉(zhuǎn)換srt的腳本)

ass2srt.vbs(ass/ssa批量轉(zhuǎn)換srt的腳本)

熱門標(biāo)簽:如何用機(jī)器人進(jìn)行電銷 東營(yíng)快遞外呼系統(tǒng) 佛山真人電銷機(jī)器人廠家 地圖標(biāo)注政府哪個(gè)部門管 齊齊哈爾高德地圖標(biāo)注店 除了地圖標(biāo)注還有這種生意嗎 神行者美術(shù)館地圖標(biāo)注 哪里有便宜的地圖標(biāo)注公司 百度地圖標(biāo)注點(diǎn)距離代碼

iPad中的OPlayer只支持srt格式的字幕,而動(dòng)畫一般使用的是ass/ssa格式的字幕,所以需要將ass/ssa批量轉(zhuǎn)換srt。

Google了一下,在《ass2srt[ass/ssa批量轉(zhuǎn)換srt]》中找到一個(gè)ass2srt.wsf腳本,內(nèi)容如下:

job id="ass2srt">
  script language="JScript">
  cInput="unicode";  // You can find them from:
  cOutput="utf-8";  // HKEY_CLASSES_ROOT\MIME\Database\Charset
  function rrr(){
    re = /Dialogue: [^,.]*[0-9]*,([1-9]?[0-9]*:[0-9]*:[0-9]*.[0-9]*),([1-9]?[0-9]*:[0-9]*:[0-9]*.[0-9]*),[^,.]*,[^,.]*,[0-9]*,[0-9]*,[0-9]*,[^,.]*,(.*)/gi;
    rv = ss.match(re);
    t1 = RegExp.$1;
    t2 = RegExp.$2;
    t3 = RegExp.$3;
    rg = /\{[^}.]*(\\pos\([0-9]*,[0-9]*\))[^}.]*}/gi;
    t3 = t3.replace(rg,"$1" + "}"); 
    rg =/\{[^}.]*}/gi;
    t3 = t3.replace(rg,"");
    rg =/(\\pos\([0-9]*,[0-9]*\)})/gi;
    t3 = t3.replace(rg,"{" + "$1"); 
    }
  /Script>
  script language="VBScript">
  set ad=CreateObject("adodb.stream")
  set af=CreateObject("adodb.stream")
  set ass=CreateObject("adodb.stream")
  ad.open
  af.open
  ass.open
  ad.Charset=cInput
  af.Charset=cOutput
  ass.Charset=cOutput
  Set objArgs = WScript.Arguments
  For I = 0 to objArgs.Count - 1
    ad.LoadFromFile(objArgs(I))
    z=0
    gg=left(objArgs(I),len(objArgs(I))-3)"srt"
    Do While ad.eos > True
      ss =ad.ReadText(-2)
      if left(ss,8)="Dialogue" then 
        ss=replace(ss,",,",",d,")
        rrr
        t3=replace(t3,"\n",vbcrlf)
        t3=replace(t3,"\N",vbcrlf)
        z=z+1
        af.writetext z,1
        af.writetext t1  " --> "  t2,1
        af.writetext t3  vbcrlf  vbcrlf
      else 
        ass.writetext ss,1
      end if
    Loop
    af.savetofile gg,2
    ass.savetofile gg".style",2
  Next
  if i=0 then 
    msgbox "Please drag files to me!",,"Error!"
  else
    msgbox "Converted "i" file(s).",,"All Over!"
  end if
  /Script>
/job>

Windows 腳本 (.wsf) 文件是一個(gè)包含可擴(kuò)展標(biāo)記語(yǔ)言(XML)代碼的文本文檔,它結(jié)合了若干功能,提高了腳本編程的靈活性。由于 Windows 腳本文件并不局限于特定的引擎,它們能夠包含所有遵循 ActiveX(R)規(guī)范的腳本引擎的腳本。

上面的腳本文件同時(shí)包含了JScript和VBScript的代碼。問題在于,有這個(gè)必要么?單純用JScript或者VBScript都可以實(shí)現(xiàn),為什么要混用不同的語(yǔ)言呢?JScript在代碼中的作用僅僅是正則表達(dá)式而已,一個(gè)合理的推斷是作者不會(huì)VBScript的正則表達(dá)式,或者嫌VBScript的正則表達(dá)式太麻煩。就算撇開語(yǔ)言混雜不說(shuō),上面代碼的風(fēng)格實(shí)在是不敢恭維。

下面是我寫的ass2srt.vbs,也許比上面的代碼好一點(diǎn)點(diǎn)罷。

Option Explicit
Const Encoding = "unicode" 'assume unicode

'Author: Demon
'Website: http://demon.tw
'Date: 2012/6/16

Dim shell, folder, fso, ext, i, args
Set shell = CreateObject("Shell.Application")
Set fso = CreateObject("scripting.filesystemobject")
Set args = WScript.Arguments

If args.Count = 0 Then
  Set folder = shell.BrowseForFolder(0, "請(qǐng)選擇ASS字幕所在的文件夾", 1)
  If folder Is Nothing Then WScript.Quit
  For Each i In fso.GetFolder(folder.Self.Path).Files
    ext = LCase(fso.GetExtensionName(i.Path))
    If ext = "ass" Or ext = "ssa" Then
      ASS2SRT i.Path, Encoding
    End If
  Next
Else
  For i = 0 To args.Count - 1
    ASS2SRT args(i), Encoding
  Next
End If

MsgBox CInt(i)  " file(s) Converted!", vbInformation

Function ASS2SRT(path, charset)
  Const adTypeText = 2
  Const adReadLine = -2
  Const adSaveCreateOverWrite = 2
  Dim ass, srt, re, str, arr, s, e, t, i
  
  Set ass = CreateObject("ADODB.Stream")
  Set srt = CreateObject("ADODB.Stream")
  Set re = New RegExp
  
  re.Global = True
  re.IgnoreCase = True
  re.Pattern = "\{.*?\}"
  
  ass.Type = adTypeText
  ass.Charset = charset
  ass.Open
  ass.LoadFromFile path
  
  srt.Type = adTypeText
  srt.Charset = "utf-8"
  srt.Open
  
  i = 0
  
  Do Until ass.EOS
    str = ass.ReadText(adReadLine)
    If Left(str, 8) = "Dialogue" Then
      i = i + 1
      arr = Split(str, ",", 10)
      s = "0"  arr(1)  "0" 'Start time
      e = "0"  arr(2)  "0" 'End time
      t = arr(9) 'Text
      s = Replace(s, ".", ",")
      e = Replace(e, ".", ",")
      t = re.Replace(t, "")
      t = Replace(t, "\n", vbCrLf)
      t = Replace(t, "\N", vbCrLf)
      srt.WriteText i  vbCrLf
      srt.WriteText s  " --> "  e  vbCrLf
      srt.WriteText t  vbCrLf  vbCrLf
    End If
  Loop
  
  path = Left(path, Len(path) - 3)  "srt"
  srt.SaveToFile path, adSaveCreateOverWrite
End Function

把上面代碼保存為ass2srt.vbs,然后將需要轉(zhuǎn)換的ass/ssa字幕拖動(dòng)到ass2srt.vbs腳本上即可。如果需要批量轉(zhuǎn)換的ass/ssa字幕比較多,可以先把它們放到同一個(gè)文件夾里,然后直接雙擊運(yùn)行ass2srt.vbs,選擇字幕所在的文件夾即可。

原文:http://demon.tw/my-work/ass2srt.html

標(biāo)簽:四平 ???/a> 銅川 鶴壁 西安 文山 邢臺(tái) 湖州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ass2srt.vbs(ass/ssa批量轉(zhuǎn)換srt的腳本)》,本文關(guān)鍵詞  ass2srt.vbs,ass,ssa,批量,轉(zhuǎn)換,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ass2srt.vbs(ass/ssa批量轉(zhuǎn)換srt的腳本)》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于ass2srt.vbs(ass/ssa批量轉(zhuǎn)換srt的腳本)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章