-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
53 lines (45 loc) · 1.24 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "stdafx.h"
#include "Window.h"
#include "Clipboard.h"
int WINAPI _tWinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
MSG msg = { 0 };
Window window(hInstance);
// Bind the hotkey handler
window.SetHotkeyHandler([](){
tregex youtube_regex(_T("^(https?\\:\\/\\/)?(www\\.)?youtube\\.com\\/watch\\?v\\=[A-Za-z0-9_-]{11}"));
tstring potential_video_id = Clipboard::GetText();
if (std::regex_search(potential_video_id, youtube_regex))
{
PROCESS_INFORMATION proc_info = { 0 };
STARTUPINFO proc_startup_info = { 0 };
proc_startup_info.cb = sizeof(proc_startup_info);
// Execute ytdl.py under windowless python
tstring cmdline = _T("pythonw ytdl.py ") + potential_video_id;
if (CreateProcess(NULL, &cmdline[0], NULL, NULL, FALSE, 0, NULL, NULL, &proc_startup_info, &proc_info))
{
CloseHandle(proc_info.hProcess);
CloseHandle(proc_info.hThread);
}
}
});
while (true)
{
WaitMessage();
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}