Kodi Community Forum
[DEPRECIATED] XBMC Subtitles - Addon Script (previously OpenSubtitles OSD) - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: Add-on Support (https://forum.kodi.tv/forumdisplay.php?fid=27)
+---- Forum: Subtitle Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=143)
+---- Thread: [DEPRECIATED] XBMC Subtitles - Addon Script (previously OpenSubtitles OSD) (/showthread.php?tid=75437)



- Raqueem - 2011-02-25

Great plugin as far as i have tested it.


Too bad there is no automatic download in the (1st) preferred language for example, so you don't have to click each and every time.

Apart from that.. kudos.


- mr_blobby - 2011-02-25

Gothic Wrote:I had the same problem ....
On what configuration did you have the same problem?
Because I can't reproduce the problem on my Win7.


- kurri - 2011-02-25

Gothic Wrote:I had the same problem (I'm new to XBMC) and did some debug tracing.
I'm a programmer but Python isn't my language so bare with me Wink

I managed to find the issue.
The quick workaround is to do a minor change in service.py in both "Undertexter" and "Swesub".

Open the following file in gedit:
Code:
~/.xbmc/addons/script.xbmc.subtitles/resources/lib/services/Undertexter/service.py
Locate the line:
Code:
if mtime > max_mtime
Replace it with:
Code:
if (string.split(file,'.')[-1] in ['srt','sub','txt']) and (mtime > max_mtime)
If you want you can comment out the line (3 lines below the above):
Code:
time.sleep(2)

by adding a # before the line

Do the same for Swesubs.

Hope that helps

Thanks a lot, this fixed the issue for me at least!


- Gothic - 2011-02-26

mr_blobby Wrote:On what configuration did you have the same problem?
Because I can't reproduce the problem on my Win7.
Ok, then it's probably OS related.
I'm running XBMC on Ubuntu 10.10


- h3nk3 - 2011-02-26

THAAAANK YOU GOTHIC!!!

Now it works like a charm. It didnt first but after setting ":" in the last of your line everything worked!!!!

You saved my day!!!

THANKS THANKS THANKSBig GrinBig GrinBig GrinBig GrinBig Grin


- mr_blobby - 2011-02-26

The fix will be included in a new version.
Thanks!


- Gothic - 2011-02-26

h3nk3 Wrote:THAAAANK YOU GOTHIC!!!

Now it works like a charm. It didnt first but after setting ":" in the last of your line everything worked!!!!

You saved my day!!!

THANKS THANKS THANKSBig GrinBig GrinBig GrinBig GrinBig Grin

Glad I could help but I just made a minor change to mr_blobby's great work. Nod


- amet - 2011-02-27

2.3.4 is on GitHub, if you care to try it and let us know. I will push to official repo if all is in order.

Code:
2.3.4
- fixed: On Unix some services failed in using the unpacked subtitle file
- added: more tvshow regex for file mode search



- Gothic - 2011-02-27

amet Wrote:2.3.4 is on GitHub, if you care to try it and let us know. I will push to official repo if all is in order.

Code:
2.3.4
- fixed: On Unix some services failed in using the unpacked subtitle file
- added: more tvshow regex for file mode search

I think the changes has been made in the wrong place.
Downloaded rar/zip file should be ignored when setting timestamp of the newest existing file in the folder.

Code:
# determine the newest file from tmp_sub_dir
for file in files:                
     mtime = os.stat(os.path.join(tmp_sub_dir, file)).st_mtime                
     if (string.split(file,'.')[-1] in ['srt','sub','txt']) and (mtime > max_mtime):                    
          max_mtime =  mtime            
init_max_mtime = max_mtime            
#time.sleep(2)  # wait 2 seconds so that the unpacked files are at least 1 second newer



Help getting started adding a service - orivar - 2011-02-27

Hello everyone and amet in particular,

First off thanks again for the great addon. I've only recently updated to Dharma/10.0 and while my old skin is lacking proper support (MediaStream Redux) I've been using the new addon with Confluence and find it a valuable feature of XBMC.

I've posted before about adding my own service to for local subtitles and now, after finally completing all the scripts and configuration for the rest of my automated media setup, am getting around to it.

Looking for an API I found several of your posts amet directing people to existing service.py's for reference. I've tried reading a couple of updated service script sources but I'm still having trouble "reverse engineering" your exact interface:
1. It seems like there are two main functions that must be implemented, search_subtitles and download_subtitles. Are there any other mandatory functions (or heaven forbid variables)?
2. What do all the input parameters mean? Specifically, what does rar/set_temp mean and what are their expected types? Same for zip_subs/sub_folder/session_id?
3. I see both of these functions return a tuple of 3 items each. What are their types? It seems like search_subtitles returns: a list (of tuples?), some unknown string and a message (msg) I've yet to see used. download_subtitles is a boolean (which is usually False but I can't see the significance), a language string (is this a known set in XBMC? where can I find it?) and a subtitles file (full path?). I'm unlclear about some of their uses and types.
4. Are there any expected side effects to these functions besides of course extracting the downloaded file if necessary?


What I think I'm looking for is a more documented sample script (with as few utility/private functions or clearly marked ones) or perhaps an API document to get me started.
I'm sorry for the long post and am accepting PMs of course (if preferred) in reply.

Thanks.


- amet - 2011-02-27

orivar Wrote:Hello everyone and amet in particular,

First off thanks again for the great addon. I've only recently updated to Dharma/10.0 and while my old skin is lacking proper support (MediaStream Redux) I've been using the new addon with Confluence and find it a valuable feature of XBMC.

I've posted before about adding my own service to for local subtitles and now, after finally completing all the scripts and configuration for the rest of my automated media setup, am getting around to it.

Looking for an API I found several of your posts amet directing people to existing service.py's for reference. I've tried reading a couple of updated service script sources but I'm still having trouble "reverse engineering" your exact interface:
1. It seems like there are two main functions that must be implemented, search_subtitles and download_subtitles. Are there any other mandatory functions (or heaven forbid variables)?

no, thats all you need to use

orivar Wrote:2. What do all the input parameters mean? Specifically, what does rar/set_temp mean and what are their expected types? Same for zip_subs/sub_folder/session_id?
3. I see both of these functions return a tuple of 3 items each. What are their types? It seems like search_subtitles returns: a list (of tuples?), some unknown string and a message (msg) I've yet to see used. download_subtitles is a boolean (which is usually False but I can't see the significance), a language string (is this a known set in XBMC? where can I find it?) and a subtitles file (full path?). I'm unlclear about some of their uses and types.

Code:
search_subtitles( file_original_path, title, tvshow, year, season, episode, set_temp, rar, lang1, lang2, lang3 ):
file_original_path -> original path of the file playing
title -> title of the movie or episode
tvshow -> name of a tv show
year -> year
season -> season
episode -> episode
set_temp -> this is mostly false, only true on http:// streamed movies
rar -> if movie/tvshow is in a rar archive
lang1, lang2, lang3 -> languages

Code:
return subtitles_list, session_id, msg

subtitles_list -> list of subtitles
session_id -> some download sites need same session id for download of teh subtitle
msg -> any msg you would like to display after the search is done


Code:
download_subtitles (subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, session_id):
subtitles_list -> same list returned from search function
pos -> clicked position from the GUI list
zip_subs -> zipsubs.zip located in tmp location
tmp_sub_dir -> tmp location ^^
sub_folder -> folder where the sub will be saved
session_id -> session_id fron search function

Code:
return False, language, subs_file

False(or True) -> if downloaded file is archive(zip)
language -> language of the subtitle
subs_file -> this is only used if downloaded file is not archive, we need the absolute path so that we can move it to a desired location

orivar Wrote:4. Are there any expected side effects to these functions besides of course extracting the downloaded file if necessary?

you can pass the msg but other than that, no


- mr_blobby - 2011-02-27

Gothic Wrote:I think the changes has been made in the wrong place.
Downloaded rar/zip file should be ignored when setting timestamp of the newest existing file in the folder.

Code:
# determine the newest file from tmp_sub_dir
for file in files:                
     mtime = os.stat(os.path.join(tmp_sub_dir, file)).st_mtime                
     if (string.split(file,'.')[-1] in ['srt','sub','txt']) and (mtime > max_mtime):                    
          max_mtime =  mtime            
init_max_mtime = max_mtime            
#time.sleep(2)  # wait 2 seconds so that the unpacked files are at least 1 second newer
Thanks for checking.
I've made a correction for the bugfix.
It will now only look for subtitle files and will ignore any other filetype.


- orivar - 2011-02-27

Wow, thanks a lot Big Grin That cleared up most of my questions.
A few more follow-ups and, time permitting, I'll try to get around to writing it this week:

1. I'm missing the list of possible values for "language_name" in the "subtitles_list" tuple or the "lang1/2/3" parameters (hopefully these are taken from the same list but if not I could match them up...)
2. I wanna make sure I understand the way the subtitles file is returned:
a. If the downloaded file is a zip file, I should download it to "tmp_sub_dir" as "zipsubs.zip"? Why do I need a "zip_subs" parameter from your addon - what are some typical values?
b. If the downloaded file is of a different format or if I choose to extract myself (that's still an option, right?) I should put it in "sub_folder" and return its name in "subs_file" (full path I assume)? That would work, but then "sub_folder" seems redundent since I have "tmp_sub_dir" and I supply you with "subs_file" which could well be located there instead.


- amet - 2011-02-27

orivar Wrote:Wow, thanks a lot Big Grin That cleared up most of my questions.
A few more follow-ups and, time permitting, I'll try to get around to writing it this week:

1. I'm missing the list of possible values for "language_name" in the "subtitles_list" tuple or the "lang1/2/3" parameters (hopefully these are taken from the same list but if not I could match them up...)
2. I wanna make sure I understand the way the subtitles file is returned:
a. If the downloaded file is a zip file, I should download it to "tmp_sub_dir" as "zipsubs.zip"? Why do I need a "zip_subs" parameter from your addon - what are some typical values?
b. If the downloaded file is of a different format or if I choose to extract myself (that's still an option, right?) I should put it in "sub_folder" and return its name in "subs_file" (full path I assume)? That would work, but then "sub_folder" seems redundent since I have "tmp_sub_dir" and I supply you with "subs_file" which could well be located there instead.

1. utilities.py has language utilities, language_name is the full lang name(e.g English) and it comes from the site you are scraping. if its in anything else than full lang name use utilities.py to translate it

2a. you dont, you can then ignore it and recreate it yourself. note that it has to be in "tmp_sub_dir" and it needs to be called "zipsubs.zip". you have the full, translated and joined path, why not use it?

2b. if the file downloaded is not zip, then you should extract/place it somewhere(tmp_sub_dir is a good temp place) and return False(its not zip), Language(as above), path_of_your_file(full path so that gui.py can move and rename it).

"sub_folder" could be a left over from something, not sure now... ignore what you dont need Smile


- orivar - 2011-02-27

Quote:ignore what you dont need
Works for me Wink

I do want to understand though so I don't mess anything up. Regarding 2a - so "zip_subs" is a full path version of tmp_sub_dir+zipsubs.zip?

Also, hey mr_blobby Big Grin I saw your name in the Github, I wasn't aware you're a co-developer before, sorry. A thank you is in order for you as well.