if !(InStr(A_AhkPath, "_UIA")) { Run "*UIAccess " A_ScriptFullPath ExitApp } #SingleInstance Persistent A_IconTip := "link2mpv" A_AllowMainWindow := 0 Tray := A_TrayMenu Tray.Delete("&Help") Tray.Delete("&Window Spy") Tray.Delete("&Pause Script") Tray.Delete("1&") ^!+1:: { LINK := A_Clipboard if (RegExMatch(LINK, "^https?://")) { Run "mpv --ytdl-format=(bestvideo[height<=1080][width>=1080]/bestvideo[width<=1080])[format_note!*=HDR]+bestaudio/best " LINK,,, &PID KeyWait "1" StartTime := A_TickCount Quality := "1080" SetTimer CheckMPVWindow.Bind(PID, StartTime, LINK, Quality), 100 if (StrLen(LINK) > 60) { TrayTip "Link: " SubStr(LINK, 1, 60) "..." "`nPID: " PID, "Opening in mpv: (" Quality ")" } else { TrayTip "Link: " LINK "`nPID: " PID, "Opening in mpv: (" Quality ")" } } } ^!+2:: { LINK := A_Clipboard if (RegExMatch(LINK, "^https?://")) { Run "mpv --ytdl-format=bestvideo[format_note!*=HDR]+bestaudio/best " LINK,,, &PID KeyWait "2" StartTime := A_TickCount Quality := "BEST" SetTimer CheckMPVWindow.Bind(PID, StartTime, LINK, Quality), 100 if (StrLen(LINK) > 60) { TrayTip "Link: " SubStr(LINK, 1, 60) "..." "`nPID: " PID, "Opening in mpv: (" Quality ")" } else { TrayTip "Link: " LINK "`nPID: " PID, "Opening in mpv: (" Quality ")" } } } ^!+3:: { LINK := A_Clipboard if (RegExMatch(LINK, "^https?://")) { Run "mpv --ytdl-format=bestaudio " LINK,,, &PID KeyWait "3" StartTime := A_TickCount Quality := "AUDIO" SetTimer CheckMPVWindow.Bind(PID, StartTime, LINK, Quality), 100 if (StrLen(LINK) > 60) { TrayTip "Link: " SubStr(LINK, 1, 60) "..." "`nPID: " PID, "Opening in mpv: (" Quality ")" } else { TrayTip "Link: " LINK "`nPID: " PID, "Opening in mpv: (" Quality ")" } } } CheckMPVWindow(PID, StartTime, LINK, Quality) { if (WinExist("ahk_pid" PID)) { WinActivate "ahk_pid" PID SetTimer , 0 } else if (A_TickCount >= StartTime + 40000) { ProcessClose PID SetTimer , 0 if (StrLen(LINK) > 60) { TrayTip "Link: " SubStr(LINK, 1, 60) "..." "`nPID: " PID, "Opening in mpv: (" Quality ") [FAILED]", "Iconx" } else { TrayTip "Link: " LINK "`nPID: " PID, "Opening in mpv: (" Quality ") [FAILED]", "Iconx" } } }