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

streamujtvresolver.py 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # * GNU General Public License for more details.
  2. # *
  3. # * You should have received a copy of the GNU General Public License
  4. # * along with this program; see the file COPYING. If not, write to
  5. # * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  6. # * http://www.gnu.org/copyleft/gpl.html
  7. # *
  8. # */
  9. import re,util
  10. import simplejson as json
  11. from base64 import b64decode, b64encode
  12. __name__='streamujtv'
  13. def supports(url):
  14. return not _regex(url) == None
  15. # returns the steam url
  16. def resolve(url):
  17. m = _regex(url)
  18. if m:
  19. data = util.request(url)
  20. if data.find('Toto video neexistuje') > 0:
  21. util.error('Video bylo smazano ze serveru')
  22. return
  23. player = 'http://www.streamuj.tv/new-flash-player/mplugin4.swf'
  24. headers = {'User-Agent':'Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0',
  25. 'Referer':'http://www.streamuj.tv/mediaplayer/player.swf'}
  26. burl = b64decode('aHR0cDovL2Z1LWNlY2gucmhjbG91ZC5jb20vcGF1dGg=')
  27. key = util.request('http://www.streamuj.tv/_key.php?auth=3C27f5wk6qB3g7nZ5SDYf7P7k1572rFH1QxV0QQ')
  28. index = 0
  29. result = []
  30. qualities = re.search('rn\:[^\"]*\"([^\"]*)',data,re.IGNORECASE|re.DOTALL)
  31. langs = re.search('langs\:[^\"]*\"([^\"]+)',data,re.IGNORECASE|re.DOTALL)
  32. languages = []
  33. if not langs:
  34. languages = [''] # pretend there is at least language so we read 1st stream info
  35. else:
  36. languages = langs.group(1).split(',')
  37. for lang in languages:
  38. streams = re.search('res'+str(index)+'\:[^\"]*\"([^\"]+)',data,re.IGNORECASE|re.DOTALL)
  39. subs = re.search('sub'+str(index)+'\:[^\"]*\"([^\"]+)',data,re.IGNORECASE|re.DOTALL)
  40. if subs:
  41. subs = re.search('[^>]+>([^$]+)',subs.group(1),re.IGNORECASE|re.DOTALL)
  42. if streams and qualities:
  43. streams = streams.group(1).split(',')
  44. rn = qualities.group(1).split(',')
  45. qindex = 0
  46. for stream in streams:
  47. res = json.loads(util.post_json(burl,{'link':stream,'player':player,'key':key}))
  48. stream = res['link']
  49. q = rn[qindex]
  50. if q == 'HD':
  51. q = '720p'
  52. else:
  53. q = 'SD'
  54. l = ' '+lang
  55. if subs:
  56. l += ' + subs'
  57. s = subs.group(1)
  58. s = json.loads(util.post_json(burl,{'link':s,'player':player, 'key':key}))
  59. result.append({'url':stream,'quality':q,'subs':s['link'],'headers':headers,'lang':l})
  60. else:
  61. result.append({'url':stream,'quality':q,'headers':headers, 'lang':l})
  62. qindex+=1
  63. index+=1
  64. return result
  65. def _regex(url):
  66. return re.search('streamuj\.tv/video/',url,re.IGNORECASE | re.DOTALL)