-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplayinmpv.cpp
164 lines (148 loc) · 4.95 KB
/
playinmpv.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// playinmpv.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include <Windows.h>
#include <stdlib.h>
#include <string>
#include <assert.h>
#include <locale>
using namespace std;
unsigned char ToHex(unsigned char x)
{
return x > 9 ? x + 55 : x + 48;
}
unsigned char FromHex(unsigned char x)
{
unsigned char y;
if (x >= 'A' && x <= 'Z') y = x - 'A' + 10;
else if (x >= 'a' && x <= 'z') y = x - 'a' + 10;
else if (x >= '0' && x <= '9') y = x - '0';
else assert(0);
return y;
}
std::string UrlEncode(const std::string& str)
{
std::string strTemp = "";
size_t length = str.length();
for (size_t i = 0; i < length; i++)
{
if (isalnum((unsigned char)str[i]) ||
(str[i] == '-') ||
(str[i] == '_') ||
(str[i] == '.') ||
(str[i] == '~'))
strTemp += str[i];
else if (str[i] == ' ')
strTemp += "+";
else
{
strTemp += '%';
strTemp += ToHex((unsigned char)str[i] >> 4);
strTemp += ToHex((unsigned char)str[i] % 16);
}
}
return strTemp;
}
std::string UrlDecode(const std::string& str)
{
std::string strTemp = "";
size_t length = str.length();
for (size_t i = 0; i < length; i++)
{
if (str[i] == '+') strTemp += ' ';
else if (str[i] == '%')
{
assert(i + 2 < length);
unsigned char high = FromHex((unsigned char)str[++i]);
unsigned char low = FromHex((unsigned char)str[++i]);
strTemp += high * 16 + low;
}
else strTemp += str[i];
}
return strTemp;
}
std::string GetMpvPlayerPathFromRegistry()
{
HKEY hKey;
LPCWSTR subKey = L"mpv\\DefaultIcon";
std::wstring valueBuffer(MAX_PATH, '\0');
DWORD bufferSize = MAX_PATH;
if (RegOpenKeyExW(HKEY_CLASSES_ROOT, subKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
{
// Read the default value from the subkey
RegQueryValueExW(hKey, NULL, NULL, NULL, reinterpret_cast<LPBYTE>(&valueBuffer[0]), &bufferSize);
RegCloseKey(hKey);
// Extract the path from the value
std::wstring value = valueBuffer.substr(0, valueBuffer.find_first_of(L','));
return std::wstring_convert<std::codecvt<wchar_t, char, std::mbstate_t>>{}.to_bytes(value);
}
return "";
}
int main(int argc, char* argv[])
{
std::string mpvPlayerPath = GetMpvPlayerPathFromRegistry();
string cmd;
if (argc < 2)
{
std::cout << "can't get value" << endl;
Sleep(1000 * 10);
}
else {
cmd = argv[1];
std::cout << "输入url:" << endl;
std::cout << cmd <<endl;
}
cmd = cmd.substr(6);
cmd = UrlDecode(cmd);
/*
string url_1 = "upos-hz-mirrorakam.akamaized.net", url_2 = "upos-sz-mirrorks3c.bilivideo.com";
if (cmd.find(url_1)!=string::npos) {
cmd = cmd.replace(cmd.find(url_1), url_1.length(), url_2);
std::cout << "港澳台视频cdn替换为:upos-sz-mirrorks3c.bilivideo.com" << endl;
}
if (cmd.find(url_1) != string::npos) {
cmd = cmd.replace(cmd.find(url_1), url_1.length(), url_2);
std::cout << "港澳台音频cdn替换为:upos-sz-mirrorks3c.bilivideo.com" << endl;
}
*/
char* char_url;
_get_pgmptr(&char_url);
string str_url = char_url;
string str_url0 = str_url.substr(0, 3);
string str_url1 = str_url.substr(3,str_url.length()-17);
/*
cmd = str_url0 + "\"" + str_url1 + "\\\"mpv " + cmd;
const char* cstr = cmd.c_str();
const std::string& mpvCmd = mpvPlayerPath + " " + cmd; //add
const char* cstr = mpvCmd.c_str(); //add
std::cout << "执行命令:" << endl;
std::cout << cstr << endl;
*/
if (!mpvPlayerPath.empty())
{
cmd = mpvPlayerPath + " " + cmd;
std::cout << "执行命令:" << endl;
std::cout << cmd << endl;
const char* cstr = cmd.c_str();
system(cstr);
}
else
{
cmd = str_url0 + "\"" + str_url1 + "\\\"mpv " + cmd;
std::cout << "未在注册表中找到MPV播放器路径,使用默认方式执行命令:" << endl;
std::cout << cmd << endl;
const char* cstr = cmd.c_str();
system(cstr);
}
Sleep(1000 * 1);
return 0;
}
// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单
// 入门使用技巧:
// 1. 使用解决方案资源管理器窗口添加/管理文件
// 2. 使用团队资源管理器窗口连接到源代码管理
// 3. 使用输出窗口查看生成输出和其他消息
// 4. 使用错误列表窗口查看错误
// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件