好友
阅读权限10
听众
最后登录1970-1-1
|
在前人的基础上改动和增加了部分代码以支持有道翻译api
主要增加了下述代码
[Asm] 纯文本查看 复制代码 /*
生成uuid
*/
string generateUUID() {
string randomStr = "" + HostGetTickCount();
string md5Hash = HostHashMD5(randomStr); // 生成 MD5
// 格式化为类似 UUID 的样式
return md5Hash.substr(0, 8) + "-" + md5Hash.substr(8, 4) + "-" + md5Hash.substr(12, 4) + "-" + md5Hash.substr(16, 4) + "-" + md5Hash.substr(20, 12);
}
int daysInMonth(int year, int month) {
if (month == 2) {
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0) ? 29 : 28;
} else if (month == 4 || month == 6 || month == 9 || month == 11) return 30;
else return 31;
}
/*
获取当前时间戳(1748530654, 10位)
*/
string getCurtime() {
datetime now;
int year = now.get_year();
int totalDays = 0;
for (int y = 1970; y < year; y++) {
totalDays += (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0) ? 366 : 365;
}
int month = now.get_month();
for (int m = 1; m < month; m++) {
totalDays += daysInMonth(year, m);
}
int day = now.get_day();
totalDays += day - 1;
int hour = now.get_hour();
int minute = now.get_minute();
int second = now.get_second();
int totalSeconds = totalDays * 86400 + hour * 3600 + minute * 60 + second;
string output_ = year + "-" + month + "-" + day + "-" + hour + "-" + minute + "-" + second;
// return year + "-" + month + "-" + day + "-" + hour + "-" + minute + "-" + second;
return "" + totalSeconds;
}
/*
用于生成sha256
*/
string getInput(const string &in input) {
if (input.empty()) {
return input;
}
uint inputLen = input.length();
if (inputLen <= 20) {
return input;
} else {
string prefix = input.substr(0, 10);
string suffix = input.substr(inputLen - 10, 10);
return prefix + "" + inputLen + suffix;
}
}
/*
生成sha256
*/
string getSha256(const string &in str) {
string hashResult = HostHashSHA256(str);
return hashResult;
}
/*
解析翻译结果
*/
string JsonParseNew(string json) {
JsonReader Reader;
JsonValue Root;
string ret = "";
if (Reader.parse(json, Root) && Root.isObject()) {
// JsonValue data = Root["data"];
// if (data.isObject()) {
JsonValue translations = Root["translation"];
if (translations.isArray()) {
for (int j = 0, len = translations.size(); j < len; j++) {
JsonValue value1 = translations[j];
ret = ret + value1.asString();
}
}
// }
if (Root["errorCode"].asString() != "0") ret = "errorCode:" + Root["errorCode"].asString();
}
return ret;
}
相关使用教程都在我的github或gitee中已说明
github: https://github.com/lp20010415/PotPlayer_Subtitle_Translate_Youdao
gitee: https://gitee.com/lp20010415/PotPlayer_Subtitle_Translate_Youdao
特别感谢前人!感恩!
前人本论坛链接: https://www.52pojie.cn/forum.php?mod=viewthread&tid=836477&highlight=PotPlayer%B2%A5%B7%C5%C6%F7%D4%DA%CF%DF%D7%D6%C4%BB%B7%AD%D2%EB |
免费评分
-
查看全部评分
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|
|