Ass2srt.vbs (Ass/ssa Batch Conversion srt script) _vbs

Source: Internet
Author: User

The OPlayer in the ipad only supports subtitles in the SRT format, and animations generally use subtitles in ass/ssa format, so you need to convert Ass/ssa batch srt.

Google a bit, in the "Ass2srt[ass/ssa batch conversion SRT]" found a ass2srt.wsf script, which reads as follows:

<job id= "ASS2SRT" > <script language= "JScript" > cinput= "Unicode";  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, "$" + "}"); RG =/\{[^}.]
    *}/gi;
    T3 = T3.replace (RG, "");
    RG =/(\\pos\ ([0-9]*,[0-9]*\)})/gi; 
    T3 = T3.replace (RG, "{" + "$"); } </Script> <script language= "VBScript" > Set Ad=createobject ("ADODB.stream") Set Af=createobject ("Adod B.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 =a D.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 Loo P af.savetofile gg,2 ass.savetofile gg& ". Style", 2 Next if I=0 then "Please MsgBox files to drag"
  ,, "error!"
  Else MsgBox "Converted" &i& "file (s).",, "all over!" End If </Script> </job>

A Windows script (. wsf) file is a text document containing Extensible Markup Language (XML) code that combines several features to increase the flexibility of scripting. Because Windows script files are not limited to specific engines, they can contain all scripts that follow the ActiveX (R) specification script engine.

The script file above also contains the code for JScript and VBScript. The question is, is this necessary? Only JScript or VBScript can be achieved, why mix different languages? JScript's role in code is just regular expressions, and a reasonable inference is that the author does not have a regular expression in VBScript, or that the regular expression in VBScript is too cumbersome. Even if the language mixed aside, the style of the above code is really not flattering.

Here is the ass2srt.vbs I wrote, perhaps a little bit better than the code above.

Option Explicit Const Encoding = "Unicode" ' Assume Unicode ' Author:demon ' website:http://demon.tw ' date:2012/6/16 Di M shell, folder, FSO, ext, I, args set shell = CreateObject ("Shell.Application") Set fso = CreateObject ("Scripting.filesys Temobject ") Set args = WScript.Arguments If args. Count = 0 Then Set folder = Shell. BrowseForFolder (0, "Please select the folder in which the ass caption is located", 1) If folder is no Then wscript.quit for the all 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 F Or 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, R E, 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, ",",) s = "0" & Amp 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

Save the above code as Ass2srt.vbs, and then drag the Ass/ssa caption you want to convert onto the Ass2srt.vbs script. If you need to bulk conversion of Ass/ssa subtitles more, you can put them in the same folder, and then double-click to run Ass2srt.vbs, select the folder where the subtitles can be.

Original: http://demon.tw/my-work/ass2srt.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.