本帖最后由 went 于 2022-4-6 19:43 编辑
| | | cls | | | | function Hide-Src($num1,$num2,[System.IO.FileInfo]$srt){ | | $arr = Get-Content $srt.FullName | | if($arr.Count -lt 4){ return $null } | | $txt = $arr | Select-Object -First 3 | Select-Object -Skip 2 | | | | $r = [regex]::new('(?<=>[^<]*)[a-zA-Z](?=[^<]*<)') | | | | $char_len = $txt.Length - $r.Replace($txt,'').Length | | if($char_len -lt $num2){ return $null } | | | | $char_del = $char_len/$num2*$num1 | | $r.Matches($txt) | Sort-Object { return Get-Random } | Select-Object -First $char_del | foreach { | | $txt = $txt.SubString(0,$_.Index) + '_' + $txt.SubString($_.Index+1,$txt.Length-$_.Index-1) | | } | | return &{ | | '{0}\{1}[{2}分之{3}挖空].srt' -f $srt.Directory.FullName,$srt.BaseName,$num1,$num2 | | $arr[0..1] | | $txt | | $arr[3..($arr.Count-1)] | | } | | } | | $msg = @' | | 1.全部所有的字母挖空请按1 | | 2.五分之四的字母挖空请按2 | | 3.四分之三的字母挖空请按3 | | 4.三分之二的字母挖空请按4 | | 5.二分之一的字母挖空请按5 | | 6.三分之一的字母挖空请按6 | | 7.四分之一的字母挖空请按7 | | 8.五分之一的字母挖空请按8 | | 请输入 | | '@ | | | | while($true){ | | $a = $b = 0 | | $chs = Read-Host -Prompt $msg | | switch($chs){ | | '1' { $a=1; $b=1 } | | '2' { $a=4; $b=5 } | | '3' { $a=3; $b=4 } | | '4' { $a=2; $b=3 } | | '5' { $a=1; $b=2 } | | '6' { $a=1; $b=3 } | | '7' { $a=1; $b=4 } | | '8' { $a=1; $b=5 } | | } | | if($a -ne 0 -and $b -ne 0){ | | Get-ChildItem -Recurse '*.srt' | foreach { | | if($_.BaseName -notmatch '\[.*?\]'){ | | Write-Host $_.FullName | | $res = Hide-Src -num1 $a -num2 $b -srt $_ | | if($res -ne $null){ | | $res[1..($res.Count-1)] | Out-File -LiteralPath $res[0] | | Write-Host $res[0] | | } | | '-------------------' | | } | | } | | } else { Write-Host '输入无效' } | | Write-Host "`r`n按任意键回到主菜单" | | [void][System.Console]::ReadKey();cls | | }COPY |
|