Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # The directory of the ASS files that need to be cleaned
- $dir = "C:\Users\Kintoki\Desktop\ASS_files"
- $files = Get-ChildItem "$dir" | Where-Object {$_.Extension -eq ".ass"}
- #Start batch loop
- for ($i=0; $i -lt $files.Count; $i++) {
- $subs = $files[$i].FullName
- $ASS = Get-Content -LiteralPath $subs
- Write-Host ('>> File: ' + $files[$i].BaseName)
- #Remove non-used styles
- foreach($elem in ($ASS -match "Style:\s(\D.*)").Replace("Style: ","")){
- $tmp = $elem.split(",") | Select-Object -Index 0
- if($tmp){
- $str = ',' + $tmp + ','
- [int]$occ = (Select-String -InputObject $ASS -Pattern $str -AllMatches).Matches.Count
- #check if the first assigned actor/name is actually used, else remove
- if($occ -le 0){
- $ASS = $ASS -ne "Style: $elem"
- Write-Host "* Removed stylename '$tmp' because it does not appear in ASS"
- }
- }
- }
- Set-Content -Encoding UTF8 -LiteralPath $subs -Value $ASS
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement