Advertisement
Guest User

Untitled

a guest
Mar 1st, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.27 KB | None | 0 0
  1. __author__ = 'mark'
  2.  
  3. from _csv import Error
  4.  
  5. import xbmcaddon
  6. import xbmcgui
  7. import xbmc
  8. import urllib2
  9. import urllib
  10. import json
  11. import cookielib
  12.  
  13.  
  14. #
  15. # see http://forum.kodi.tv/showthread.php?tid=189876
  16. # for the only half decent explanation I have found ... :(
  17. #
  18. # http://kodi.wiki/view/List_of_Built_In_Functions
  19. # http://kodi.wiki/view/Skin_development_introduction
  20. # http://kodi.wiki/view/Opening_Windows_and_Dialogs
  21. # http://kodi.wiki/view/InfoLabels
  22. # http://kodi.wiki/view/Button_control
  23. # http://kodi.wiki/view/Controls
  24. #
  25.  
  26. def registerwithunblockr(key, email, affiliate_id):
  27.     d = {'key': key, '_format': 'xml', 'login': email, 'email': email, 'pass': 'secret'}
  28.     try:
  29.         cj = cookielib.CookieJar();
  30.         ck = cookielib.Cookie(
  31.  
  32.                               version=0, name='OLRProduct',
  33.                           value='amember_aff_id',
  34.                           port=None, port_specified=False,
  35.                           domain='.unblockr.net',
  36.                           domain_specified=True,
  37.                           domain_initial_dot=True, path='/',
  38.                           path_specified=True, secure=False,
  39.                           expires=None, discard=True, comment=None,
  40.                           comment_url=None, rest={'HttpOnly': None}
  41.  
  42.                               )
  43.         cj.set_cookie(ck);
  44.         opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
  45.         response = opener.open('http://manage.unblockr.net/api/users',urllib.urlencode(d))
  46.         if 200 != response.code:
  47.             xbmc.executebuiltin('Notification(%s, %s, %d, %s)' % (
  48.                 __addonname__, "Failed (code:%d) to call Unblockr URL" % response.code, 2000, __icon__))
  49.         else:
  50.             unblockrJSON = response.read();
  51.             xbmc.log("unblockr response is '"+unblockrJSON+"'")
  52.             resp = json.loads(unblockrJSON)
  53.             if resp['code'] < 0:
  54.                 raise Error(resp['msg'])
  55.  
  56.     except (IOError, Error) as E:
  57.         errmsg = 'Unblockr IP Reset (%s)' % (E)
  58.         xbmc.executebuiltin('Notification(%s, %s, %d, %s)' % (__addonname__, errmsg, 2000, __icon__))
  59.  
  60.  
  61. ACTION_EXIT_SCRIPT = (9, 10)
  62.  
  63.  
  64. class MainGUI(xbmcgui.WindowXMLDialog):
  65.     def __init__(self, *args, **kwargs):
  66.         xbmcgui.WindowXMLDialog.__init__(self)
  67.  
  68.     def onInit(self):
  69.         pass
  70.  
  71.     def onAction(self, action):
  72.         if (action in ACTION_EXIT_SCRIPT):
  73.             self.close()
  74.  
  75.     def onClick(self, controlId):
  76.         if (controlId == 300):
  77.             xbmc.log("Will register '" + xbmc.getInfoLabel('Skin.String(email)') + "' with unblockr")
  78.             registerwithunblockr('D7CqmCqIpO0XwqfNzS49', xbmc.getInfoLabel('Skin.String(email)'), '2')
  79.             self.close()
  80.  
  81.         if (controlId == 299):
  82.             self.close()
  83.  
  84.     def onControl(self, controlId):
  85.         xbmc.log('ACTION:' + controlId)
  86.         xbmc.log('')
  87.  
  88.     def onFocus(self, controlId):
  89.         pass
  90.  
  91.  
  92. __addon__ = xbmcaddon.Addon(id='script.service.unblockr')
  93. __addonname__ = __addon__.getAddonInfo('name')
  94. __icon__ = __addon__.getAddonInfo('icon')
  95.  
  96. xbmc.log('FB:' + xbmcaddon.Addon().getAddonInfo('path').decode('utf-8'));
  97. ui = MainGUI('signup.xml', xbmcaddon.Addon().getAddonInfo('path').decode('utf-8'))
  98.  
  99. ui.doModal()
  100. del ui
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement