oltodosel / interSubs

Interactive subtitles for mpv. Instantly translate selected word/sentence.
MIT License
225 stars 20 forks source link

pronunciation of a word not working #18

Closed lacygoill closed 5 years ago

lacygoill commented 5 years ago

Hello,

According to the README page, one can press the right-click button of a mouse while the cursor is over a word to hear its pronunciation.

Right-click on the word to hear its pronunciation.

At the moment, it doesn't seem to work on my machine; here's the output of mpv when I press the button:

Traceback (most recent call last):1%) A-V:  0.000
  File "/home/user/.config/mpv/scripts/interSubs.py", line 1286, in mousePressEvent
    exec('self.%s(event)' % mouse_action[2])
  File "<string>", line 1, in <module>
  File "/home/user/.config/mpv/scripts/interSubs.py", line 1302, in f_listen
    listen(self.word, config.listen_via)
  File "/home/user/.config/mpv/scripts/interSubs.py", line 675, in listen
    gTTS(text = word, lang = config.lang_from, slow = False).save('/tmp/gtts_word.mp3')
  File "/home/user/.config/mpv/scripts/interSubs.py", line 878, in save
    self.write_to_fp(f)
  File "/home/user/.config/mpv/scripts/interSubs.py", line 891, in write_to_fp
    'tk' : self.token.calculate_token(part)}
  File "/home/user/.config/mpv/scripts/interSubs.py", line 719, in calculate_token
    seed = self._get_token_key()
  File "/home/user/.config/mpv/scripts/interSubs.py", line 752, in _get_token_key
    tkk_expr = re.search(".*?(TKK=.*?;)W.*?", line).group(1)
AttributeError: 'NoneType' object has no attribute 'group'
AV: 00:01:17 / 01:52:31 (1%) A-V:  0.000

The issue seems to be in the function _get_token_key() in interSubs.py:

https://github.com/oltodosel/interSubs/blob/08ffbcff174569f6da9d0b2bea2bdfa09ec20c7a/interSubs.py#L752

I think that the output of re.search() is None, so .group(1) refers to a non-existing capturing group.

I can reproduce the issue in a python interpreter:

$ python3
>>> import re,requests
>>> response = requests.get("https://translate.google.com/")
>>> line = response.text.split('\n')[-1]
>>> tkk_expr = re.search(".*?(TKK=.*?;)W.*?", line).group(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'

I don't know whether the issue is in the code, or is due to my internet connection (my AS seems blacklisted by some websites); I can access https://translate.google.com without any issue.


Here are some information about my system:


Thank you very much for your plugin.

oltodosel commented 5 years ago

gtts and pons seem to have stopped working. I'll look into it on a later date. Set in config listen_via = 'forvo' - it still works.

lacygoill commented 5 years ago

Indeed, setting listen_via to 'forvo' in interSubs_config.py fixes the issue. Thank you for the solution.

oltodosel commented 5 years ago

gtts/pons pronunciation fixed.