-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
SubtitleTranslate - lingva.as
283 lines (251 loc) · 5.2 KB
/
SubtitleTranslate - lingva.as
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*
real time subtitle translate for PotPlayer using Lingva (Google alternative front-end) API
*/
// void OnInitialize()
// void OnFinalize()
// string GetTitle() -> get title for UI
// string GetVersion -> get version for manage
// string GetDesc() -> get detail information
// string GetLoginTitle() -> get title for login dialog
// string GetLoginDesc() -> get desc for login dialog
// string GetUserText() -> get user text for login dialog
// string GetPasswordText() -> get password text for login dialog
// string ServerLogin(string User, string Pass) -> login
// string ServerLogout() -> logout
//------------------------------------------------------------------------------------------------
// array<string> GetSrcLangs() -> get source language
// array<string> GetDstLangs() -> get target language
// string Translate(string Text, string &in SrcLang, string &in DstLang) -> do translate !!
string JsonParseV1(string json)
{
JsonReader Reader;
JsonValue Root;
string ret = "";
if (Reader.parse(json, Root) && Root.isObject()) {
JsonValue translation = Root["translation"];
if (translation.isString()) ret = translation.asString();
HostPrintUTF8("(f: JsonParseV1) ret: " + ret);// for debug print
}
return ret;
}
array<string> LangTable =
{
"af",
"sq",
"am",
"ar",
"hy",
"az",
"eu",
"be",
"bn",
"bs",
"bg",
"my",
"ca",
"ceb",
"ny",
"zh",
"zh-CN",
"zh-TW",
"co",
"hr",
"cs",
"da",
"nl",
"en",
"eo",
"et",
"tl",
"fi",
"fr",
"fy",
"gl",
"ka",
"de",
"el",
"gu",
"ht",
"ha",
"haw",
"iw",
"hi",
"hmn",
"hu",
"is",
"ig",
"id",
"ga",
"it",
"ja",
"jw",
"kn",
"kk",
"km",
"ko",
"ku",
"ky",
"lo",
"la",
"lv",
"lt",
"lb",
"mk",
"ms",
"mg",
"ml",
"mt",
"mi",
"mr",
"mn",
"my",
"ne",
"no",
"ps",
"fa",
"pl",
"pt",
"pa",
"ro",
"romanji",
"ru",
"sm",
"gd",
"sr",
"st",
"sn",
"sd",
"si",
"sk",
"sl",
"so",
"es",
"su",
"sw",
"sv",
"tg",
"ta",
"te",
"th",
"tr",
"uk",
"ur",
"uz",
"vi",
"cy",
"xh",
"yi",
"yo",
"zu"
};
string UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36";
string GetTitle()
{
return "{$CP949=링바(구글) 번역$}{$CP950=Lingva(Google) 翻譯$}{$CP0=Lingva(Google) translate$}";
}
string GetVersion()
{
return "1";
}
string GetDesc()
{
return "https://github.com/gnh1201/potplayer-lingva";
}
string GetLoginTitle()
{
return "";
}
string GetLoginDesc()
{
return "";
}
string GetUserText()
{
return "Server URL:";
}
string GetPasswordText()
{
return "";
}
string server_url;
string ServerLogin(string User, string Pass)
{
//HostOpenConsole(); // for debug
string text;
int start_pos;
server_url = User;
if (server_url.empty())
{
string[] server_urls = {
"https://translate.catswords.net",
"https://translate.plausibility.cloud",
"https://translate.alxserver.de",
"https://translate.abrendan.dev",
"https://lingva.dialectapp.org",
"https://translate.sphererapids.com",
"https://salucyr69.synology.me:6455",
"https://translater.perfectpurple.top",
"https://translate.palmasolutions.net",
"https://nyc1.lv.ggtyler.dev",
"https://lingva.sharktale.xyz",
"https://translate.gururaja.in",
"https://lingva.steel77.ddnss.de",
"https://translate.mnsr.net",
"https://lingva.privacytools.click",
"https://lingva.adminforge.de",
"https://fanyi.qz.ci",
"https://lingva.seasi.dev",
"https://lingva.lunar.icu",
"https://translate.nexo.moe",
"https://translate.ssnc.uk",
"https://lingva.ml"
};
for (uint i = 0; i < server_urls.length(); i++) {
server_url = server_urls[i];
string text = HostUrlGetString(server_url + "/api/v1/en/ko/hello", UserAgent);
HostPrintUTF8("(f: ServerLogin) url: " + server_url + ", text: " + text); // for debug print
int start_pos = text.findFirst("translation", 0);
if (start_pos > 0) {
return "200 ok";
}
}
}
return "200 ok";
}
void ServerLogout()
{
server_url = "";
}
array<string> GetSrcLangs()
{
array<string> ret = LangTable;
ret.insertAt(0, ""); // empty is auto
return ret;
}
array<string> GetDstLangs()
{
array<string> ret = LangTable;
return ret;
}
string Translate(string Text, string &in SrcLang, string &in DstLang)
{
//HostOpenConsole(); // for debug
SrcLang.replace("zh-CN", "zh");
SrcLang.replace("zh-TW", "zh");
DstLang.replace("zh-CN", "zh");
DstLang.replace("zh-TW", "zh");
if (SrcLang.length() <= 0) SrcLang = "auto";
SrcLang.MakeLower();
string enc = HostUrlEncode(Text);
string url = server_url + "/api/v1/" + SrcLang + "/" + DstLang + "/" + enc;
string text = HostUrlGetString(url, UserAgent);
HostPrintUTF8("(f: Translate) url: " + url + ", text:" + text); // for debug print
string ret = JsonParseV1(text);
if (ret.length() > 0)
{
SrcLang = "UTF8";
DstLang = "UTF8";
return ret;
}
return ret;
}