Advertisement
Guest User

putlocker / firedrive

a guest
Feb 16th, 2014
782
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.22 KB | None | 0 0
  1. """
  2. urlresolver XBMC Addon
  3. Copyright (C) 2011 t0mm0
  4.  
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. """
  18.  
  19. import re
  20. import os
  21. import xbmcgui
  22. import xbmc
  23. from t0mm0.common.net import Net
  24. import urllib2
  25. import urllib
  26. from urlresolver import common
  27. from urlresolver.plugnplay.interfaces import UrlResolver
  28. from urlresolver.plugnplay.interfaces import PluginSettings
  29. from urlresolver.plugnplay import Plugin
  30. from threading import Thread
  31. import time
  32.  
  33. #SET ERROR_LOGO# THANKS TO VOINAGE, BSTRDMKR, ELDORADO
  34. error_logo = os.path.join(common.addon_path, 'resources', 'images', 'redx.png')
  35.  
  36. class PutlockerResolver(Plugin, UrlResolver, PluginSettings):
  37. implements = [UrlResolver, PluginSettings]
  38. name = "putlocker/sockshare/filedrive/firedrive"
  39. profile_path = common.profile_path
  40. cookie_file = os.path.join(profile_path, 'putlocker.cookies')
  41.  
  42. def __init__(self):
  43. p = self.get_setting('priority') or 100
  44. self.priority = int(p)
  45. self.net = Net()
  46.  
  47. def get_media_url(self, host, media_id):
  48. if self.get_setting('login') == 'true':
  49. if self.login_stale():
  50. self.login()
  51. self.net.set_cookies(self.cookie_file)
  52. web_url = self.get_url(host, media_id)
  53. if web_url[-1:1]=="#": web_url.replace("#","");
  54.  
  55. #find session_hash
  56. try:
  57. html = self.net.http_GET(web_url).content
  58. if ">This file doesn't exist, or has been removed.<" in html: raise Exception (host+": This file doesn't exist, or has been removed.")
  59. elif "404: This file might have been moved, replaced or deleted.<" in html: raise Exception (host+": 404: This file might have been moved, replaced or deleted.")
  60. #Shortcut for logged in users
  61. pattern = '<a href="(/.+?)" class="download_file_link" style="margin:0px 0px;">Download File</a>'
  62. link = re.search(pattern, html)
  63. if link:
  64. common.addon.log('Direct link found: %s' % link.group(1))
  65. if 'putlocker' in host:
  66. return 'http://www.filedrive.com%s' % link.group(1)
  67. #return 'http://www.putlocker.com%s' % link.group(1)
  68. elif 'filedrive' in host:
  69. return 'http://www.filedrive.com%s' % link.group(1)
  70. elif 'firedrive' in host:
  71. return 'http://www.firedrive.com%s' % link.group(1)
  72.  
  73. if 'firedrive' in host or 'filedrive' in host or 'putlocker' in host:
  74. try:
  75. data = {}; r = re.findall(r'type="hidden" name="(.+?)"\s* value="?(.+?)"/>', html); #data['usr_login']=''
  76. for name, value in r: data[name] = value
  77. #data['imhuman']='Proceed to video'; data['btn_download']='Proceed to video'
  78. #xbmc.sleep(2000)
  79. html = self.net.http_POST(web_url, data).content
  80. except urllib2.URLError, e:
  81. common.addon.log_error(host+': got http error %d fetching 2nd url %s' % (e.code, web_url))
  82. return self.unresolvable(code=3, msg='Exception: %s' % e) #return False
  83. r = re.search('<a href="(.+?)" id=\'external_download\' title=\'Download This File\'>', html)
  84. if r:
  85. return urllib.unquote_plus(r.group(1))
  86. #else:
  87. # common.addon.log_error(host+': stream url not found')
  88. # return self.unresolvable(code=0, msg='no file located') #return False
  89. r = re.search("$.post('(.+?)', function(data) {", html)
  90. if r:
  91. return urllib.unquote_plus(r.group(1))
  92. else:
  93. common.addon.log_error(host+': stream url not found')
  94. return self.unresolvable(code=0, msg='no file located') #return False
  95. else:
  96. r = re.search('value="([0-9a-f]+?)" name="hash"', html)
  97. if r:
  98. session_hash = r.group(1)
  99. else:
  100. raise Exception ('putlocker: session hash not found')
  101. #post session_hash
  102. html = self.net.http_POST(web_url, form_data={'hash': session_hash,
  103. 'confirm': 'Continue as Free User'}).content
  104.  
  105. #find playlist code
  106. r = re.search('\?stream=(.+?)\'', html)
  107. if r:
  108. playlist_code = r.group(1)
  109. else:
  110. r = re.search('key=(.+?)&',html)
  111. playlist_code = r.group(1)
  112.  
  113. #find download link
  114. q = self.get_setting('quality')
  115.  
  116. #Try to grab highest quality link available
  117. if q == '1':
  118. #download & return link.
  119. if 'putlocker' in host:
  120. Avi = "http://putlocker.com/get_file.php?stream=%s&original=1"%playlist_code
  121. html = self.net.http_GET(Avi).content
  122. final=re.compile('url="(.+?)"').findall(html)[0].replace('&amp;','&')
  123. return "%s|User-Agent=%s"%(final,'Mozilla%2F5.0%20(Windows%20NT%206.1%3B%20rv%3A11.0)%20Gecko%2F20100101%20Firefox%2F11.0')
  124. elif 'filedrive' in host:
  125. Avi = "http://filedrive.com/get_file.php?stream=%s&original=1"%playlist_code
  126. html = self.net.http_GET(Avi).content
  127. final=re.compile('url="(.+?)"').findall(html)[0].replace('&amp;','&')
  128. return "%s|User-Agent=%s"%(final,'Mozilla%2F5.0%20(Windows%20NT%206.1%3B%20rv%3A11.0)%20Gecko%2F20100101%20Firefox%2F11.0')
  129. elif 'firedrive' in host:
  130. Avi = "http://firedrive.com/get_file.php?stream=%s&original=1"%playlist_code
  131. html = self.net.http_GET(Avi).content
  132. final=re.compile('url="(.+?)"').findall(html)[0].replace('&amp;','&')
  133. return "%s|User-Agent=%s"%(final,'Mozilla%2F5.0%20(Windows%20NT%206.1%3B%20rv%3A11.0)%20Gecko%2F20100101%20Firefox%2F11.0')
  134. else:
  135. Avi = "http://sockshare.com/get_file.php?stream=%s&original=1"%playlist_code
  136. html = self.net.http_GET(Avi).content
  137. final=re.compile('url="(.+?)"').findall(html)[0].replace('&amp;','&')
  138. return "%s|User-Agent=%s"%(final,'Mozilla%2F5.0%20(Windows%20NT%206.1%3B%20rv%3A11.0)%20Gecko%2F20100101%20Firefox%2F11.0')
  139.  
  140. #Else grab standard flv link
  141. else:
  142. xml_url = re.sub('/(file|embed)/.+', '/get_file.php?stream=', web_url)
  143. xml_url += playlist_code
  144. html = self.net.http_GET(xml_url).content
  145.  
  146. r = re.search('url="(.+?)"', html)
  147. if r:
  148. flv_url = r.group(1)
  149. else:
  150. raise Exception ('putlocker: stream url not found')
  151.  
  152. return "%s|User-Agent=%s"%(flv_url.replace('&amp;','&'),'Mozilla%2F5.0%20(Windows%20NT%206.1%3B%20rv%3A11.0)%20Gecko%2F20100101%20Firefox%2F11.0')
  153.  
  154. except urllib2.URLError, e:
  155. common.addon.log_error('Putlocker: got http error %d fetching %s' %
  156. (e.code, web_url))
  157. common.addon.show_small_popup('Error','Http error: '+str(e), 5000, error_logo)
  158. return self.unresolvable(code=3, msg=e)
  159.  
  160. except Exception, e:
  161. common.addon.log_error('**** Putlocker Error occured: %s' % e)
  162. common.addon.show_small_popup(title='[B][COLOR white]PUTLOCKER[/COLOR][/B]', msg='[COLOR red]%s[/COLOR]' % e, delay=5000, image=error_logo)
  163. return self.unresolvable(code=0, msg=e)
  164.  
  165.  
  166. def get_url(self, host, media_id):
  167. if 'putlocker' in host:
  168. host = 'www.putlocker.com'
  169. host = 'www.firedrive.com'
  170. media_id=media_id.replace("#","");
  171. elif 'filedrive' in host:
  172. host = 'www.filedrive.com'
  173. elif 'firedrive' in host:
  174. host = 'www.firedrive.com'
  175. else:
  176. host = 'www.sockshare.com'
  177. host = 'www.firedrive.com'
  178. media_id=media_id.replace("#","");
  179. return 'http://%s/file/%s' % (host, media_id)
  180.  
  181.  
  182. def get_host_and_id(self, url):
  183. r = re.search('//(.+?)/(?:file|embed)/([0-9A-Z]+)', url)
  184. if r:
  185. return r.groups()
  186. else:
  187. return False
  188.  
  189. def valid_url(self, url, host):
  190. if self.get_setting('enabled') == 'false': return False
  191. return (re.match('http://(www.)?(putlocker|filedrive|firedrive|sockshare).com/' + '(file|embed)/[0-9A-Z]+', url) or 'putlocker' in host or 'sockshare' in host or 'filedrive' in host or 'firedrive' in host)
  192.  
  193. def login_stale(self):
  194. url = 'http://www.putlocker.com/cp.php'
  195. if not os.path.exists(self.cookie_file):
  196. return True
  197. self.net.set_cookies(self.cookie_file)
  198. source = self.net.http_GET(url).content
  199. if re.search('(?:<span class=pro_user>\( Pro \)</span>|<span class="free_user">\( Free \)</span>)', source):
  200. common.addon.log('Putlocker account appears to be logged in.')
  201. return False
  202. else:
  203. return True
  204.  
  205. #SiteAuth methods
  206. def login(self):
  207. if self.login_stale():
  208. print 'Need to login since session is invalid'
  209. url = 'http://www.putlocker.com/authenticate.php?login'
  210. source = self.net.http_GET(url).content
  211. self.net.save_cookies(self.cookie_file)
  212. self.net.set_cookies(self.cookie_file)
  213. captcha_img = re.search('<td>CAPTCHA</td>.+?<td><img src="(.+?)" /><br>', source, re.DOTALL).group(1)
  214. captcha_img = 'http://www.putlocker.com%s' %re.sub('&amp;','&',captcha_img)
  215. local_captcha = os.path.join(common.profile_path, "captcha.img" )
  216. localFile = open(local_captcha, "wb")
  217. localFile.write(self.net.http_GET(captcha_img).content)
  218. localFile.close()
  219. solver = InputWindow(captcha=local_captcha)
  220. solution = solver.get()
  221. if solution:
  222. common.addon.log('Solution provided: %s' %solution)
  223. data = {'user':self.get_setting('username'), 'pass':self.get_setting('password'), 'captcha_code':solution, 'remember':1, 'login_submit':'Login'}
  224. response = self.net.http_POST(url, form_data=data)
  225. self.net.save_cookies(self.cookie_file)
  226. self.net.set_cookies(self.cookie_file)
  227. print response.get_url()
  228. else:
  229. common.addon.log('Dialog was canceled')
  230. return False
  231.  
  232.  
  233. if re.search('OK', source):
  234. self.net.save_cookies(self.cookie_file)
  235. self.net.set_cookies(self.cookie_file)
  236. xbmc.executebuiltin("Notification(' Putlocker Pro ', ' Login successful')")
  237. return True
  238. else: return False
  239. else: return True
  240.  
  241. #PluginSettings methods
  242. def get_settings_xml(self):
  243. xml = PluginSettings.get_settings_xml(self)
  244. xml += '<setting label="Highest Quality" id="%s_quality" ' % self.__class__.__name__
  245. xml += 'type="enum" values="FLV|Maximum" default="0" />\n'
  246. xml += '<setting id="%s_login" ' % self.__class__.__name__
  247. xml += 'type="bool" label="login" default="false"/>\n'
  248. xml += '<setting id="%s_username" enable="eq(-1,true)" ' % self.__class__.__name__
  249. xml += 'type="text" label="username" default=""/>\n'
  250. xml += '<setting id="%s_password" enable="eq(-2,true)" ' % self.__class__.__name__
  251. xml += 'type="text" label="password" option="hidden" default=""/>\n'
  252. xml += '<setting id="%s_notify" ' % self.__class__.__name__
  253. xml += 'type="bool" label="Notify on login" default="false"/>\n'
  254. return xml
  255.  
  256. class InputWindow(xbmcgui.WindowDialog):
  257. def __init__(self, *args, **kwargs):
  258. self.cptloc = kwargs.get('captcha')
  259. self.img = xbmcgui.ControlImage(335,30,624,60,self.cptloc)
  260. self.addControl(self.img)
  261. self.kbd = xbmc.Keyboard()
  262.  
  263. def get(self):
  264. self.show()
  265. time.sleep(5)
  266. self.kbd.doModal()
  267. if (self.kbd.isConfirmed()):
  268. text = self.kbd.getText()
  269. self.close()
  270. return text
  271. self.close()
  272. return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement