Last active
August 29, 2017 15:42
-
-
Save mollyporph/fa3f8babda49e1b416b8 to your computer and use it in GitHub Desktop.
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-TVEpisodes{ | |
[CmdletBinding(SupportsShouldProcess)] | |
Param( | |
[string]$Name, | |
[int]$Season = 1) | |
process{ | |
$seasonFolders = dir -Directory | |
$seasonFolders | %{ | |
$seasonFolderName = $PSItem.FullName | |
$seasonStr = "$($Season)".PadLeft(2,"0"); | |
$Season++; | |
$index = 0; | |
if($pscmdlet.ShouldProcess($Name)) | |
{ | |
gci $_.FullName -File -Filter *.mkv | % { | |
$index++; | |
$str = "$($index)".PadLeft(2,"0"); | |
mv -LiteralPath $PSItem.FullName | |
-Destination "$($seasonFolderName)/$($Name) S$($seasonStr)E$($str)$($PSItem.Extension)" -Force | |
} | |
} | |
else | |
{ | |
gci $_.FullName -File -Filter *.mkv | % { | |
$index++; | |
$str = "$($index)".PadLeft(2,"0"); | |
mv -LiteralPath $PSItem.FullName | |
-Destination "$($seasonFolderName)/$($Name) S$($seasonStr)E$($str)$($PSItem.Extension)" -Force -WhatIf | |
} | |
} | |
} | |
} | |
} | |
# Animes for example usually use a continous number for episodes, which is hard for media platforms to crunch | |
# In my experience most of these series have season folders but still use the global numbering system. | |
# this script will traverse in to all subfolders, treating them as a season starting with the $Season param number | |
# It will then rename all episodes to the more standard "{Name} S{Season}E{EpisodeIndex}" format | |
#Given an example | |
# Naruto Shippuden S1 | |
# > Naruto Shippuden - 1.mkv | |
# > ... | |
# ... | |
# Naruto Shippuden S21 | |
# > Naruto Shippuden - 480.mkv | |
# > Naruto Shippuden - 481.mkv | |
# > Naruto Shippuden - 482.mkv | |
# > Naruto Shippuden - 483.mkv | |
# > ... | |
# Rename-TVEpisodes "Naruto Shippuden" | |
# Will result in the following folder structure | |
# Naruto Shippuden S1 | |
# > Naruto Shippuden S01E01.mkv | |
# > ... | |
# ... | |
# Naruto Shippuden S21 | |
# > Naruto Shippuden S21E01.mkv | |
# > Naruto Shippuden S21E02.mkv | |
# > Naruto Shippuden S21E03.mkv | |
# > Naruto Shippuden S21E04.mkv | |
# > ... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment