Skip to content

Instantly share code, notes, and snippets.

@fischgeek
Created February 19, 2019 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fischgeek/af584af4274075260aa19ffa2f99b32c to your computer and use it in GitHub Desktop.
Save fischgeek/af584af4274075260aa19ffa2f99b32c to your computer and use it in GitHub Desktop.
PowerShell script to rip DVDs into a Plex library
Clear-Host
# Point to the makemkvcon.exe (https://www.makemkv.com/download/)
Set-Alias makemkv "C:\Program Files (x86)\MakeMKV\makemkvcon.exe"
# Point to the HandBrakeCLI.exe (https://handbrake.fr/downloads2.php)
Set-Alias handbrake "C:\Program Files\Handbrake\HandBrakeCLI.exe"
# Define where your Plex library is (final resting place)
$plex = "\\server\plex\movies"
# Define a temporary directory to store the MKV files in
$dir = "C:\makemkv"
# --------------------------------------------------
$title = Read-Host -Prompt "Enter movie title"
$start = (Get-Date)
"Running MakeMKV process...";
makemkv mkv disc:0 all c:\makemkv
"Finding the largest file..."
$file = Get-ChildItem $dir | Sort-Object Length -Descending | Select-Object -First 1
$baseName = $title #$file.BaseName
$outFile = "$dir\$baseName".ToLower() #-replace ".{4}$"
$outFile = $outFile.Replace("_", " ")
$outFile += ".mp4"
#"Deleting unnecessary files..."
#Get-ChildItem $dir | Where-Object{$_.Name -cne $file.Name} | Where-Object{Remove-Item $_.FullName -WhatIf}
"Running Handbrake process..."
handbrake -i $file.FullName -o $outFile
"Moving file to Plex..."
Move-Item "$outFile" "$plex"
"Cleaning up the directory..."
Get-ChildItem $dir | Remove-Item
$v = [math]::Round(((Get-Date) - $start).TotalMinutes, 2)
"Process complete."
"Total process execution time: $v minutes"
try {
$d = New-Object -ComObject IMAPI2.MsftDiscMaster2
$dr = New-Object -ComObject IMAPI2.MsftDiscRecorder2
$dr.InitializeDiscRecorder($d)
$dr.EjectMedia()
} catch { }
" "
Read-Host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment