SHARE
TWEET

Untitled

a guest Sep 11th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # The directory of the ASS files that need to be cleaned
  2. $dir = "C:\Users\Kintoki\Desktop\ASS_files"
  3.  
  4. $files = Get-ChildItem "$dir" | Where-Object {$_.Extension -eq ".ass"}
  5. #Start batch loop
  6. for ($i=0; $i -lt $files.Count; $i++) {
  7.     $subs = $files[$i].FullName
  8.     $ASS = Get-Content -LiteralPath $subs
  9.     Write-Host ('>> File: ' + $files[$i].BaseName)
  10.     #Remove non-used styles
  11.     foreach($elem in ($ASS -match "Style:\s(\D.*)").Replace("Style: ","")){
  12.         $tmp = $elem.split(",") | Select-Object -Index 0
  13.         if($tmp){
  14.             $str = ',' + $tmp + ','
  15.             [int]$occ = (Select-String -InputObject $ASS -Pattern $str -AllMatches).Matches.Count
  16.             #check if the first assigned actor/name is actually used, else remove
  17.             if($occ -le 0){
  18.                 $ASS = $ASS -ne "Style: $elem"
  19.                 Write-Host "* Removed stylename '$tmp' because it does not appear in ASS"
  20.             }
  21.         }
  22.     }
  23.     Set-Content -Encoding UTF8 -LiteralPath $subs -Value $ASS
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top