Enigma2 plugin to to play various online streams (mostly Latvian).

putlockerresolver.py 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # -*- coding: UTF-8 -*-
  2. # *
  3. # *
  4. # * This Program is free software; you can redistribute it and/or modify
  5. # * it under the terms of the GNU General Public License as published by
  6. # * the Free Software Foundation; either version 2, or (at your option)
  7. # * any later version.
  8. # *
  9. # * This Program is distributed in the hope that it will be useful,
  10. # * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # * GNU General Public License for more details.
  13. # *
  14. # * You should have received a copy of the GNU General Public License
  15. # * along with this program; see the file COPYING. If not, write to
  16. # * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17. # * http://www.gnu.org/copyleft/gpl.html
  18. # *
  19. # *
  20. # */
  21. # thanks to:
  22. # https://github.com/Eldorados
  23. import re,util,os
  24. __name__ = 'putlocker'
  25. def supports(url):
  26. return not _regex(url) == None
  27. def get_host_and_id(url):
  28. r = re.search('//(.+?)/(?:file|embed)/([0-9A-Z]+)', url)
  29. if r:
  30. return r.groups()
  31. else:
  32. return False
  33. def get_host(host,media_id):
  34. #host,media_id=get_host_and_id(url)
  35. if 'putlocker' in host:
  36. host = 'www.putlocker.com'
  37. else:
  38. host = 'www.sockshare.com'
  39. return 'http://%s/file/%s' % (host, media_id)
  40. def login_stale():
  41. url = 'http://www.putlocker.com/cp.php'
  42. if not os.path.exists(cookie_file):
  43. return True
  44. #self.net.set_cookies(cookie_file)
  45. source = util.request(url)
  46. if re.search('(?:<span class=pro_user>\( Pro \)</span>|<span class="free_user">\( Free \)</span>)', source):
  47. print ('Putlocker account appears to be logged in.')
  48. return False
  49. else:
  50. return True
  51. # returns the steam url
  52. def url(url):
  53. if supports(url):
  54. '''
  55. if self.get_setting('login') == 'true':
  56. if login_stale():
  57. login()
  58. #self.net.set_cookies(cookie_file)
  59. '''
  60. host,media_id=get_host_and_id(url)
  61. web_url = get_host(host,media_id)
  62. #find session_hash
  63. try:
  64. html = util.request(web_url)
  65. except urllib2.URLError, e:
  66. print ('putlocker: got http error %d fetching %s' % (e.code, web_url))
  67. return False
  68. #Shortcut for logged in users
  69. pattern = '<a href="(/.+?)" class="download_file_link" style="margin:0px 0px;">Download File</a>'
  70. link = re.search(pattern, html)
  71. if link:
  72. print 'Direct link found: %s' %link.group(1)
  73. return 'http://www.putlocker.com%s' %link.group(1)
  74. r = re.search('value="([0-9a-f]+?)" name="hash"', html)
  75. if r:
  76. session_hash = r.group(1)
  77. else:
  78. print ('putlocker: session hash not found')
  79. return False
  80. #post session_hash
  81. try:
  82. html = util.post(web_url, {'hash': session_hash,'confirm': 'Continue as Free User'})
  83. except urllib2.URLError, e:
  84. print ('putlocker: got http error %d posting %s' %(e.code, web_url))
  85. return False
  86. #find playlist code
  87. r = re.search('\?stream=(.+?)\'', html)
  88. if r:
  89. playlist_code = r.group(1)
  90. else:
  91. r = re.search('key=(.+?)&',html)
  92. playlist_code = r.group(1)
  93. #find download link
  94. #q = self.get_setting('quality')
  95. q = '1'
  96. #Try to grab highest quality link available
  97. if q == '1':
  98. #download & return link.
  99. if 'putlocker' in host:
  100. Avi = "http://putlocker.com/get_file.php?stream=%s&original=1"%playlist_code
  101. html = util.request(Avi)
  102. final=re.compile('url="(.+?)"').findall(html)[0].replace('&amp;','&')
  103. return [final]
  104. else:
  105. Avi = "http://sockshare.com/get_file.php?stream=%s&original=1"%playlist_code
  106. html = util.request(Avi)
  107. final=re.compile('url="(.+?)"').findall(html)[0].replace('&amp;','&')
  108. return [final]
  109. #Else grab standard flv link
  110. else:
  111. xml_url = re.sub('/(file|embed)/.+', '/get_file.php?stream=', web_url)
  112. xml_url += playlist_code
  113. try:
  114. html = util.request(xml_url)
  115. except urllib2.URLError, e:
  116. pritn ('putlocker: got http error %d fetching %s'(e.code, xml_url))
  117. return False
  118. r = re.search('url="(.+?)"', html)
  119. if r:
  120. flv_url = r.group(1)
  121. else:
  122. print ('putlocker: stream url not found')
  123. return False
  124. return [flv_url.replace('&amp;','&')]
  125. def resolve(u):
  126. stream = url(u)
  127. if stream:
  128. return [{'name':__name__,'quality':'360p','url':stream[0],'surl':u}]
  129. def _regex(url):
  130. return re.search('http://(www.)?(putlocker|sockshare).com/' + '(file|embed)/[0-9A-Z]+', url,re.IGNORECASE | re.DOTALL)