gunesmes / translate-subtitles

CLI and package for flawless translation. Transitle is a AI-based subtitle translator. It allows you to translate subtitles in a directory flawlessly with your favorite translator. Translate bunch of subtitlesfrom original language to desired language. This gives you a AI-based translated subtitle.
https://pypi.org/project/transitle/
GNU General Public License v3.0
46 stars 13 forks source link

Problem when translating a subtitle #3

Closed Tizioincognit0 closed 4 years ago

Tizioincognit0 commented 4 years ago

When i’m trying to translate a subtitle file (for example “still-alice”), I’m getting the following errors. sh-3.2# python run.py /Applications/SRT\ Translator/subtitle_translator 50 google pl it 00:00:47,140 --> 00:00:49,270 Traceback (most recent call last): File "run.py", line 70, in <module> translater(sys.argv[1:]) File "run.py", line 66, in translater s.translate_substitle(subFile, source_language, target_language, translator, max_length) File "src/subTranslater.py", line 219, in translate_substitle translated_sub = self.send_google_translator(prepared_sub, source_language, target_language) File "src/subTranslater.py", line 93, in send_google_translator return gs.translate(prepared_sub, target_language, source_language) File "src/goslate.py", line 338, in translate return self._translate_single_text(text, target_language, source_language) File "src/goslate.py", line 283, in _translate_single_text return ''.join(self._execute(make_task(i) for i in split_text(text))) File "src/goslate.py", line 166, in _execute yield each() File "src/goslate.py", line 281, in <lambda> return lambda: self._basic_translate(text, target_language, source_lauguage)[0] File "src/goslate.py", line 208, in _basic_translate translation = u''.join(i['trans'] for i in data['sentences']) TypeError: string indices must be integers At the end, is generated a srt file called “still-alice_pl_to_it.srt” which contains only a blank line with the timing of the first line of “still-alice.srt” which I attached to this issue. I'm using subtitle_translator on macOS Mojave 10.14.6. still-alice_pl_to_it.srt.zip

gunesmes commented 4 years ago

Unfortunately, this is throwing because Google changed the services it returns something different also they added security checks for IP blocking. There should be a smart workaround in google translate requests. I fixed this and added some time.sleep(random.random()) to simulate browser. If your ip is blocked by Google you can reconnect to the network.