Advertisement
Guest User

pandoki.diff

a guest
Jan 2nd, 2015
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.35 KB | None | 0 0
  1. diff -Naur old/resources/lib/pandoki/pandoki.py plugin.audio.pandoki/resources/lib/pandoki/pandoki.py
  2. --- old/resources/lib/pandoki/pandoki.py    2015-01-02 08:14:17.152966502 +0100
  3. +++ plugin.audio.pandoki/resources/lib/pandoki/pandoki.py   2015-01-02 08:07:13.588677898 +0100
  4. @@ -2,6 +2,15 @@
  5.  import xbmc, xbmcaddon, xbmcgui, xbmcplugin, xbmcvfs
  6.  import asciidamnit, musicbrainzngs, pithos
  7.  
  8. +try:
  9. +    import urllib3
  10. +    import urllib3.contrib.pyopenssl
  11. +    urllib3.contrib.pyopenssl.inject_into_urllib3()
  12. +    _urllib3 = True
  13. +except ImportError:
  14. +    _urllib3 = False
  15. +    pass
  16. +
  17.  from mutagen.mp3 import MP3
  18.  from mutagen.easyid3 import EasyID3
  19.  from mutagen.easymp4 import EasyMP4
  20. @@ -56,6 +65,11 @@
  21.          self.prof  = Val('prof')
  22.          self.wait  = { 'auth' : 0, 'stations' : 0, 'flush' : 0, 'scan' : 0, 'next' : 0 }
  23.          self.silent    = xbmc.translatePath("special://home/addons/%s/resources/media/silent.m4a" % _id)
  24. +        
  25. +        if (Val('sni') == 'true'):
  26. +            self.sni = True
  27. +        else:
  28. +            self.sni = False
  29.  
  30.          musicbrainzngs.set_useragent("xbmc.%s" % _id, Val('version'))
  31.          xbmcvfs.mkdirs(xbmc.translatePath(Val('cache')).decode("utf-8"))
  32. @@ -79,6 +93,21 @@
  33.  
  34.          return open
  35.  
  36. +    def ProxySNI(self):
  37. +        proxy = Val('proxy')
  38. +
  39. +        if   proxy == '0': # Global
  40. +            open = urllib3.PoolManager()
  41. +
  42. +        elif proxy == '1': # None
  43. +            open = urllib3.PoolManager()
  44. +
  45. +        elif proxy == '2': # Custom
  46. +            http = "http://%s:%s@%s:%s" % (Val('proxy_user'), Val('proxy_pass'), Val('proxy_host'), Val('proxy_port'))
  47. +            open = urllib3.ProxyManager(http)
  48. +
  49. +        return open
  50. +
  51.  
  52.      def Auth(self):
  53.          p = Val('prof')
  54. @@ -89,7 +118,10 @@
  55.  
  56.          if time.time() < self.wait['auth']: return True
  57.  
  58. -        self.pithos.set_url_opener(self.Proxy())
  59. +        if (self.sni):
  60. +            self.pithos.set_url_opener(self.ProxySNI(), True)
  61. +        else:
  62. +            self.pithos.set_url_opener(self.Proxy(), False)
  63.  
  64.          try: self.pithos.connect(Val('one' + p), Val('username' + p), Val('password' + p))
  65.          except pithos.PithosError:
  66. @@ -102,6 +134,13 @@
  67.  
  68.  
  69.      def Login(self):
  70. +        if (self.sni):
  71. +            if not (_urllib3):
  72. +                if xbmcgui.Dialog().yesno(Val('name'), 'SNI Support not found', 'Please install: pyOpenSSL/ndg-httpsclient/pyasn1', 'Check Settings?'):
  73. +                    xbmcaddon.Addon().openSettings()
  74. +                else:
  75. +                    exit()
  76. +
  77.          while not self.Auth():
  78.              if xbmcgui.Dialog().yesno(Val('name'), '          Login Failed', 'Bad User / Pass / Proxy', '       Check Settings?'):
  79.                  xbmcaddon.Addon().openSettings()
  80. diff -Naur old/resources/lib/pithos/pithos.py plugin.audio.pandoki/resources/lib/pithos/pithos.py
  81. --- old/resources/lib/pithos/pithos.py  2015-01-02 08:14:17.152966502 +0100
  82. +++ plugin.audio.pandoki/resources/lib/pithos/pithos.py 2015-01-01 21:42:53.382838813 +0100
  83. @@ -85,6 +85,7 @@
  84.      def __init__(self):
  85.          self.opener = urllib2.build_opener()
  86.          self.stations = []
  87. +        self.sni = False
  88.          pass
  89.  
  90.  
  91. @@ -125,19 +126,27 @@
  92.          if blowfish:
  93.              data = self.pandora_encrypt(data)
  94.  
  95. -        try:
  96. -            req = urllib2.Request(url, data, {'User-agent': USER_AGENT, 'Content-type': 'text/plain'})
  97. -            response = self.opener.open(req, timeout=HTTP_TIMEOUT)
  98. -            text = response.read()
  99. -        except urllib2.HTTPError as e:
  100. -            logging.error("HTTP error: %s", e)
  101. -            raise PithosNetError(str(e))
  102. -        except urllib2.URLError as e:
  103. -            logging.error("Network error: %s", e)
  104. -            if e.reason[0] == 'timed out':
  105. -                raise PithosTimeout("Network error", submsg="Timeout")
  106. -            else:
  107. -                raise PithosNetError("Network error", submsg=e.reason[1])
  108. +        if self.sni:
  109. +            try:
  110. +                response = self.opener.urlopen('POST', url, headers={'User-agent': USER_AGENT, 'Content-type': 'text/plain'}, body=data)
  111. +                text = response.data
  112. +            except:
  113. +                logging.error("urllib3 error")
  114. +                raise PithosNetError('urllib3 error')
  115. +        else:
  116. +            try:
  117. +                req = urllib2.Request(url, data, {'User-agent': USER_AGENT, 'Content-type': 'text/plain'})
  118. +                response = self.opener.open(req, timeout=HTTP_TIMEOUT)
  119. +                text = response.read()
  120. +            except urllib2.HTTPError as e:
  121. +                logging.error("HTTP error: %s", e)
  122. +                raise PithosNetError(str(e))
  123. +            except urllib2.URLError as e:
  124. +                logging.error("Network error: %s", e)
  125. +                if e.reason[0] == 'timed out':
  126. +                    raise PithosTimeout("Network error", submsg="Timeout")
  127. +                else:
  128. +                    raise PithosNetError("Network error", submsg=e.reason.strerror)
  129.  
  130.          logging.debug(text)
  131.  
  132. @@ -179,7 +188,8 @@
  133.              return tree['result']
  134.  
  135.  
  136. -    def set_url_opener(self, opener):
  137. +    def set_url_opener(self, opener, sni):
  138. +        self.sni = sni
  139.          self.opener = opener
  140.  
  141.  
  142. diff -Naur old/resources/settings.xml plugin.audio.pandoki/resources/settings.xml
  143. --- old/resources/settings.xml  2015-01-02 08:14:17.144966647 +0100
  144. +++ plugin.audio.pandoki/resources/settings.xml 2015-01-01 21:42:53.382838813 +0100
  145. @@ -12,7 +12,8 @@
  146.         <setting id="password2"  type="text"   label="Password"                         visible="eq(-8,2)" option="hidden"/>
  147.         <setting id="one2"       type="bool"   label="Pandora One"      default="false" visible="eq(-9,2)"/>
  148.         <setting                 type="sep"/>
  149. -       <setting id="proxy"      type="enum"   label="Use Proxy"        default="0"     values="Global|None|Custom"/>
  150. +    <setting id="sni"        type="bool"   label="SNI Support"      default="false"/>
  151. +    <setting id="proxy"      type="enum"   label="Use Proxy"        default="0"     values="Global|None|Custom"/>
  152.         <setting id="proxy_host" type="text"   label="Server"                           visible="eq(-1,2)"/>
  153.         <setting id="proxy_port" type="number" label="Port"                             visible="eq(-2,2)"/>
  154.         <setting id="proxy_user" type="text"   label="Username"                         visible="eq(-3,2)"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement