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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. # * Copyright (C) 2011 Libor Zoubek
  2. # * Modified by ivars777
  3. # * Based in code from https://github.com/kodi-czsk/script.module.stream.resolver
  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. # Based in code from https://github.com/kodi-czsk/script.module.stream.resolver
  23. import re
  24. import traceback
  25. import util
  26. import sys,os
  27. #sys.path.insert(0,os.path.dirname(os.path.abspath(__file__)))
  28. server_path = "resolvers"
  29. sys.path.append(os.path.join(os.path.dirname(__file__), server_path))
  30. RESOLVERS = []
  31. util.debug('%s searching for modules' % __name__)
  32. for module in os.listdir(os.path.join(os.path.dirname(__file__), server_path)):
  33. if module == '__init__.py' or module[-3:] != '.py':
  34. continue
  35. module = module[:-3]
  36. #exec 'import %s' % module
  37. #resolver = eval(module)
  38. resolver = __import__(module)
  39. #reload(resolver)
  40. if not hasattr(resolver, 'resolve'):
  41. continue
  42. print 'found %s %s' % (resolver, dir(resolver))
  43. #util.debug('found %s %s' % (resolver, dir(resolver)))
  44. if not hasattr(resolver, '__priority__'):
  45. resolver.__priority__ = 0
  46. RESOLVERS.append(resolver)
  47. del module
  48. RESOLVERS = sorted(RESOLVERS, key=lambda m: -m.__priority__)
  49. def item():
  50. stream0 = {'name': '', 'url': '', 'quality': '???', 'surl': '', 'subs': '', 'headers': {},"desc":"","img":"","lang":"","type":"","order":0}
  51. return stream0
  52. def resolve(url):
  53. """
  54. resolves given url by asking all resolvers
  55. returns None if no resolver advised to be able to resolve this url
  56. returns False if resolver did his job, but did not return any value (thus failed)
  57. returns Array of resolved objects in positive usecase
  58. """
  59. url = util.decode_html(url)
  60. util.info('Resolving ' + url)
  61. resolver = _get_resolver(url)
  62. value = None
  63. if resolver is None:
  64. return []
  65. util.info('Using resolver \'%s\'' % str(resolver.__name__));
  66. value = resolver.resolve(url)
  67. if not value:
  68. return []
  69. default = item()
  70. for i in value:
  71. i["resolver"] = resolver.__name__
  72. if 'name' not in i.keys():
  73. i['name'] = resolver.__name__
  74. i['surl'] = url
  75. for key in default.keys():
  76. if key not in i.keys():
  77. i[key] = default[key]
  78. if "|" in i["url"]:
  79. headers = i["url"].split("|")[1]
  80. i["url"]=i["url"].split("|")[0]
  81. for h in headers.split("&"):
  82. if "=" in h:
  83. i["headers"][h.split("=")[0]] = h.split("=")[1]
  84. return sorted(value, key=lambda i: i['quality'], reverse=True)
  85. def _get_resolver(url):
  86. util.debug('Get resolver for ' + url)
  87. for r in RESOLVERS:
  88. util.debug('querying %s' % r)
  89. if r.supports(url):
  90. return r
  91. def can_resolve(url):
  92. """ Returns true if we are able to resolve stream by given URL """
  93. return _get_resolver(url) is not None
  94. if __name__ == "__main__":
  95. from subprocess import call
  96. #url = "http://hqq.tv/player/embed_player.php?vid=235238210241210222228241233208212245&autoplay=no"
  97. #url = "http://hqq.tv/player/embed_player.php?vid=243221241234244238208213206212211231&autoplay=no"
  98. url = "http://hqq.tv/player/embed_player.php?vid=208231211231207221227243206206221244&autoplay=no"
  99. #url = "https://openload.co/embed/TMthIdpy4PI/"
  100. #url = "https://www.youtube.com/watch?v=Tx1K51_F99o"
  101. #url = "https://www.youtube.com/watch?v=8BkcX7O1890"
  102. #url = "https://www.youtube.com/watch?v=Se07R8SYsg0"
  103. #url = "https://kinostok.tv/embed/731f3437e3c53104dd56d04039a0b15a"
  104. #url = "http://vk.com/video_ext.php?oid=246066565&id=169244575&hash=d430ab0e76c9f7a1&hd=3"
  105. #url ="https://openload.co/embed/rPMXJYPTkw4/"
  106. #url = "https://openload.co/embed/bE7WfZ-vz_A/"
  107. #url = "https://openload.co/embed/bE7WfZ/"
  108. #url = "https://openload.co/embed/OuskaKyC2GU/"
  109. url = "http://hqq.tv/player/embed_player.php?vid=235238210241210222228241233208212245&autoplay=no"
  110. url = "https://hqq.tv/player/embed_player.php?vid=235242211228257255206246241253244213194271217261258"
  111. #url = "https://openload.co/embed/rmNcP-0QopE/"
  112. #url = "https://openload.co/embed/gpLF6Grzy80/"
  113. #url = "https://openload.co/embed/oQLXcU1ITAY/"
  114. #url = "http://hqq.tv/player/embed_player.php?vid=245208228234224222241224221239207212&autoplay=no"
  115. url = "https://goo.gl/yMTzqf"
  116. url = "http://cdn.kapnob.ru/video/5e67c8b1ad018ffa/iframe"
  117. url = "http://kodik.cc/video/10830/4269a802d1a9d9bdc53fe38488d53a52/720p"
  118. streams = resolve(url)
  119. if not streams:
  120. print "No streams found"
  121. sys.exit()
  122. for s in streams:
  123. print s
  124. print streams[0]["url"]
  125. util.play_video(streams)
  126. ##call([r"c:\Program Files\VideoLAN\VLC\vlc.exe",streams[0]["url"]])
  127. pass