[Request] Automatic title scanning

Everything related to MakeMKV
Post Reply
mikee
Posts: 1
Joined: Mon Mar 04, 2019 7:07 am

[Request] Automatic title scanning

Post by mikee »

I've noticed that when MakeMKV starts up it will automatically scans the disc to show the list of titles.

Can the same be enabled when MakeMKV is already running and a new disc is inserted?
It's already detecting the new drive and presents the huge button, I'm asking for that button to press itself.

Not sure if this is a feature request or it's already possible.
Woodstock
Posts: 10864
Joined: Sun Jul 24, 2011 11:21 pm

Re: [Request] Automatic title scanning

Post by Woodstock »

I've noticed that when MakeMKV starts up it will automatically scans the disc to show the list of titles.
It does? Not that I've seen.

Starting MakeMKV with a disk inserted, the disk gets scanned enough to display its information in the Info window, but I still have to click the Open button to get the directory read.

If no disk is inserted when it is started, inserting a disk takes me to the same screen, and I have to click the Open button to get the directory.
WoofGrrrr
Posts: 5
Joined: Tue Mar 31, 2020 4:01 pm
Location: Vermont, USA

Re: [Request] Automatic title scanning

Post by WoofGrrrr »

One more vote for this. It would speed up ripping disks for me.

When I pop a disk in, I typically get involved with something else and fail to notice when the disk is loaded. The app just sits there, waiting for me to click the Open button.

At the very least, if there could be a reminder, like when initial loading is complete, it would help a bit.
eonmc2
Posts: 2
Joined: Tue Jan 12, 2021 7:33 pm

Re: [Request] Automatic title scanning

Post by eonmc2 »

Any update on this? It would be great if MakeMKV could auto-scan and go straight to the title selection automatically.

In the meantime, I put together a PowerShell script as a workaround. It relies on forcing window focus and sending keystrokes, so it might be a bit clunky/unstable, but it gets the job done for now.

Code: Select all

# MakeMKV_AutoScan.ps1
# Monitors the optical drive and automatically initiates the disc scan in MakeMKV.

param(
    [string]$DriveLetter = "D",
    [string]$MakeMKVPath = "C:\Program Files (x86)\MakeMKV\makemkv.exe",
    [int]$WaitSeconds = 5,
    [int]$PollSeconds = 3
)

$CleanDrive = $DriveLetter.Substring(0,1).ToUpper()
$root = "${CleanDrive}:\"
$hasRunForLabel = $null

Add-Type @"
using System;
using System.Runtime.InteropServices;
public class WinAPI {
    [DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
    [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd);
    [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
    [DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
    [DllImport("user32.dll")] public static extern bool AttachThreadInput(uint idAttach, uint idAttachTo, bool fAttach);
    [DllImport("kernel32.dll")] public static extern uint GetCurrentThreadId();
}
"@

function Force-Focus([IntPtr]$hWnd) {
    if ($hWnd -eq [IntPtr]::Zero) { return $false }
    
    [WinAPI]::ShowWindowAsync($hWnd, 9) | Out-Null
    [WinAPI]::SetForegroundWindow($hWnd) | Out-Null
    
    $remoteThreadId = [WinAPI]::GetWindowThreadProcessId($hWnd, [IntPtr]::Zero)
    $currentThreadId = [WinAPI]::GetCurrentThreadId()
    
    if ($remoteThreadId -ne $currentThreadId) {
        [WinAPI]::AttachThreadInput($currentThreadId, $remoteThreadId, $true) | Out-Null
        [WinAPI]::SetForegroundWindow($hWnd) | Out-Null
        [WinAPI]::AttachThreadInput($currentThreadId, $remoteThreadId, $false) | Out-Null
    }
    
    return ([WinAPI]::GetForegroundWindow() -eq $hWnd)
}

Write-Host "=== MakeMKV Auto-Scan Monitor ===" -ForegroundColor Cyan
Write-Host "Watching drive $CleanDrive for new discs..." -ForegroundColor Gray

while ($true) {
    try {
        $di = New-Object System.IO.DriveInfo($root)
        
        if ($di.IsReady) {
            $label = $di.VolumeLabel
            if (-not $label) { $label = "__NO_LABEL__" }

            if ($hasRunForLabel -ne $label) {
                Write-Host "$(Get-Date -Format 'HH:mm:ss') -> New disc detected: $label" -ForegroundColor Green
                $hasRunForLabel = $label
                
                $proc = Get-Process makemkv* -ErrorAction SilentlyContinue | Select-Object -First 1
                if (-not $proc) {
                    Write-Host "Launching MakeMKV..." -ForegroundColor DarkGray
                    $proc = Start-Process -FilePath $MakeMKVPath -PassThru -WindowStyle Normal
                }
                
                Write-Host "Waiting $WaitSeconds seconds for drive spin-up..." -ForegroundColor DarkGray
                Start-Sleep -Seconds $WaitSeconds
                
                $proc = Get-Process makemkv* -ErrorAction SilentlyContinue | Select-Object -First 1
                if ($proc) {
                    Write-Host "Sending scan command..." -ForegroundColor DarkGray
                    if (Force-Focus $proc.MainWindowHandle) {
                        Start-Sleep -Milliseconds 500
                        $wshell = New-Object -ComObject WScript.Shell
                        
                        $wshell.SendKeys("%f")
                        Start-Sleep -Milliseconds 400
                        $wshell.SendKeys("{DOWN}")
                        Start-Sleep -Milliseconds 100
                        $wshell.SendKeys("{DOWN}")
                        Start-Sleep -Milliseconds 100
                        $wshell.SendKeys("{RIGHT}")
                        Start-Sleep -Milliseconds 300
                        $wshell.SendKeys("{ENTER}")
                        
                        Write-Host "Scan initiated." -ForegroundColor Green
                    } else {
                        Write-Host "Failed to gain window focus." -ForegroundColor Red
                    }
                }
            }
        } else {
            if ($hasRunForLabel -ne $null) {
                Write-Host "$(Get-Date -Format 'HH:mm:ss') -> Disc removed." -ForegroundColor DarkGray
            }
            $hasRunForLabel = $null
        }
    } catch { }
    
    Start-Sleep -Seconds $PollSeconds
}
Post Reply