- @if(0)==(0) echo off
- dir /b *zh-cn.srt | cscript //nologo //e:jscript "%~f0"
- pause & goto :EOF
- @end
-
- var fso = new ActiveXObject('Scripting.FileSystemObject');
- var reg = /^(\d\d:\d\d:\d\d,\d+)[^\r\n]+(\r?\n[^\r\n]+)/gm;
-
- while(!WSH.StdIn.AtEndOfStream) {
- var map = [];
- var cnFile = WSH.StdIn.ReadLine();
- var enFile = cnFile.replace(/zh-cn\.srt$/i, 'en.srt');
- if(!fso.FileExists(enFile)) continue;
-
- var cnStr = getText(cnFile);
- var enStr = getText(enFile);
-
- while(arr=reg.exec(enStr)) map[arr[1]] = arr[2];
- var s = cnStr.replace(
- /^(\d\d:\d\d:\d\d,\d+)[^\r\n]+\r?\n[^\r\n]+/gm,
- function(s0, s1) { return s0 + map[s1]; }
- )
-
- var file = cnFile.replace(/zh-cn\.srt$/i, 'chs-en.srt');
- writeToFile(s, file);
-
- //fso.DeleteFile(cnFile);
- //fso.DeleteFile(enFile);
- }
-
- function getText(file) {
- with(new ActiveXObject('ADODB.Stream')){
- Mode = 3; Type = 2;
- Charset = 'utf-8';
- Open();
- LoadFromFile(file);
- var s = ReadText(-1);
- }
- return s;
- }
-
- function writeToFile(s, file) {
- with(new ActiveXObject('ADODB.Stream')){
- Mode = 3; Type = 2;
- Charset = 'utf-8';
- Open();
- WriteText(s);
- SaveToFile(file, 2);
- }
- }
复制代码
|