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

videomailresolver.py 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # -*- coding: UTF-8 -*-
  2. #/*
  3. # * Copyright (C) 2016 mx3L & lzoubek
  4. # *
  5. # *
  6. # * This Program is free software; you can redistribute it and/or modify
  7. # * it under the terms of the GNU General Public License as published by
  8. # * the Free Software Foundation; either version 2, or (at your option)
  9. # * any later version.
  10. # *
  11. # * This Program is distributed in the hope that it will be useful,
  12. # * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # * GNU General Public License for more details.
  15. # *
  16. # * You should have received a copy of the GNU General Public License
  17. # * along with this program; see the file COPYING. If not, write to
  18. # * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19. # * http://www.gnu.org/copyleft/gpl.html
  20. # *
  21. # */
  22. import re, util,urllib2
  23. __name__ = 'videomail'
  24. def supports(url):
  25. return not _regex(url) == None
  26. # returns the steam url
  27. def resolve(url):
  28. m = _regex(url)
  29. if m:
  30. items = []
  31. vurl = m.group('url')
  32. vurl = re.sub('\&[^$]*','',vurl)
  33. vurl = re.sub('/embed','',vurl)
  34. vurl = 'http://videoapi.my.mail.ru/' + vurl + '.json'
  35. util.init_urllib()
  36. req = urllib2.Request(vurl)
  37. req.add_header('User-Agent', util.UA)
  38. resp = urllib2.urlopen(req)
  39. data = resp.read()
  40. vkey = []
  41. for cookie in re.finditer('(video_key=[^\;]+)',resp.headers.get('Set-Cookie'),re.IGNORECASE | re.DOTALL):
  42. vkey.append(cookie.group(1))
  43. headers = {'Cookie':vkey[-1]}
  44. item = util.json.loads(data)
  45. for v in item[u'videos']:
  46. quality = v['key']
  47. link = v['url']
  48. items.append({'quality':quality, 'url':link, 'headers':headers})
  49. return items
  50. def _regex(url):
  51. m1 = re.search('http://.+?mail\.ru.+?<param.+?value=\"movieSrc=(?P<url>[^\"]+)', url, re.IGNORECASE | re.DOTALL)
  52. m2 = re.search('://video.+?\.mail\.ru\/(?P<url>.+?)\.html', url, re.IGNORECASE | re.DOTALL)
  53. return m1 or m2