Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Subtitle Renamer
- # Written by No_MansLand on Reddit
- #
- # Bugs:
- # - Renamed files are incorrect in the print out, not the actual export.
- # - Copies the primary file for some reason.. I'll figure this out eventually.
- # - No ISO-816 yet.. I'm planning on this.
- # - Probably something else? I dont know..
- # - Let me know.
- Set-ExecutionPolicy -Scope CurrentUser Bypass
- Write-Host -ForegroundColor Green -BackgroundColor Black "-----------------------------------------------------------------------------"
- Write-Host " "
- Write-Host -ForegroundColor Red -BackgroundColor Black "Automatic Subtitle Mover & Renamer for PLEX"
- Write-Host -ForegroundColor Green -BackgroundColor Black "Because for some reason, in 2023 - Plex still cannot use a Subtitle file.."
- Write-Host " "
- Write-Host -ForegroundColor Blue -BackgroundColor Black "Instructions for use:"
- Write-Host " "
- Write-Host -ForegroundColor Green -BackgroundColor Black "Step 1. Enter the Parent Path (e.g: C:\Users\bsmith\Downloads\TVShow\Season #\"
- Write-Host -ForegroundColor Green -BackgroundColor Black "Step 2. Press Enter."
- Write-Host -ForegroundColor Green -BackgroundColor Black "Step 3. Wait."
- Write-Host " "
- Write-Host -ForegroundColor Red -BackgroundColor Black "Important Notice: This will only look for files called 'Subtitles' or 'Subs'"
- Write-Host " "
- Write-Host -ForegroundColor Green -BackgroundColor Black "-----------------------------------------------------------------------------"
- $parentDirectory = Read-Host "Please Enter the parent directory"
- while([String]::IsNullOrEmpty($parentDirectory) -or ([String]::IsNullOrWhiteSpace($parentDirectory))) {
- Write-Host -ForegroundColor Red -BackgroundColor Black "Parent Directory must be entered."
- $parentDirectory = Read-Host "Please Enter the parent directory"
- }
- $checkPath = Test-Path -Path $parentDirectory
- while($checkPath -eq $False) {
- Write-Host -ForegroundColor Red -BackgroundColor Black "This path does not exist. Please double check it."
- $parentDirectory = Read-Host "Please Enter the parent directory"
- $checkPath = Test-Path -Path $parentDirectory
- }
- if($checkPath -eq $true) {
- Write-Host -ForegroundColor Green -BackgroundColor Black "This path exists, checking for Subs or a Subtitles folder."
- $subs = Test-Path -Path "$($parentDirectory)\subs"
- if($subs -eq $False) {
- Write-Host -ForegroundColor Cyan -BackgroundColor Black "Subs file doesn't exist."
- $path_type = "0"
- } else {
- Write-Host -ForegroundColor Cyan -BackgroundColor Black "Found a Subs file."
- $path_type = "1"
- }
- $subtitles = Test-Path -Path "$($parentDirectory)\Subtitles"
- if($subtitles -eq $False) {
- Write-Host -ForegroundColor Cyan -BackgroundColor Black "Subtitles file doesn't exist."
- $path_types = "0"
- } else {
- Write-Host -ForegroundColor Cyan -BackgroundColor Black "Found a Subtitles file"
- $path_types = "1"
- }
- if(($path_type -eq 0) -and ($path_types -eq 0)) {
- Write-Host -ForegroundColor Red -BackgroundColor Black "Unable to find a Subs or Subtitles Folder."
- } else {
- if($path_type -eq 1) {
- $folders = Get-ChildItem -Path "$($parentDirectory)\Subs" -Recurse -Directory | Where-Object({$_.GetFiles().Count -ne 0})
- $directory = "$($parentDirectory)\Subs"
- }
- if($path_types -eq "1") {
- $folders = Get-ChildItem -Path "$($parentDirectory)\Subtitles" -Recurse -Directory | Where-Object({$_.GetFiles().Count -ne 0})
- $directory = "$($parentDirectory)\Subtitles"
- }
- Write-Host -ForegroundColor Cyan -BackgroundColor Black "$($folders.Count) folder(s) have been found."
- Write-Host -ForegroundColor Green -BackgroundColor Black "Beginning Copy of Subtitles."
- foreach($subfolder in $folders) {
- Write-Host -ForegroundColor Cyan -BackgroundColor Black "Beginning copy of subtitles from $($subfolder)"
- $copyingPath = $directory + "\" + $subfolder
- $file = (Get-ChildItem $copyingPath)
- foreach($cpfile in $file) {
- $new_name = "$($subfolder.Name).$($cpfile.Name)"
- #$rename_path = $file.Fullname
- #Rename-Item -Path $rename_path -NewName $new_name
- Get-ChildItem -Path "$($cpfile.FullName)" | Rename-Item -NewName $new_name
- Write-Host -ForegroundColor Green -BackgroundColor Black "Renamed $($file.Name) to $($new_name)"
- $updated_file = (Get-ChildItem $copyingPath)
- try {
- foreach($copyfile in $updated_file) {
- Copy-Item -Path "$($copyfile.FullName)" -Destination $parentDirectory
- Write-Host -ForegroundColor Green -BackgroundColor Black "Succesfully Copied: $($copyfile.Name)"
- }
- } catch {
- Write-Host -ForegroundColor Red -BackgroundColor Black "Failed to copy file name: $($copyfile.Name)"
- }
- }
- }
- Write-Host -ForegroundColor Green -BackgroundColor Black "Succesfully Copied all subtitles files."
- }
- }
- Write-Host -ForegroundColor Green -BackgroundColor Black "Script has been completed & Plex can now read these files."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement