返回列表 发帖

请求删除此帖,废弃无用了请求删除此帖,废弃无用了

本帖最后由 cl2039996 于 2022-5-8 16:29 编辑

请求删除此帖,废弃无用了请求删除此帖,废弃无用了请求删除此帖,废弃无用了请求删除此帖,废弃无用了

bat存为ANSI/GB2312编码
<# :
cls&echo off&cd /d "%~dp0"&mode con lines=5000
set "current=%cd%"
powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText(\"%~f0\",[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
pause
exit
#>
$current=get-item -literal $env:current;
$files=@(dir -literal $current.FullName -recurse|?{($_.Extension -eq '.srt') -and ($_ -is [System.IO.FileInfo])});
$enc=New-Object System.Text.UTF8Encoding $False;
[System.Collections.ArrayList]$filelist=@();
for($i=0;$i -lt $files.length;$i++){
    $text=[IO.File]::ReadAllText($files[$i].FullName, $enc);
    $m=[regex]::match($text, '(?i)\{\\pos\(\d+ ?, ?\d+\)\}');
    if($m.Success){
        [void]$filelist.add($files[$i]);
        write-host ($m.groups[0].value+'  '+$files[$i].FullName.Substring($current.FullName.length));
    }
}
if($filelist.Count -ge 1){
    write-host '1、修改位置标签';
    write-host '2、清除位置标签';
   
    $choice1='';
    while($choice1 -notmatch '^(1|2)$'){
        $choice1=read-host '输入数字序号并回车';
    }
   
    $pos='';
    if($choice1 -eq '1'){
        $x_value=read-host '输入x坐标并回车';
        $y_value=read-host '输入y坐标并回车';
        if(($x_value -notmatch '^\d+$') -or ($y_value -notmatch '^\d+$')){
            write-host '输入有误';exit;
        }
        $pos='{\pos('+$x_value+','+$y_value+')}';
    }
    clear-host;
    for($i=0;$i -lt $filelist.Count;$i++){
        write-host $filelist[$i].FullName.Substring($current.FullName.length);
        $text=[IO.File]::ReadAllText($filelist[$i].FullName, $enc);
        $text=$text -replace '\{\\pos\(\d+ ?, ?\d+\)\}', $pos;
        [IO.File]::WriteAllText($filelist[$i].FullName, $text, $enc);
    }
}else{
    $pos='';
    $x_value=read-host '输入x坐标并回车';
    $y_value=read-host '输入y坐标并回车';
    if(($x_value -notmatch '^\d+$') -or ($y_value -notmatch '^\d+$')){
        write-host '输入有误';exit;
    }
    $pos='{\pos('+$x_value+','+$y_value+')}';
   
    for($i=0;$i -lt $files.length;$i++){
        write-host $files[$i].FullName.Substring($current.FullName.length);
        [System.Collections.ArrayList]$newtext=@();
        $oldtext=[IO.File]::ReadAllText($files[$i].FullName, $enc);
        $arr=$oldtext.trim() -split '[\r\n]{3,}';
        for($j=0;$j -lt $arr.length;$j++){
            $brr=$arr[$j] -split '[\r\n]+';
            if(-not [string]::IsNullOrEmpty($brr[2])){
                if(($brr[2] -notmatch '\{\\an\d+\}')){
                    $brr[2]=$pos+$brr[2];
                }
            }
            $line=$brr -join "`r`n";
            [void]$newtext.add($line);
        }
        [IO.File]::WriteAllText($files[$i].FullName, $($newtext -join "`r`n`r`n"), $enc);
    }
}COPY
提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

本帖最后由 cl2039996 于 2022-3-19 16:53 编辑

回复 2# zaqmlp

您好,经测试,各项功能符合预期,非常感激!可是,有一个棘手的问题是:

执行bat之后,pos位置标签完美添加上了,可是意外发现,所有srt中的中文字幕全部变成乱码,如下面红色所示:
1
00:00:00,000 --> 00:00:03,360
{\pos(300,400)}<font color="#00ff00">and then, <b><font color="#ff0000">all of a sudden</font><\b>, out of nowhere, they just...</font>
<font color="#00ff00">Ȼ��ͻȻ֮�䣬</font> <font color="#00ff00">��֪�Ӻζ��������Ǿ͡���</font>

2
00:00:00,000 --> 00:00:03,360
{\an9}<b><font color="#cccccc">Biff and Chip - Series 1- 5. A Sticky Situation_batch</font><\b>

请求大佬给修一下,您之前写的各种bat没有出现这种现象。修复bug后红包立刻转给您

TOP

本帖最后由 zaqmlp 于 2022-3-19 17:03 编辑

回复 3# cl2039996
以后提需求时打包测试文件用网盘分享出来

$enc=New-Object System.Text.UTF8Encoding $False;
改为
$enc=[Text.Encoding]::GetEncoding('GB2312');
提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

回复 4# zaqmlp


    遵命大佬,是我着急了,以后我上传供测试的文件。

TOP

返回列表