Advertisement
Guest User

firedrive/filedrive/putlocker/sockshare

a guest
Feb 16th, 2014
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.71 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.  
  54. #find session_hash
  55. try:
  56. html = self.net.http_GET(web_url).content
  57.  
  58. #Shortcut for logged in users
  59. pattern = '<a href="(/.+?)" class="download_file_link" style="margin:0px 0px;">Download File</a>'
  60. link = re.search(pattern, html)
  61. if link:
  62. common.addon.log('Direct link found: %s' % link.group(1))
  63. if 'putlocker' in host:
  64. return 'http://www.filedrive.com%s' % link.group(1)
  65. #return 'http://www.putlocker.com%s' % link.group(1)
  66. elif 'filedrive' in host:
  67. return 'http://www.filedrive.com%s' % link.group(1)
  68. elif 'firedrive' in host:
  69. return 'http://www.firedrive.com%s' % link.group(1)
  70.  
  71. if 'firedrive' in host or 'filedrive' in host or 'putlocker' in host:
  72. try:
  73. data = {}; r = re.findall(r'type="hidden" name="(.+?)"\s* value="?(.+?)"/>', html); #data['usr_login']=''
  74. for name, value in r: data[name] = value
  75. #data['imhuman']='Proceed to video'; data['btn_download']='Proceed to video'
  76. #xbmc.sleep(2000)
  77. html = self.net.http_POST(web_url, data).content
  78. except urllib2.URLError, e:
  79. common.addon.log_error(host+': got http error %d fetching 2nd url %s' % (e.code, web_url))
  80. return self.unresolvable(code=3, msg='Exception: %s' % e) #return False
  81. r = re.search('<a href="(.+?)" id=\'external_download\' title=\'Download This File\'>', html)
  82. if r:
  83. return urllib.unquote_plus(r.group(1))
  84. #else:
  85. # common.addon.log_error(host+': stream url not found')
  86. # return self.unresolvable(code=0, msg='no file located') #return False
  87. r = re.search("$.post('(.+?)', function(data) {", html)
  88. if r:
  89. return urllib.unquote_plus(r.group(1))
  90. else:
  91. common.addon.log_error(host+': stream url not found')
  92. return self.unresolvable(code=0, msg='no file located') #return False
  93. else:
  94. r = re.search('value="([0-9a-f]+?)" name="hash"', html)
  95. if r:
  96. session_hash = r.group(1)
  97. else:
  98. raise Exception ('putlocker: session hash not found')
  99. #post session_hash
  100. html = self.net.http_POST(web_url, form_data={'hash': session_hash,
  101. 'confirm': 'Continue as Free User'}).content
  102.  
  103. #find playlist code
  104. r = re.search('\?stream=(.+?)\'', html)
  105. if r:
  106. playlist_code = r.group(1)
  107. else:
  108. r = re.search('key=(.+?)&',html)
  109. playlist_code = r.group(1)
  110.  
  111. #find download link
  112. q = self.get_setting('quality')
  113.  
  114. #Try to grab highest quality link available
  115. if q == '1':
  116. #download & return link.
  117. if 'putlocker' in host:
  118. Avi = "http://putlocker.com/get_file.php?stream=%s&original=1"%playlist_code
  119. html = self.net.http_GET(Avi).content
  120. final=re.compile('url="(.+?)"').findall(html)[0].replace('&amp;','&')
  121. return "%s|User-Agent=%s"%(final,'Mozilla%2F5.0%20(Windows%20NT%206.1%3B%20rv%3A11.0)%20Gecko%2F20100101%20Firefox%2F11.0')
  122. elif 'filedrive' in host:
  123. Avi = "http://filedrive.com/get_file.php?stream=%s&original=1"%playlist_code
  124. html = self.net.http_GET(Avi).content
  125. final=re.compile('url="(.+?)"').findall(html)[0].replace('&amp;','&')
  126. return "%s|User-Agent=%s"%(final,'Mozilla%2F5.0%20(Windows%20NT%206.1%3B%20rv%3A11.0)%20Gecko%2F20100101%20Firefox%2F11.0')
  127. elif 'firedrive' in host:
  128. Avi = "http://firedrive.com/get_file.php?stream=%s&original=1"%playlist_code
  129. html = self.net.http_GET(Avi).content
  130. final=re.compile('url="(.+?)"').findall(html)[0].replace('&amp;','&')
  131. return "%s|User-Agent=%s"%(final,'Mozilla%2F5.0%20(Windows%20NT%206.1%3B%20rv%3A11.0)%20Gecko%2F20100101%20Firefox%2F11.0')
  132. else:
  133. Avi = "http://sockshare.com/get_file.php?stream=%s&original=1"%playlist_code
  134. html = self.net.http_GET(Avi).content
  135. final=re.compile('url="(.+?)"').findall(html)[0].replace('&amp;','&')
  136. return "%s|User-Agent=%s"%(final,'Mozilla%2F5.0%20(Windows%20NT%206.1%3B%20rv%3A11.0)%20Gecko%2F20100101%20Firefox%2F11.0')
  137.  
  138. #Else grab standard flv link
  139. else:
  140. xml_url = re.sub('/(file|embed)/.+', '/get_file.php?stream=', web_url)
  141. xml_url += playlist_code
  142. html = self.net.http_GET(xml_url).content
  143.  
  144. r = re.search('url="(.+?)"', html)
  145. if r:
  146. flv_url = r.group(1)
  147. else:
  148. raise Exception ('putlocker: stream url not found')
  149.  
  150. 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')
  151.  
  152. except urllib2.URLError, e:
  153. common.addon.log_error('Putlocker: got http error %d fetching %s' %
  154. (e.code, web_url))
  155. common.addon.show_small_popup('Error','Http error: '+str(e), 5000, error_logo)
  156. return self.unresolvable(code=3, msg=e)
  157.  
  158. except Exception, e:
  159. common.addon.log_error('**** Putlocker Error occured: %s' % e)
  160. common.addon.show_small_popup(title='[B][COLOR white]PUTLOCKER[/COLOR][/B]', msg='[COLOR red]%s[/COLOR]' % e, delay=5000, image=error_logo)
  161. return self.unresolvable(code=0, msg=e)
  162.  
  163.  
  164. def get_url(self, host, media_id):
  165. if 'putlocker' in host:
  166. host = 'www.putlocker.com'
  167. #host = 'www.firedrive.com'
  168. elif 'filedrive' in host:
  169. host = 'www.filedrive.com'
  170. elif 'firedrive' in host:
  171. host = 'www.firedrive.com'
  172. else:
  173. host = 'www.sockshare.com'
  174. return 'http://%s/file/%s' % (host, media_id)
  175.  
  176.  
  177. def get_host_and_id(self, url):
  178. r = re.search('//(.+?)/(?:file|embed)/([0-9A-Z]+)', url)
  179. if r:
  180. return r.groups()
  181. else:
  182. return False
  183.  
  184. def valid_url(self, url, host):
  185. if self.get_setting('enabled') == 'false': return False
  186. 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)
  187.  
  188. def login_stale(self):
  189. url = 'http://www.putlocker.com/cp.php'
  190. if not os.path.exists(self.cookie_file):
  191. return True
  192. self.net.set_cookies(self.cookie_file)
  193. source = self.net.http_GET(url).content
  194. if re.search('(?:<span class=pro_user>\( Pro \)</span>|<span class="free_user">\( Free \)</span>)', source):
  195. common.addon.log('Putlocker account appears to be logged in.')
  196. return False
  197. else:
  198. return True
  199.  
  200. #SiteAuth methods
  201. def login(self):
  202. if self.login_stale():
  203. print 'Need to login since session is invalid'
  204. url = 'http://www.putlocker.com/authenticate.php?login'
  205. source = self.net.http_GET(url).content
  206. self.net.save_cookies(self.cookie_file)
  207. self.net.set_cookies(self.cookie_file)
  208. captcha_img = re.search('<td>CAPTCHA</td>.+?<td><img src="(.+?)" /><br>', source, re.DOTALL).group(1)
  209. captcha_img = 'http://www.putlocker.com%s' %re.sub('&amp;','&',captcha_img)
  210. local_captcha = os.path.join(common.profile_path, "captcha.img" )
  211. localFile = open(local_captcha, "wb")
  212. localFile.write(self.net.http_GET(captcha_img).content)
  213. localFile.close()
  214. solver = InputWindow(captcha=local_captcha)
  215. solution = solver.get()
  216. if solution:
  217. common.addon.log('Solution provided: %s' %solution)
  218. data = {'user':self.get_setting('username'), 'pass':self.get_setting('password'), 'captcha_code':solution, 'remember':1, 'login_submit':'Login'}
  219. response = self.net.http_POST(url, form_data=data)
  220. self.net.save_cookies(self.cookie_file)
  221. self.net.set_cookies(self.cookie_file)
  222. print response.get_url()
  223. else:
  224. common.addon.log('Dialog was canceled')
  225. return False
  226.  
  227.  
  228. if re.search('OK', source):
  229. self.net.save_cookies(self.cookie_file)
  230. self.net.set_cookies(self.cookie_file)
  231. xbmc.executebuiltin("Notification(' Putlocker Pro ', ' Login successful')")
  232. return True
  233. else: return False
  234. else: return True
  235.  
  236. #PluginSettings methods
  237. def get_settings_xml(self):
  238. xml = PluginSettings.get_settings_xml(self)
  239. xml += '<setting label="Highest Quality" id="%s_quality" ' % self.__class__.__name__
  240. xml += 'type="enum" values="FLV|Maximum" default="0" />\n'
  241. xml += '<setting id="%s_login" ' % self.__class__.__name__
  242. xml += 'type="bool" label="login" default="false"/>\n'
  243. xml += '<setting id="%s_username" enable="eq(-1,true)" ' % self.__class__.__name__
  244. xml += 'type="text" label="username" default=""/>\n'
  245. xml += '<setting id="%s_password" enable="eq(-2,true)" ' % self.__class__.__name__
  246. xml += 'type="text" label="password" option="hidden" default=""/>\n'
  247. xml += '<setting id="%s_notify" ' % self.__class__.__name__
  248. xml += 'type="bool" label="Notify on login" default="false"/>\n'
  249. return xml
  250.  
  251. class InputWindow(xbmcgui.WindowDialog):
  252. def __init__(self, *args, **kwargs):
  253. self.cptloc = kwargs.get('captcha')
  254. self.img = xbmcgui.ControlImage(335,30,624,60,self.cptloc)
  255. self.addControl(self.img)
  256. self.kbd = xbmc.Keyboard()
  257.  
  258. def get(self):
  259. self.show()
  260. time.sleep(5)
  261. self.kbd.doModal()
  262. if (self.kbd.isConfirmed()):
  263. text = self.kbd.getText()
  264. self.close()
  265. return text
  266. self.close()
  267. return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement