Advertisement
Guest User

Subtitle Renamer for PLEX

a guest
Feb 22nd, 2023
756
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Subtitle Renamer
  2. # Written by No_MansLand on Reddit
  3. #
  4. # Bugs:
  5. # - Renamed files are incorrect in the print out, not the actual export.
  6. # - Copies the primary file for some reason.. I'll figure this out eventually.
  7. # - No ISO-816 yet.. I'm planning on this.
  8. # - Probably something else? I dont know..
  9. # - Let me know.
  10.  
  11. Set-ExecutionPolicy -Scope CurrentUser Bypass
  12.  
  13. Write-Host -ForegroundColor Green -BackgroundColor Black "-----------------------------------------------------------------------------"
  14. Write-Host " "
  15. Write-Host -ForegroundColor Red -BackgroundColor Black "Automatic Subtitle Mover & Renamer for PLEX"
  16. Write-Host -ForegroundColor Green -BackgroundColor Black "Because for some reason, in 2023 - Plex still cannot use a Subtitle file.."
  17. Write-Host " "
  18. Write-Host -ForegroundColor Blue -BackgroundColor Black "Instructions for use:"
  19. Write-Host " "
  20. Write-Host -ForegroundColor Green -BackgroundColor Black "Step 1. Enter the Parent Path (e.g: C:\Users\bsmith\Downloads\TVShow\Season #\"
  21. Write-Host -ForegroundColor Green -BackgroundColor Black "Step 2. Press Enter."
  22. Write-Host -ForegroundColor Green -BackgroundColor Black "Step 3. Wait."
  23. Write-Host " "
  24. Write-Host -ForegroundColor Red -BackgroundColor Black "Important Notice: This will only look for files called 'Subtitles' or 'Subs'"
  25. Write-Host " "
  26. Write-Host -ForegroundColor Green -BackgroundColor Black "-----------------------------------------------------------------------------"
  27.  
  28. $parentDirectory = Read-Host "Please Enter the parent directory"
  29.  
  30. while([String]::IsNullOrEmpty($parentDirectory) -or ([String]::IsNullOrWhiteSpace($parentDirectory))) {
  31.     Write-Host -ForegroundColor Red -BackgroundColor Black "Parent Directory must be entered."
  32.     $parentDirectory = Read-Host "Please Enter the parent directory"
  33. }
  34. $checkPath = Test-Path -Path $parentDirectory
  35. while($checkPath -eq $False) {
  36.     Write-Host -ForegroundColor Red -BackgroundColor Black "This path does not exist. Please double check it."
  37.     $parentDirectory = Read-Host "Please Enter the parent directory"
  38.     $checkPath = Test-Path -Path $parentDirectory
  39. }
  40. if($checkPath -eq $true) {
  41.     Write-Host -ForegroundColor Green -BackgroundColor Black "This path exists, checking for Subs or a Subtitles folder."
  42.     $subs = Test-Path -Path "$($parentDirectory)\subs"
  43.  
  44.     if($subs -eq $False) {
  45.         Write-Host -ForegroundColor Cyan -BackgroundColor Black "Subs file doesn't exist."
  46.         $path_type = "0"
  47.     } else {
  48.         Write-Host -ForegroundColor Cyan -BackgroundColor Black "Found a Subs file."
  49.         $path_type = "1"
  50.     }
  51.     $subtitles = Test-Path -Path "$($parentDirectory)\Subtitles"
  52.     if($subtitles -eq $False) {
  53.         Write-Host -ForegroundColor Cyan -BackgroundColor Black "Subtitles file doesn't exist."
  54.         $path_types = "0"
  55.     } else {
  56.         Write-Host -ForegroundColor Cyan -BackgroundColor Black "Found a Subtitles file"
  57.         $path_types = "1"
  58.     }
  59.     if(($path_type -eq 0) -and ($path_types -eq 0)) {
  60.         Write-Host -ForegroundColor Red -BackgroundColor Black "Unable to find a Subs or Subtitles Folder."
  61.     } else {
  62.         if($path_type -eq 1) {
  63.             $folders = Get-ChildItem -Path "$($parentDirectory)\Subs" -Recurse -Directory | Where-Object({$_.GetFiles().Count -ne 0})
  64.             $directory = "$($parentDirectory)\Subs"
  65.         }
  66.         if($path_types -eq "1") {
  67.             $folders = Get-ChildItem -Path "$($parentDirectory)\Subtitles" -Recurse -Directory | Where-Object({$_.GetFiles().Count -ne 0})
  68.             $directory = "$($parentDirectory)\Subtitles"
  69.         }
  70.         Write-Host -ForegroundColor Cyan -BackgroundColor Black "$($folders.Count) folder(s) have been found."
  71.         Write-Host -ForegroundColor Green -BackgroundColor Black "Beginning Copy of Subtitles."
  72.         foreach($subfolder in $folders) {
  73.             Write-Host -ForegroundColor Cyan -BackgroundColor Black "Beginning copy of subtitles from $($subfolder)"
  74.             $copyingPath = $directory + "\" + $subfolder
  75.             $file = (Get-ChildItem $copyingPath)
  76.             foreach($cpfile in $file) {
  77.                 $new_name = "$($subfolder.Name).$($cpfile.Name)"
  78.                 #$rename_path = $file.Fullname
  79.                 #Rename-Item -Path $rename_path -NewName $new_name
  80.                 Get-ChildItem -Path "$($cpfile.FullName)" | Rename-Item -NewName $new_name
  81.                 Write-Host -ForegroundColor Green -BackgroundColor Black "Renamed $($file.Name) to $($new_name)"
  82.                 $updated_file = (Get-ChildItem $copyingPath)
  83.                 try {
  84.                     foreach($copyfile in $updated_file) {
  85.                         Copy-Item -Path "$($copyfile.FullName)" -Destination $parentDirectory
  86.                         Write-Host -ForegroundColor Green -BackgroundColor Black "Succesfully Copied: $($copyfile.Name)"
  87.                     }
  88.                 } catch {
  89.                     Write-Host -ForegroundColor Red -BackgroundColor Black "Failed to copy file name: $($copyfile.Name)"
  90.                 }
  91.             }
  92.         }
  93.         Write-Host -ForegroundColor Green -BackgroundColor Black "Succesfully Copied all subtitles files."
  94.     }
  95. }
  96. Write-Host -ForegroundColor Green -BackgroundColor Black "Script has been completed & Plex can now read these files."
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement