sinedie/SRTranslator

Translation timed out

drphero opened this issue · 5 comments

By using -s I can see that DeepL is asking to upgrade to pro in order to translate more that 5,000 characters at once. I thought SRTranslator does the translation in smaller chunks to avoid this problem. Is this a bug?

Hi, sry by the late reply.

Yeah, it does, but it is not 5000, deepl downgrade it to 3000. This should be done in chunks.

Can you show me something to see if it is really a bug? A screenshot could be okay. Ty

Vrejf commented

Hi! I got something very similar. Trying on an srt with about 30k chars.

... Translating chunk. 0 %
... Translating chunk. 9 %
... Translating chunk. 19 %
... Translating chunk. 29 %
2023-02-12 20:23:42.285 Uncaught app exception
...
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/srtranslator/srt_file.py", line 138, in translate
    translation = translator.translate(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/srtranslator/translators/deepl.py", line 125, in translate
raise TimeOutException("Translation timed out")
srtranslator.translators.base.TimeOutException: Translation timed out```
Vrejf commented

Hi again!
In selenium_utils.py the Keys.CONTROL only works on some systems (windows/linux?), so I added this code to make it work on more systems.
It solved the problem for me atleast. Im on MacOS

class TextArea(BaseElement):
    def write(self, value: str) -> None:
        if self.element is None:
            return
        
        # Check OS to use Cmd or Ctrl keys
        cmd_ctrl = Keys.COMMAND if sys.platform == "darwin" else Keys.CONTROL

        actions_handler = ActionChains(self.driver).move_to_element(self.element)
        # Changed key variables:
        actions_handler.click().key_down(cmd_ctrl).send_keys("a").perform()
        actions_handler.send_keys(Keys.CLEAR).key_up(cmd_ctrl).perform()
        actions_handler.send_keys(*value).perform()

Also don't know if chuck size should be 3000 instead of 4500 in srt_files.py?

Hey, ok, first the timeout... It timesout if DeepL takes too long to translate (this is, nothing written, [...] character in result, or different number of sentences in both inputs) see this. Can you show me the browser when it timeout. Use -s flag to see it)

Second, ty for catching this, gonna update it tonight for mac users

Last, yeah it is okay, it is just the default value, it really doesn't matter to much. the real value is the one in the translator.

Vrejf commented

Using the code that I added I no longer have problems with timeout. Thank you!