Feasibilty of addon for live translate chosen words in subtitles while watching
#1
Hi guys,
I wrote this post in the "Add-ons help & support" forum, but I think this is the right forum to put it. I'll appreciate it if one of the moderators will delete the redundant question (http://forum.xbmc.org/showthread.php?tid=206678).

TL;DR: read bold text

I live in a country where English is not the native tongue, but it happens that all the media I watch is (obviously enough) in English.
Most of the times I can't wait for people to translate and release subtitles in my language (it's Hebrew), because many times it can take several days and more (sometimes it's never)..
So, in recent years I'm just watching all the movies with English subtitles which helps a lot in getting the correct spoken words compared to just hearing.

This is all good, but it's a fact that at least 5% of the words in every movie\TV episodes is new to me... some of those words keep repeating in the movie I current watch, and some appear in many movies, but I don't bother to translate them while watching because of time it takes, and it's not very convenient sitting with a mouse and keyboard while watching tv.. and it's especially inconvenient if you don't have a separate monitor for that process. So it happens that many of those words I just skip... I can understand their meaning from the context usually, but knowing the exact translation would be so much better. Also it can be excellent learning experience.

So what I was thinking is an addon that would allow you, during playback, press some button on the remote which will pause the screen and trigger a small (floating) menu with all of the words in the current frame from the subtitle currently in use. it can also view words from previous frame (or should I say previous subtitle line), just in case the user pressed that button 2 seconds late (And in any case it should always allow the user to scroll down the next words and scroll up for previous words). Next to each of those words appears its translation from google translate, or maybe some local dictionary file or something... I really believe this kind of addon would be very much appreciated among people like me , and it will also allow foreigners to learn English better (after all, when you translate a words that you really need to USE [in contrast to just memorizing words with no cause] you have high chances that you'll remember it, and if it appears later again, those chances are just getting higher).

So to my question - is this kind of addon feasible with the XBMC addon framework? Is it considered complicated?
Just want to know if I'm not just spending my time going over the documents for addon development....
Reply
#2
I think it is certainly feasible, especially if the subtitles are in text format, eg SRT. However it would be a bit of work...
If I have helped you or increased your knowledge, click the 'thumbs up' button to give thanks :) (People with less than 20 posts won't see the "thumbs up" button.)
Reply
#3
Interesting idea. Could maybe use Google Translate API.
Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
Reply
#4
Workflow, the addon could:

1 pause
2 bring up a scrolling dialog box with the subtitles in it at current position - they are just text after all. Xbmc must know internally the current subtitle stream and position in it. Query; is this info available to an addon?
3 user scrolls to unknown word and presses ok, Google translate or similar service gives translation, pops up another dialog?
4 must be able to set from and to language on the fly. ''From" defaults to subtitle language, "to" defaults to your locality as defined in xbmc settings.
If I have helped you or increased your knowledge, click the 'thumbs up' button to give thanks :) (People with less than 20 posts won't see the "thumbs up" button.)
Reply
#5
nickr, yup - your workflow sounds right. I, too, would love to know if the info of the subtitle is available to an addon. But even if not all the info is available, the very least that we can work with is the subtitle filename, because we can always parse it to extract subtitle time frames and separate the words with regexp, then just pick the words in the current video playback time. This is intended to be used with SRT only files.

I also think that local dictionary (as compared to online google translate) will be better, so a format for dictionary file (could be just huge JSON file, or XML file), should be determined and presented to the user as a possibility to add dictionaries (it's up to the user to get dictionaries - free or paid, and make them compatible with the addon), but in the lack of one, we fall back to online translating using google translate or similar service (this should also be customizable, like the current subtitles services which allows users\developers to add new subtitles providers with scraping rules). By the way, the target language for the translation should be determined by an option in the addon settings menu, because locality does not always imply on the user's target language.

I also don't think that too much dialogs is good.. this process should be the fastest it can be, without interfering with the video too much.. so I think pressing the button will bring only one dialog which will include all the current words alongside their translation... so the user only needs to close on dialog box.. but this is really minor detail.

Currently, I'm just starting out with addons development, and I'm trying to get all the details on the process... (already have a lot of experience with Python, so this might not take too long...) I just wish there was a very good comprehensive guide for addons development, because unfortunately that docs seems too much cumbersome and definitely not linear.

If anyone wants to take this as a project, I'd love that, and I'll be happy to participate, and also learn from this.
Reply
#6
(2014-10-19, 04:33)nickr Wrote: Workflow, the addon could:

1 pause
2 bring up a scrolling dialog box with the subtitles in it at current position - they are just text after all. Xbmc must know internally the current subtitle stream and position in it. Query; is this info available to an addon?
3 user scrolls to unknown word and presses ok, Google translate or similar service gives translation, pops up another dialog?
4 must be able to set from and to language on the fly. ''From" defaults to subtitle language, "to" defaults to your locality as defined in xbmc settings.

1. _
2. I am pretty sure the subtitle is available from the JSON RPC API. And even if it just gives you a filename, it shouldnt be difficult to get the current time from the player and lookup the value in the subtitle file. Though any user specified subtitle offset may be difficult to obtain. But you could just allow the user to jump forward or back to the previous subtitle (which would be a good feature to have as standard anyway).
3. Google translate does have an API, but it costs $. This may be a better alternative: http://mymemory.translated.net/doc/spec.php
4. This can all be handled in a simple List structure.
Reply
#7
So, I've been going all over the api provided by xbmc libraries (in particular the xbmc.Player api), and couldn't find any method to retrieve the current subtitles filename (JSON RPC API seems to just provide similar functionality to the Python's libraries).

The only subtitles-related methods are:
- Player.getAvailableSubtitleStreams
- Player.getSubtitles

The first retrieve a list of language codes (i.e. "en", "he", "fr") for all available subtitles whether in the movie file dir or embedded in it , the second one also gives a language code but only for for the currently used subtitles file (this might be useful).

So, without the subtitles filename I'll have to look at the movie file's folder, and search for a subtitles file with a modifier of the language code for the currently used subtitles files (i.e. run Player.getSubtitles(), and then check if it's something the user wants to translate, and then look for a file with that language's code as a suffix , parse it, and so on...).

Now, a couple questions:
1. How do I make this script invoked only by pressing some button on the remote ? (I saw a lot of examples of scripts that are initalized on startup, and setting an event to be triggered every time the movie is stopped, but couldn't find any script that all of its functionality is controlled during playback with a remote control button). I would really appreciate a very simple example (I know about keyboard.xml and stuff.. but an example would really help here).
2. Subtitles folder can be changed via the system settings (it default to the movie directory). How do I retrieve the correct folder set by the user ?
3. Some good practice maybe about GUI development? I just want to put some simple box with a list of words and translations for now.. that shouldn't be hard, but yet many GUIs that I have looked at are using some complicated skins settings... I just want to use the default skin, is that possible? (I mean, when creating a Window and putting in some controls, they currently look very ugly, flat, no shadow and nothing.. I just want them to look like default buttons and windows as they look in the entire XBMC platform). Plus I'd really love working with WindowXML, but couldn't find any decent guide for it.

Appreciate all your help!
Reply
#8
1. I think it would require mapping in keyboard.xml. I reckon elements of this http://kodi.wiki/view/Add-on:Keymap_Editor could be used to map a button on the remote from within the addon settings.

2. You can use the 'special' protocol http://kodi.wiki/view/Special_protocol to get the users sub-title folder location. The full location string can be retrieved like this:
Code:
xbmc.translatePath('special://subtitles')

3. All the skins will have a window (DialogSelect.xml) that you can provide with a list of ListItems. You can reserve the first or last 3-5 items in the list to be user options like --From Language-- or --Previous Subtitle--. The script can then be set to close the window, do that action, and reopen the window again. (It can even automatically return to the item it was on.)

You could try and build your own window. But I would recommend going with something quick and ugly to start with, to test the functioning of the script, and then try to make it pretty once the main function is working.
Reply

Logout Mark Read Team Forum Stats Members Help
Feasibilty of addon for live translate chosen words in subtitles while watching0