PowerShell script to organise downloaded media and name based on resolution

Problem:

I needed a script to automatically organise downloaded media, including renaming, creating folders and more.

The below script will:

1. Replace any dots with spaces (i.e. movie.2018.mkv)

2. Remove any of the ‘junk’ i.e. the smaller metadata files which you usually delete.

3. Remove the year from the title

4. Check the resolution and if 4K name appropriately

5. Create a folder based on the file name

6. Move the finished product to a specified folder for metadata processing i.e Media Companion.

Get-ChildItem F:\Download_Complete -recurse | where-object {$_.length -gt 100000000} | Move-Item -Destination F:\Download_Complete -force

$dir = "F:\Download_Complete"
CD $dir
Get-ChildItem -Recurse |
    Where-Object {$_.Name -match '.'} |
    Rename-Item -NewName {$_.BaseName.replace('.',' ')+$_.Extension}

Get-ChildItem -Path F:\Download_Complete -Recurse -Directory | Remove-Item -Recurse -Force

Get-ChildItem F:\Download_Complete\*.* | 
    rename-item -newname { 
        ($_.BaseName -replace '\s*\d.*') + $_.Extension
    }


gci F:\Download_Complete\*.* | % {

$res = C:\ffmpeg\bin\ffprobe -v error -select_streams v:0 -show_entries stream=width -of csv=s=x:p=0 $_.Fullname If ($res -gt 3000) { rename-item path $_.Fullname Newname ( $_.basename +  4K + $_.extension) }


    }

$SourceFolder = "F:\Download_Complete"
$TargetFolder = "F:\Ready\Movies"

Get-ChildItem -Path $SourceFolder -Filter *.mkv |
    ForEach-Object {
        $ChildPath = Join-Path -Path $_.Name.Replace('.mkv','') -ChildPath $_.Name

        [System.IO.FileInfo]$Destination = Join-Path -Path $TargetFolder -ChildPath $ChildPath

        if( -not ( Test-Path -Path $Destination.Directory.FullName ) ){
            New-Item -ItemType Directory -Path $Destination.Directory.FullName
            }

        Move-Item -Path $_.FullName -Destination $Destination.FullName -force
        }

One Reply to “PowerShell script to organise downloaded media and name based on resolution”

  1. You should really elaborate as to the “and more” that this script will perform if one is not fully prepared. Essentially all non .mkv files contained in subfolders of the $SourceFolder folder will be deleted, so fair warning to folks using this script.

Leave a Reply

Your email address will not be published. Required fields are marked *