Powershell script to auto rip discs to iso using native MakeMKV

Discussion of advanced MakeMKV functionality, expert mode, conversion profiles
Post Reply
Bruhz
Posts: 1
Joined: Wed Mar 27, 2024 10:27 pm

Powershell script to auto rip discs to iso using native MakeMKV

Post by Bruhz »

Code: Select all

while ($true) {
    $initialLabel = ""
    # Initially set $currentLabel to the current volume label
    $currentLabel = (Get-Volume | Where-Object {$_.DriveLetter -eq "E"}).FileSystemLabel

    # Wait for the volume label to change from its initial value
    while ($currentLabel -eq $initialLabel) {
        Write-Host "Waiting for volume label to change..."
        Start-Sleep -Seconds 5 # Wait for 5 seconds before checking again
        $currentLabel = (Get-Volume | Where-Object {$_.DriveLetter -eq "E"}).FileSystemLabel
    }

    # Proceed with backup once the volume label changes
    $driveInfo = Get-Volume | Where-Object {$_.DriveLetter -eq "E"}
    $volLabel = $driveInfo.FileSystemLabel

    $targetDir = "C:\Discs\$volLabel"
    if (-not (Test-Path $targetDir)) {
        New-Item -ItemType Directory -Path $targetDir
    }

    $makemkvPath = "C:\Program Files (x86)\MakeMKV\makemkvcon64.exe"
    $command = "& `"$makemkvPath`" backup --decrypt --progress=-stdout --messages=-stdout --noscan -r --progress=-same disc:0 `"$targetDir.iso`""

    Invoke-Expression $command
    Write-Host "Backup completed for $targetDir | $volLabel"

    # Eject the CD/DVD-ROM
    $ejectCommand = "(New-Object -comObject Shell.Application).Namespace(17).ParseName('E:').InvokeVerb('Eject')"
    Invoke-Expression $ejectCommand

    # Wait for a moment before starting the loop again to ensure the disc is ejected
    Start-Sleep -Seconds 10
    Write-Host "Ready for the next disc..."
}
Nobody had much in terms of, how to rip to an ISO. How to backup the full drive, etc for command line, which the help and info sheet is kinda a mess. So, here is my current script. Dissect and mutilate as necessary. This is just what I made. Next step, to auto acquire the disc:number from the drive letter

Second one, with number appending for keeping track, auto naming of drive letters and numbers. Auto MKV Creation and ISO creation and manages audio discs

Code: Select all

$makemkvPath = "C:\Program Files (x86)\MakeMKV\makemkvcon64.exe"
$anyburnPath = "C:\Program Files\AnyBurn\abcmd.exe"
$initialLabel = ""
$drvltr = "D"
#$rootDir = "D:\ISO"
$rootDir = "R:\ISO"

$highestNumber = (Get-ChildItem $rootDir -File | Where-Object Name -match 'chk(\d+)$' | Foreach-Object {[int]$matches[1]} | Measure-Object -Maximum).Maximum
$appendme = '{0:D3}' -f ($highestNumber + 1)


$command3 = "& `"$makemkvPath`" -r --cache=1 info disc:9999"
$output = Invoke-Expression $command3

$lines = $output -split "`r?`n"
$drvnum = $lines | Where-Object {$_ -match '^DRV:(\d+),\d+,\d+,\d+,"[^"]*","[^"]*","([^"]*)"$' -and $matches[2] -eq $drvltr} | ForEach-Object {$matches[1]}


while ($true) {
    do {
        Write-Host "Waiting for volume label to change for disc #$appendme..."
        Start-Sleep -Seconds 5
        $currentLabel = (Get-Volume | Where-Object {$_.DriveLetter -eq "$drvltr"}).FileSystemLabel
    } while ($currentLabel -eq $initialLabel)

    $targetDir = "$rootDir\$currentLabel.$appendme"
    New-Item -ItemType Directory -Path $targetDir -Force

    $driveInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID = 'E:'"
    Write-Host "Write the number $appendme on this disk"
    if ($driveInfo.FileSystem -eq "CDFS") {
        $command2 = "& `"$anyburnPath`" make-image `"$drvltr`:`" -o `"$targetDir.bin`""
        Invoke-Expression $command2
    } else {
        $command1a = "& `"$makemkvPath`" backup --decrypt --noscan -r disc:$drvnum `"$targetDir.iso`""
        Invoke-Expression $command1a
        $command1b = "& `"$makemkvPath`" mkv --minlength=1200 iso:`"$targetDir.iso`" all `"$targetDir`""
        Invoke-Expression $command1b
    }

   
    Write-Host "Backup completed for Disc #$appendme in $targetDir | $currentLabel"

    $ejectCommand = "(New-Object -comObject Shell.Application).Namespace(17).ParseName(`"$drvltr`:`").InvokeVerb('Eject')"
    Invoke-Expression $ejectCommand
    Start-Sleep -Seconds 10
    Write-Host "Ready for the next disc..."
}
Post Reply