Skip to content

Commit

Permalink
Merge pull request #8 from gnh1201/main
Browse files Browse the repository at this point in the history
Apply all revisions (2024-12-11)
  • Loading branch information
gnh1201 authored Dec 10, 2024
2 parents e6b1dfd + f6591de commit ae30341
Showing 1 changed file with 55 additions and 4 deletions.
59 changes: 55 additions & 4 deletions SubtitleTranslate - lingva.as
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
real time subtitle translate for PotPlayer using Lingva (Google alternative front-end) API
*/

Expand Down Expand Up @@ -27,6 +27,7 @@ string JsonParseV1(string json)
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;
Expand Down Expand Up @@ -145,6 +146,7 @@ array<string> LangTable =

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$}";
Expand All @@ -157,7 +159,7 @@ string GetVersion()

string GetDesc()
{
return "https://github.com/thedaviddelta/lingva-translate";
return "https://github.com/gnh1201/potplayer-lingva";
}

string GetLoginTitle()
Expand All @@ -184,8 +186,51 @@ string server_url;

string ServerLogin(string User, string Pass)
{
HostOpenConsole(); // for debug

string text;
int start_pos;
server_url = User;
if (server_url.empty()) server_url = "https://lingva.ml";
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";
}

Expand Down Expand Up @@ -213,13 +258,19 @@ 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)
{
Expand Down

0 comments on commit ae30341

Please sign in to comment.