Trying to fix XBMC subtitle provider ondertitels.com need some help
#1
The ondertitels.com subtitle provider is broken and will not download subtitles. The error logged in xbmc.log is:

19:59:59 T:140093527381760 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type:
Error Contents: 'NoneType' object is not iterable
Traceback (most recent call last):
File "/storage/.xbmc/addons/script.xbmc.subtitles/resources/lib/gui.py", line 492, in onClick
self.Download_Subtitles( self.getControl( SUBTITLES_LIST ).getSelectedPosition())
File "/storage/.xbmc/addons/script.xbmc.subtitles/resources/lib/gui.py", line 301, in Download_Subtitles
self.session_id
TypeError: 'NoneType' object is not iterable
-->End of Python script error report<--

The entire xbmc.log is available at pastebin:
http://sprunge.us/cUXW

I am doing some investigation myself and found out the problem is the regular expression that is scraping the download url from the ondertitels.com webpage.
When changing the downloadlink_pattern to "<a href=\"/(getdownload\.php\?id=\d{1,10}&userfile=[^\n\r\t]*\.\w{3})\"><b>Download</b></a>" the download link is fetched successfully but I am encountering an error when trying to save the zip file to the temp location.

The error thrown is: "ascii' codec can't decode byte 0xd7 in position 18: ordinal not in range(128)"

Full log at: http://sprunge.us/NSNj

The geturl method executes a request.get(url, cookie) and returns r.content

PHP Code:
def geturl(urlaction=FETCH_NORMALcookiedata=''):
    
log__name__ ,"%s Getting url:%s" % (debug_pretexturl))
    try:
        if 
action == FETCH_SUBTITLE:
            
requests.get(urlcookies=cookiedata)
            return 
r.content
        elif action 
== FETCH_COOKIE:
            
requests.get(url)
            return (
r.textr)
        else:
            
requests.get(url)
            return 
r.text
    except
:
        
log__name__ ,"%s Failed to get url:%s" % (debug_pretexturl))
        return 
None 

When writing the content returned from the above method to disk the encoding error is thrown. (see local_file_handle.write(content) below)

PHP Code:
def download_subtitles (subtitles_listposzip_substmp_sub_dirsub_foldersession_id): #standard input
    
log__name__ ,"subtitles_list: %s: " % (subtitles_list))
    
log__name__ ,"pos %s: " % (pos))
    
log__name__ ,"zip_subs %s: " % (zip_subs))
    
log__name__ ,"tmp_sub_dir %s: " % (tmp_sub_dir))
    
log__name__ ,"sub_folder %s " % (sub_folder))
    
log__name__ ,"session_id %s " % (session_id))

    
url main_url subtitles_list[pos][ "link" ]
    
local_tmp_file zip_subs
    content
cookie geturl(urlFETCH_COOKIE)
    
downloadlink getdownloadlink(content)
    
log__name__ ,"downloadlink %s: " % (downloadlink))
    if 
downloadlink is not None:
        try:
            
url main_url downloadlink
            log
__name__ ,"url %s: " % (url))
            
url string.replace(url," ","+")
            
log__name__ ,"url %s: " % (url))
            
log__name__ ,"%s Fetching subtitles using url %s - and cookie: %s" % (debug_pretexturlcookie.cookies))
            
content geturl(urlFETCH_SUBTITLEcookie.cookies)
            
log__name__ ,"content %s: " % (content))
            if 
content is not None:
                
log__name__ ,"%s Saving subtitles to '%s'" % (debug_pretextlocal_tmp_file))
                
local_file_handle open(local_tmp_file"w" "b")
                
local_file_handle.write(content)
                
local_file_handle.close()
        
except:
            
log__name__ ,"%s Failed to save subtitles to '%s'" % (debug_pretextlocal_tmp_file))
        
log__name__ ,"%s Subtitles saved to '%s'" % (debug_pretextlocal_tmp_file))
        
language subtitles_list[pos][ "language_name" ]
        return 
Truelanguage"" #standard output 

I do not have that much knowledge in the python language and am struggling to fix this encoding issue. The content variable is of type str.
The strange thing is, in my "test project" on my Windows environment the file is written to disk without a problem. When doing the same on linux the encoding error is thrown. (OpenElec 3.2.3)
Can somebody help me fix this encoding issue so I can fix the ondertitels.com provider?
Reply
#2
Nevermind fixed it. Problem was the logging of the content variable:

PHP Code:
log__name__ ,"content %s: " % (content)) 

Ondertitel.com subtitle provider is working again. Code is available at github, did a pull request to amet.

https://github.com/amet/script.xbmc.subtitles/pull/205
Reply

Logout Mark Read Team Forum Stats Members Help
Trying to fix XBMC subtitle provider ondertitels.com need some help0