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

exashareresolver.py 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: UTF-8 -*-
  2. # /*
  3. # * Copyright (C) 2015 Lubomir Kucera
  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
  23. import util
  24. #from demjson import demjson
  25. import json
  26. __author__ = 'Jose Riha/Lubomir Kucera'
  27. __name__ = 'exashare'
  28. def supports(url):
  29. return re.search(r'exashare\.com/embed\-[^\.]+\.html', url) is not None
  30. def resolve(url):
  31. realurl = re.search(r'<iframe src="([^"]+)".*', util.request(url), re.I | re.S).group(1)
  32. data = re.search(r'<script[^\.]+?\.setup\((.+?)\);', util.request(realurl), re.I | re.S)
  33. if data:
  34. data = data.group(1).decode('string_escape')
  35. data = re.sub(r'\w+\(([^\)]+?)\)', r'\1', data) # Strip JS functions
  36. data = re.sub(r': *([^"][a-zA-Z]+)',r':"\1"', data) # Fix incorrect JSON
  37. data = json.loads(data)
  38. if 'sources' in data:
  39. result = []
  40. for source in data['sources']:
  41. if 'tracks' in data:
  42. for track in data['tracks']:
  43. result.append({
  44. 'url': source['file'],
  45. 'subs': track['file'],
  46. 'lang': ' %s subtitles' % track['label']
  47. })
  48. return result
  49. return None