| |
| |
| |
| |
| |
| |
| $txtfile=".\黑名单单词列表.txt"; |
| $newfolder="E:\单词归类"; |
| |
| if(-not (test-path -literal $txtfile)){write-host ('"'+$txtfile+'" 未找到');exit;} |
| |
| $enc=[Text.Encoding]::GetEncoding('GB2312'); |
| $dic=New-Object 'System.Collections.Generic.Dictionary[string, string]'; |
| $text=[IO.File]::ReadAllLines($txtfile, $enc); |
| for($i=0;$i -lt $text.length;$i++){ |
| $key=$text[$i].trimend().ToLower(); |
| if(-not $dic.ContainsKey($key)){ |
| $dic.add($key, ''); |
| } |
| } |
| |
| $folders=@(dir -literal "."|?{$_ -is [System.IO.DirectoryInfo]}); |
| for($i=0;$i -lt $folders.length;$i++){ |
| write-host $folders[$i].FullName; |
| $files=@(dir -literal $folders[$i].FullName|?{('.srt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])}); |
| for($j=0;$j -lt $files.length;$j++){ |
| write-host $files[$j].Name; |
| $oldtext=[IO.File]::ReadAllText($files[$j].FullName, $enc); |
| $arr=$oldtext.trim() -split '[\r\n]+'; |
| if($arr.length -ge 3){ |
| $oldline=$arr[2] -replace '<[^>]+?>','中'; |
| $mm=[regex]::matches($arr[2], '<[^>]+?>'); |
| $m=[regex]::matches($oldline, "(?i)[a-z'_\-\d]+"); |
| foreach($it in $m){ |
| $isexist=$false; |
| $word=$it.groups[0].value; |
| $key=$word.ToLower(); |
| if($dic.ContainsKey($key)){ |
| $isexist=$true; |
| } |
| if((-not $isexist) -and ($word -match '[a-z]')){ |
| $newpath=$newfolder.trimend('\')+'\'+$word; |
| if(-not (test-path -literal $newpath)){[void][IO.Directory]::CreateDirectory($newpath);} |
| $newbasename="[{0}][{1}][{2}]" -f $word,$folders[$i].Name,(get-date).ToString('yyyy-MM-dd HH点mm分ss秒fff毫秒'); |
| $newsrt=$newpath+'\'+$newbasename+$files[$j].Extension; |
| $reg="(?i)(?<=^|[^a-z'_\-\d])"+[regex]::Escape($word)+"(?=[^a-z'_\-\d]|$)"; |
| $newline=[regex]::replace($oldline, $reg, { |
| param($z); |
| '[b]<font color="#ff0000">'+$z.groups[0].value+'</font>[\b]'; |
| }); |
| if($mm.Count -ge 1){ |
| $global:n=0; |
| $newline=[regex]::replace($newline, '中', { |
| param($z); |
| $mm[$global:n].groups[0].value; |
| $global:n++; |
| }); |
| } |
| $brr=$arr.Clone(); |
| $brr[2]=$newline; |
| $newtext=($brr -join "`r`n")+"`r`n`r`n"+'2'+"`r`n"+$arr[1]+"`r`n"+'{\an9}[b]<font color="#cccccc">'+$folders[$i].Name+'</font>[\b]'; |
| [IO.File]::WriteAllText($newsrt, $newtext, $enc); |
| $newmp4=$newpath+'\'+$newbasename+'.mp4'; |
| $oldmp4=$folders[$i].FullName+'\'+$files[$j].BaseName+'..mp4'; |
| if(test-path -liter $oldmp4){ |
| copy-item -literal $oldmp4 $newmp4 -force; |
| }else{ |
| $oldmp4=$folders[$i].FullName+'\'+$files[$j].BaseName+'.mp4'; |
| if(test-path -liter $oldmp4){ |
| copy-item -literal $oldmp4 $newmp4 -force; |
| } |
| } |
| } |
| } |
| } |
| } |
| }COPY |