Created
March 27, 2018 01:55
-
-
Save scrthq/2a2ecaab1e9c7c3af4049205d439bf03 to your computer and use it in GitHub Desktop.
Quick function to rename subtitle files for Plex subtitle cleanup jobs to remove duplicate locale's. Assumes you are only using a single locale for subs. Defaults to English and SRT extension.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Rename-Subtitles { | |
[CmdletBinding()] | |
Param | |
( | |
[parameter(Mandatory = $true,Position = 0,ValueFromPipeline = $true)] | |
[ValidateScript({Test-Path $_})] | |
[String] | |
$Path, | |
[parameter(Mandatory = $false)] | |
[String] | |
$Locale = "en", | |
[parameter(Mandatory = $false)] | |
[String] | |
$Extension = "srt" | |
) | |
Process { | |
foreach ($P in $Path) { | |
$subs = Get-ChildItem $P -Recurse | Where-Object {$_.Name -like "*.$($Extension)"} | |
foreach ($sub in $subs) { | |
$clearName = ((($sub.Name -replace "\.$($Locale)\.",".") -replace "\.$($Locale)\.",".") -replace "\.$($Locale)\.",".") -replace "\.$($Extension)$",".$($Locale).$($Extension)" | |
Write-Host -ForegroundColor Yellow "Renaming '$($sub.FullName)' to '$($sub.Directory)\$($clearName)'" | |
Rename-Item -Path $sub.FullName -NewName $clearName -Force | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tip Time
Place this in your PowerShell
$PROFILE
for ease of use by doing the following:ise $profile
. If you get an error that the file doesn't exist, run"" > $profile
to create it then re-runise $profile
Once you do the above, the function will be available in session whenever you open PowerShell.
Usage
Run the following, replacing the fake path
"C:\Media Library"
with the actual path to the folder containing your media:You should see output similar to the following showing you all the files it's renaming: