Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working #1

Open
gfernandop opened this issue Mar 4, 2017 · 2 comments
Open

Not working #1

gfernandop opened this issue Mar 4, 2017 · 2 comments

Comments

@gfernandop
Copy link

gfernandop commented Mar 4, 2017

Hello nopium,

Congratulations for your idea!!!
It is a wonderful plugin however it is not working anymore...
I would appreciate too much if you help me to put it working again.
I was trying to use the extension aiming to improve my english skills translating some excerpts of the subtitles from english to portuguese when needed.
When I try to activate the plugin I receive a message tolding that the file doesn't exist:

"Could not load subtitles :(
Make sure you have here appears the filename"

Could you help me to use your extension?

Thank you very much

@vdroznik
Copy link

It won't work because of this: https://trac.videolan.org/vlc/ticket/8097

@Nickyg001
Copy link

Sorry but if the script doesn't work because there are no API permissions for google translate, how does the script below for POTPLAYER work very well??
Post the script maybe you can understand and improve the script for VLC and make the translation API work.

/////////////////////////////////////////////////////////////////////*
real time subtitle translate for PotPlayer using google 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 GetSrcLangs() -> get source language
// array GetDstLangs() -> get target language
// string Translate(string Text, string &in SrcLang, string &in DstLang) -> do translate !!

string JsonParseOld(string json)
{
JsonReader Reader;
JsonValue Root;
string ret = "";

if (Reader.parse(json, Root) && Root.isArray())
{
	for (int i = 0, len = Root.size(); i < len; i++)
	{
		JsonValue child1 = Root[i];
		
		if (child1.isArray())
		{
			for (int j = 0, len = child1.size(); j < len; j++)
			{		
				JsonValue child2 = child1[j];
				
				if (child2.isArray())
				{
					JsonValue item = child2[0];
			
					if (!ret.empty()) ret = ret + "\n";
					if (item.isString()) ret = ret + item.asString();
				}
			}
			break;
		}
	}
} 
return ret;

}

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 = data["translations"];
		
		if (translations.isArray())
		{
			for (int j = 0, len = translations.size(); j < len; j++)
			{		
				JsonValue child1 = translations[j];
				
				if (child1.isObject())
				{
					JsonValue translatedText = child1["translatedText"];
			
					if (!ret.empty()) ret = ret + "\n";
					if (translatedText.isString()) ret = ret + translatedText.asString();
				}
			}
		}
	}
} 
return ret;

}

array 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=Google 翻譯$}{$CP0=Google translate$}";
}

string GetVersion()
{
return "1";
}

string GetDesc()
{
return "https://translate.google.com/";
}

string GetLoginTitle()
{
return "Input google API key";
}

string GetLoginDesc()
{
return "Input google API key";
}

string GetUserText()
{
return "API key:";
}

string GetPasswordText()
{
return "";
}

string api_key;

string ServerLogin(string User, string Pass)
{
api_key = User;
if (api_key.empty()) return "fail";
return "200 ok";
}

void ServerLogout()
{
api_key = "";
}

array GetSrcLangs()
{
array ret = LangTable;

ret.insertAt(0, ""); // empty is auto
return ret;

}

array GetDstLangs()
{
array ret = LangTable;

return ret;

}

string Translate(string Text, string &in SrcLang, string &in DstLang)
{
//HostOpenConsole(); // for debug

if (SrcLang.length() <= 0) SrcLang = "auto";
SrcLang.MakeLower();

string enc = HostUrlEncode(Text);

// by new API
if (api_key.length() > 0)
{
string url = "https://translation.googleapis.com/language/translate/v2?target=" + DstLang + "&q=" + enc;
if (!SrcLang.empty() && SrcLang != "auto") url = url + "&source=" + SrcLang;
url = url + "&key=" + api_key;
string text = HostUrlGetString(url, UserAgent);
string ret = JsonParseNew(text);
if (ret.length() > 0)
{
SrcLang = "UTF8";
DstLang = "UTF8";
return ret;
}
}

// by old API
string url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" + SrcLang + "&tl=" + DstLang + "&dt=t&q=" + enc;
string text = HostUrlGetString(url, UserAgent);
string ret = JsonParseOld(text);
if (ret.length() > 0)
{
SrcLang = "UTF8";
DstLang = "UTF8";
return ret;
}

return ret;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants