Powershell Rename Long and Complex Video filenames

128 views Asked by At

I just got recent released series called "THE FALL OF THE HOUSE OF USHER". I want to rename it's episode-video files to much easily readable all capitals and dots in filename replaced to spaces(1 dot-1 space, but keeping extension and it's dot intact ofcourse).

So in a nutshell what I wanna do is capture everything before and including "1080p"(and remove the rest of the junk) in all these filenames and rename them by capitalizing all and putting spaces instead of dots and keeping the same extension if it's .mkv or .mp4.

The.Fall.of.the.House.of.Usher.S01E08.The.Raven.1080p.x264.Hindi.English.Msubs.MoviesMod.org
The.Fall.of.the.House.of.Usher.S01E07.The.Pit.and.the.Pendulum.1080p.x264.Hindi.English.Msubs.MoviesMod.org
....
....

How do I do that ? I do have this code but it has been designed for different specific kinda filename of different movie, how do I change it and make a copy of code compatible with episode-video filename format like aforementioned ??

Get-ChildItem -Filter *.mkv | where-object {$_.length -gt 524288000} | Where {$_.BaseName -CNotMatch "^[A-z\s\d]+$"} | Foreach {$FileName = [Regex]::Match($_, "^(.*?)202[2|3]").Value; $FileName = $FileName -replace '\.', ' '; $FileName = $FileName.ToUpper() + ' 1080p.mkv'; rename-item -Path $_.fullname -NewName $FileName}

If we can keep "1080p" intact too, it will be cherry on the top, thanks!!

1

There are 1 answers

1
Santiago Squarzon On BEST ANSWER

This might do the trick, the first -replace '(?<=1080p|720p).+' would be creating a new string removing everything after 1080p or 720p then the following -replace '\.', ' ' will replace every . for a and lastly ToUpper() will capitalize the string. The rest is concatenating that string with the extension.

$validExtensions = '.mkv', '.mp4'
Get-ChildItem -File |
    Where-Object Extension -In $validExtensions |
    Where-Object Length -GT 500mb |
    Rename-Item -NewName {
        ($_.BaseName -replace '(?<=1080p|720p).+' -replace '\.', ' ').ToUpper() + $_.Extension
    }