Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = 'mark'
- from _csv import Error
- import xbmcaddon
- import xbmcgui
- import xbmc
- import urllib2
- import urllib
- import json
- import cookielib
- #
- # see http://forum.kodi.tv/showthread.php?tid=189876
- # for the only half decent explanation I have found ... :(
- #
- # http://kodi.wiki/view/List_of_Built_In_Functions
- # http://kodi.wiki/view/Skin_development_introduction
- # http://kodi.wiki/view/Opening_Windows_and_Dialogs
- # http://kodi.wiki/view/InfoLabels
- # http://kodi.wiki/view/Button_control
- # http://kodi.wiki/view/Controls
- #
- def registerwithunblockr(key, email, affiliate_id):
- d = {'key': key, '_format': 'xml', 'login': email, 'email': email, 'pass': 'secret'}
- try:
- cj = cookielib.CookieJar();
- ck = cookielib.Cookie(
- version=0, name='OLRProduct',
- value='amember_aff_id',
- port=None, port_specified=False,
- domain='.unblockr.net',
- domain_specified=True,
- domain_initial_dot=True, path='/',
- path_specified=True, secure=False,
- expires=None, discard=True, comment=None,
- comment_url=None, rest={'HttpOnly': None}
- )
- cj.set_cookie(ck);
- opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
- response = opener.open('http://manage.unblockr.net/api/users',urllib.urlencode(d))
- if 200 != response.code:
- xbmc.executebuiltin('Notification(%s, %s, %d, %s)' % (
- __addonname__, "Failed (code:%d) to call Unblockr URL" % response.code, 2000, __icon__))
- else:
- unblockrJSON = response.read();
- xbmc.log("unblockr response is '"+unblockrJSON+"'")
- resp = json.loads(unblockrJSON)
- if resp['code'] < 0:
- raise Error(resp['msg'])
- except (IOError, Error) as E:
- errmsg = 'Unblockr IP Reset (%s)' % (E)
- xbmc.executebuiltin('Notification(%s, %s, %d, %s)' % (__addonname__, errmsg, 2000, __icon__))
- ACTION_EXIT_SCRIPT = (9, 10)
- class MainGUI(xbmcgui.WindowXMLDialog):
- def __init__(self, *args, **kwargs):
- xbmcgui.WindowXMLDialog.__init__(self)
- def onInit(self):
- pass
- def onAction(self, action):
- if (action in ACTION_EXIT_SCRIPT):
- self.close()
- def onClick(self, controlId):
- if (controlId == 300):
- xbmc.log("Will register '" + xbmc.getInfoLabel('Skin.String(email)') + "' with unblockr")
- registerwithunblockr('D7CqmCqIpO0XwqfNzS49', xbmc.getInfoLabel('Skin.String(email)'), '2')
- self.close()
- if (controlId == 299):
- self.close()
- def onControl(self, controlId):
- xbmc.log('ACTION:' + controlId)
- xbmc.log('')
- def onFocus(self, controlId):
- pass
- __addon__ = xbmcaddon.Addon(id='script.service.unblockr')
- __addonname__ = __addon__.getAddonInfo('name')
- __icon__ = __addon__.getAddonInfo('icon')
- xbmc.log('FB:' + xbmcaddon.Addon().getAddonInfo('path').decode('utf-8'));
- ui = MainGUI('signup.xml', xbmcaddon.Addon().getAddonInfo('path').decode('utf-8'))
- ui.doModal()
- del ui
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement