xbmc.Player() callbacks
#1
Hello,
I am creating an addon where I reproduce some links using xbmcplugin.setResolvedUrl().
Sometimes the video is not yet available or is rejected by geolocation, which gives me an error CCurlFile::Stat - Failed: HTTP response code said error(22) for... or CCurlFile::Open failed with code 401 for...
Is there any method to get those codes from the addon?
I've been looking at the xbmc.Player() callbacks, specifically onPlayBackStopped and onPlayBackError but I don't know how to get the aforementioned error code from CCurlFile
Reply
#2
(2022-05-19, 17:43)caperucitaferoz Wrote: Hello,
I am creating an addon where I reproduce some links using xbmcplugin.setResolvedUrl().
Sometimes the video is not yet available or is rejected by geolocation, which gives me an error CCurlFile::Stat - Failed: HTTP response code said error(22) for... or CCurlFile::Open failed with code 401 for...
Is there any method to get those codes from the addon?
I've been looking at the xbmc.Player() callbacks, specifically onPlayBackStopped and onPlayBackError but I don't know how to get the aforementioned error code from CCurlFile

I don't think you can get the response codes directly but I'll leave that to a Kodi member or similar to answer.  What I've done is test the URL in advance of calling the setResolvedUrl() method.

Something like this.

def get_html(url):
    req = urllib.request.Request(url)
    req.add_header('User-Agent','User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:44.0) Gecko/20100101 Firefox/44.0')

    try:
        response = urllib.request.urlopen(req)
        code = response.getcode()
        if code == 403:              
            xbmcgui.Dialog().notification(name, translation(30001), defaultimage, notetime, False)
            html = 'error'
        elif code == 22:              
            xbmcgui.Dialog().notification(name, translation(30010), defaultimage, notetime, False)
            html = 'error'
        html = response.read()
        response.close()
    except urllib.error.URLError:              
        xbmcgui.Dialog().notification(name, translation(30010), defaultimage, notetime, False)
        html = 'error'
    return html

You can add more codes to test (i.e. html >= 400 etc..) for and if html != error then do the setResolvedUrl() command.  I am sure thee is likely an easier way but this worked for me. I also give the user a notification if something goes wrong.


Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#3
I'm using some callbacks from xbmc.Player in my addon, maybe you can take some inspiration.

https://github.com/Mariusz89B/script.mtv...#L432-L524
https://github.com/Mariusz89B/script.mtv...1566-L1626
https://github.com/Mariusz89B/script.mtv...e.py#L1678
Reply
#4
Your checkConnection function is a similar approach albeit much better written Smile


Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#5
Thank you both very much for your responses. Now I understand the process and although it was not exactly my request, I think it will come in handy.

Thank you very much
Reply

Logout Mark Read Team Forum Stats Members Help
xbmc.Player() callbacks0