-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] Google changed once more the response format [playground] testi…
…ng batchexecute
- Loading branch information
1 parent
2a1291c
commit d5f0357
Showing
5 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# heavily inspired by ssut/googletrans and https://kovatch.medium.com/deciphering-google-batchexecute-74991e4e446c | ||
|
||
import json | ||
|
||
src = "" | ||
data = "" | ||
resp = "" | ||
|
||
post_data = json.dumps([[ | ||
[ | ||
'MkEWBc', | ||
json.dumps([["text", "src", "destination", True],[None]], separators=(',', ':')), | ||
None, | ||
'generic', | ||
], | ||
]], separators=(',', ':')) | ||
|
||
|
||
# broken json parsing | ||
for line in data.split('\n'): | ||
token_found = token_found or '"MkEWBc"' in line[:30] | ||
if not token_found: | ||
continue | ||
|
||
opened_square_bracket = 0 | ||
closed_square_bracket = 0 | ||
|
||
is_in_string = False | ||
for index, char in enumerate(line): | ||
if char == '\"' and line[max(0, index - 1)] != '\\': | ||
is_in_string = not is_in_string # flip the bool value | ||
if not is_in_string: | ||
if char == '[': | ||
opened_square_bracket += 1 | ||
elif char == ']': | ||
closed_square_bracket += 1 | ||
|
||
resp += line | ||
if opened_square_bracket == closed_square_bracket: | ||
break | ||
|
||
# retrieving the info | ||
|
||
parsed = json.loads(json.loads(resp)[0][2]) | ||
translated = (' ' if parsed[1][0][0][3] else '').join([part[0] for part in parsed[1][0][0][5]]) | ||
|
||
if src == 'auto': | ||
try: | ||
src = parsed[2] | ||
except: pass | ||
|
||
if src == 'auto': | ||
try: | ||
src = parsed[0][2] | ||
except: pass | ||
|
||
origin_pronunciation = None | ||
try: | ||
origin_pronunciation = parsed[0][0] | ||
except: pass | ||
|
||
pronunciation = None | ||
try: | ||
pronunciation = parsed[1][0][0][1] | ||
except: pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,13 @@ | |
setup( | ||
name = "translatepy", | ||
packages = ["translatepy"], | ||
version = "1.5.1", | ||
version = "1.5.2", | ||
license = "GNU General Public License v3 (GPLv3)", | ||
description = "Translate, transliterate, get the language of texts in no time with the help of multiple APIs!", | ||
author = "Anime no Sekai", | ||
author_email = "[email protected]", | ||
url = "https://github.com/Animenosekai/translate", | ||
download_url = "https://github.com/Animenosekai/translate/archive/v1.5.1.tar.gz", | ||
download_url = "https://github.com/Animenosekai/translate/archive/v1.5.2.tar.gz", | ||
keywords = ['python', 'translate', 'translation', 'google-translate', 'yandex-translate', 'bing-translate', 'reverso', 'transliteration', 'detect-language'], | ||
install_requires = ['safeIO>=1.2', 'requests', 'beautifulsoup4', 'typing; python_version<"3.5"'], | ||
classifiers = ['Development Status :: 5 - Production/Stable', 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9'], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
__copyright__ = 'Copyright 2021, translate' | ||
__credits__ = ['animenosekai'] | ||
__license__ = 'GNU General Public License v3 (GPLv3)' | ||
__version__ = 'translatepy v1.5.1' | ||
__version__ = 'translatepy v1.5.2' | ||
__maintainer__ = 'Anime no Sekai' | ||
__email__ = '[email protected]' | ||
__status__ = 'Stable' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
""" | ||
translatepy v1.5.1 (Stable) | ||
translatepy v1.5.2 (Stable) | ||
© Anime no Sekai — 2021 | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters