Advertisement
Guest User

Untitled

a guest
Jun 20th, 2016
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.37 KB | None | 0 0
  1. from resources.lib.config import cConfig
  2. from resources.lib.gui.gui import cGui
  3. from resources.lib.parser import cParser
  4.  
  5. import urllib2,urllib
  6. import xbmc
  7. import xbmcaddon
  8. import re,os
  9.  
  10. PathCache = xbmc.translatePath(xbmcaddon.Addon('plugin.video.vstream').getAddonInfo("profile"))
  11. UA = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3'
  12. headers = { 'User-Agent' : UA }
  13.  
  14. class cPremiumHandler:
  15.  
  16. def __init__(self, sHosterIdentifier):
  17. self.__sHosterIdentifier = sHosterIdentifier.lower()
  18. self.__sDisplayName = 'Premium mode'
  19. self.isLogin = False
  20.  
  21. def isPremiumModeAvailable(self):
  22. bIsPremium = cConfig().getSetting('hoster_' + str(self.__sHosterIdentifier) + '_premium')
  23. if (bIsPremium == 'true'):
  24. cConfig().log("Utilise compte premium pour hoster " + str(self.__sHosterIdentifier))
  25. return True
  26.  
  27. cConfig().log("Utilise compte gratuit pour hoster: " + str(self.__sHosterIdentifier))
  28. return False
  29.  
  30. def getUsername(self):
  31. sUsername = cConfig().getSetting('hoster_' + str(self.__sHosterIdentifier) + '_username')
  32. return sUsername
  33.  
  34. def getPassword(self):
  35. sPassword = cConfig().getSetting('hoster_' + str(self.__sHosterIdentifier) + '_password')
  36. return sPassword
  37.  
  38. #-----------------------
  39. # Cookies gestion
  40. #------------------------
  41.  
  42. def DeleteCookie(self,Domain):
  43. print 'Effacement cookies'
  44. file = os.path.join(PathCache,'Cookie_'+ str(Domain) +'.txt')
  45. os.remove(os.path.join(PathCache,file))
  46.  
  47. def SaveCookie(self,Domain,data):
  48. Name = os.path.join(PathCache,'Cookie_'+ str(Domain) +'.txt')
  49.  
  50. #save it
  51. file = open(Name,'w')
  52. file.write(data)
  53.  
  54. file.close()
  55.  
  56. def Readcookie(self,Domain):
  57. Name = os.path.join(PathCache,'Cookie_'+ str(Domain) +'.txt')
  58.  
  59. try:
  60. file = open(Name,'r')
  61. data = file.read()
  62. file.close()
  63. except:
  64. return ''
  65.  
  66. return data
  67.  
  68. def AddCookies(self):
  69. cookies = self.Readcookie(self.__sHosterIdentifier)
  70. return 'Cookie=' + cookies
  71.  
  72. def Authentificate(self):
  73.  
  74. post_data = {}
  75.  
  76. if 'uptobox' in self.__sHosterIdentifier:
  77. url = 'https://login.uptobox.com/logarithme'
  78. post_data['op'] = 'login'
  79. post_data['login'] = self.getUsername()
  80. post_data['password'] = self.getPassword()
  81.  
  82. elif 'onefichier' in self.__sHosterIdentifier:
  83. url = 'https://1fichier.com/login.pl'
  84. post_data['mail'] = self.getUsername()
  85. post_data['pass'] = self.getPassword()
  86. post_data['lt'] = 'on'
  87. post_data['purge'] = 'on'
  88. post_data['valider'] = 'Send'
  89. elif 'uploaded' in self.__sHosterIdentifier:
  90. url = 'http://uploaded.net/io/login'
  91. post_data['id'] = self.getUsername()
  92. post_data['pw'] = self.getPassword()
  93.  
  94. #si aucun de trouve on retourne
  95. else:
  96. return False
  97.  
  98. #print url
  99. #print post_data
  100.  
  101. req = urllib2.Request(url, urllib.urlencode(post_data), headers)
  102.  
  103. try:
  104. response = urllib2.urlopen(req)
  105. except urllib2.URLError, e:
  106. if e.code == 403:
  107. #login denied
  108. cGui().showInfo(self.__sDisplayName, 'Authentification rate' , 5)
  109. elif e.code == 502:
  110. #login denied
  111. cGui().showInfo(self.__sDisplayName, 'Authentification rate' , 5)
  112. elif e.code == 234:
  113. #login denied
  114. cGui().showInfo(self.__sDisplayName, 'Authentification rate' , 5)
  115. else:
  116. print e.code
  117. print e.reason
  118.  
  119. self.isLogin = False
  120. return False
  121.  
  122. sHtmlContent = response.read()
  123. head = response.headers
  124. response.close()
  125.  
  126. #print head
  127.  
  128. #fh = open('c:\\prem.txt', "w")
  129. #fh.write(sHtmlContent)
  130. #fh.close()
  131.  
  132. if 'uptobox' in self.__sHosterIdentifier:
  133. if 'OK' in sHtmlContent:
  134. self.isLogin = True
  135. else:
  136. cGui().showInfo(self.__sDisplayName, 'Authentification rate' , 5)
  137. return False
  138. elif 'onefichier' in self.__sHosterIdentifier:
  139. if 'You are logged in. This page will redirect you.' in sHtmlContent:
  140. self.isLogin = True
  141. else:
  142. cGui().showInfo(self.__sDisplayName, 'Authentification rate' , 5)
  143. return False
  144. elif 'uploaded' in self.__sHosterIdentifier:
  145. if sHtmlContent == '':
  146. self.isLogin = True
  147. else:
  148. cGui().showInfo(self.__sDisplayName, 'Authentification rate' , 5)
  149. return False
  150. else:
  151. return False
  152.  
  153. #get cookie
  154. cookies = ''
  155. if 'Set-Cookie' in head:
  156. oParser = cParser()
  157. sPattern = '(?:^|,) *([^;,]+?)=([^;,\/]+?);'
  158. aResult = oParser.parse(str(head['Set-Cookie']), sPattern)
  159. #print aResult
  160. if (aResult[0] == True):
  161. for cook in aResult[1]:
  162. cookies = cookies + cook[0] + '=' + cook[1]+ ';'
  163.  
  164. #save cookie
  165. self.SaveCookie(self.__sHosterIdentifier,cookies)
  166.  
  167. cGui().showInfo(self.__sDisplayName, 'Authentification reussie' , 5)
  168. print 'Auhentification reussie'
  169.  
  170. return True
  171.  
  172. def GetHtml(self,url,data = None):
  173. cookies = self.Readcookie(self.__sHosterIdentifier)
  174.  
  175. req = urllib2.Request(url, data, headers)
  176.  
  177. if not (data == None):
  178. req.add_header('Referer', url)
  179.  
  180. req.add_header('Cookie', cookies)
  181.  
  182. try:
  183. response = urllib2.urlopen(req)
  184. except urllib2.URLError, e:
  185. print e.code
  186. print e.reason
  187. return ''
  188.  
  189.  
  190. sHtmlContent = response.read()
  191. response.close()
  192.  
  193. return sHtmlContent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement