crow-translate / QOnlineTranslator

A library for Qt5 that provides free usage of Google, Yandex and Bing translate API.
GNU General Public License v3.0
79 stars 12 forks source link

Parse Google Translate directly instead of using the public API #17

Open ghost opened 2 years ago

ghost commented 2 years ago

Describe the problem or limitation you are having The public Google Translate API is too restrictive, and returns "Too many requests" even after a few requests.

Describe the solution you'd like Parse the website instead of using the public API.

Describe alternatives you've considered Switching the translation engine. Not the best solution for some languages, which translate best in Google Translate

Additional context QTranslate is most likely doing this, since the error "Too many requests" never occurs there.

Shatur commented 2 years ago

I think we could do even better - look what kind of requests Google Translate website sends. This is how Bing API works.

ghost commented 2 years ago

I've found this: https://pythonrepo.com/repo/ssut-py-googletrans-python-third-party-apis-wrappers Perhaps it can be helpful. It says:

You may wonder why this library works properly, whereas other approaches such like goslate won't work since Google has updated its translation service recently with a ticket mechanism to prevent a lot of crawler programs.

I eventually figure out a way to generate a ticket by reverse engineering on the obfuscated and minified code used by Google to generate such token, and implemented on the top of Python. However, this could be blocked at any time.

If necessary I could probably write a JS parser as well (I know JS, some Nodejs and Electron).

Shatur commented 2 years ago

I've found this:

Thanks, it's a nice reference! But for now I running out of time, so PR's are welcome here.

If necessary I could probably write a JS parser as well (I know JS, some Nodejs and Electron).

Unfortunately, we need a C++ programmer or wait until I have more free time :)

VolkMilit commented 2 years ago

This python program use the API, if I'm not mistaken: https://github.com/ssut/py-googletrans/blob/master/googletrans/gtoken.py#L13

Yeep: https://github.com/ssut/py-googletrans/blob/master/googletrans/client.py#L26

ghost commented 2 years ago

@Shatur could you provide an option for a terminal command for Google Translate. So everyone could write their own parser / find an API and simply return that with a command line tool. For example, you could just outline in which format the data should be returned, so users can write their parsers in any language, or use any translator or dictionary they want (potentially).

Shatur commented 2 years ago

could you provide an option for a terminal command for Google Translate. So everyone could write their own parser / find an API and simply return that with a command line tool.

Not sure if I understand you correctly, but looks like you describing curl / wget.

ghost commented 2 years ago

I had originally in mind something like a user-defined command line, for example:

translatetext "text from translator"

So the user could create their own command-line tool (with the name translatetext in this case) and return data after executing it. I guess it could be something else, like curl / wget. Anything that can work to return data after executing the command in terminal.

Edit: nevermind, I realized I can just change the URL in the source code and rebuild if I really need it. Hopefully Yandex TTS starts working, since Yandex seems to be probably as good as Google in translating. And maybe I can find someone who could code in C++ and help here.

Shatur commented 2 years ago

Oh, I get it now! It would be better if translators were built in for a better user experience. I would rather improve the support for Google Translate, which all users will benefit from, than support an additional parsing format that people will implement themselves.

ghost commented 6 months ago

@Shatur does qonlinetranslator use google translate's mobile stuff which yields worse translation?

Shatur commented 6 months ago

It uses deskop API, but uses mobile user agent in order to bypass google checks.

ghost commented 6 months ago

@Shatur I'm using crow for subtitle translation, so I wondered if the google engine you implemented brings an error or a limitation, temporary ban depending on the usage. When I checked this repo, I didn't see anyone who encountered such an error, maybe something like this was reported in crow's own repo or maybe they reported it directly to you via e-mail.

Shatur commented 6 months ago

Unfortunately, it's a common problem. People just reported it to the app repo: https://github.com/crow-translate/crow-translate I afraid that the only workaround is to switch translation engine.

ghost commented 6 months ago

@Shatur mpv script uses this command, I wonder do I have to delete the -e to make crow auto switch the engine when it get error on google engine or would it switch automatically?


    local args = {
            'crow',
            '-l', from,
            '-t', to,
            '-e', 'google',
            '-b', escaped
        }
,,,
Shatur commented 6 months ago

Unfortunately, no, there is no such feature :(