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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 resolve(url):
  50. """
  51. resolves given url by asking all resolvers
  52. returns Array of resolved objects in positive usecase
  53. """
  54. url = util.decode_html(url)
  55. util.info('Resolving ' + url)
  56. resolver = _get_resolver(url)
  57. if resolver is None:
  58. return []
  59. util.info('Using resolver \'%s\'' % str(resolver.__name__));
  60. value = resolver.resolve(url)
  61. if not value:
  62. return []
  63. default = util.item()
  64. for i in value:
  65. i["resolver"] = resolver.__name__
  66. if 'name' not in i.keys():
  67. i['name'] = resolver.__name__
  68. i['surl'] = url
  69. for key in default.keys():
  70. if key not in i.keys():
  71. i[key] = default[key]
  72. if "|" in i["url"]:
  73. headers = i["url"].split("|")[1]
  74. i["url"]=i["url"].split("|")[0]
  75. for h in headers.split("&"):
  76. if "=" in h:
  77. i["headers"][h.split("=")[0]] = h.split("=")[1]
  78. return sorted(value, key=lambda i: i['quality'], reverse=True) # TODO sorted by order?
  79. def _get_resolver(url):
  80. util.debug('Get resolver for ' + url)
  81. for r in RESOLVERS:
  82. util.debug('querying %s' % r)
  83. if r.supports(url):
  84. return r
  85. def can_resolve(url):
  86. """ Returns true if we are able to resolve stream by given URL """
  87. return _get_resolver(url) is not None
  88. if __name__ == "__main__":
  89. from subprocess import call
  90. #url = "http://hqq.tv/player/embed_player.php?vid=235238210241210222228241233208212245&autoplay=no"
  91. #url = "http://hqq.tv/player/embed_player.php?vid=243221241234244238208213206212211231&autoplay=no"
  92. url = "http://hqq.tv/player/embed_player.php?vid=208231211231207221227243206206221244&autoplay=no"
  93. #url = "https://openload.co/embed/TMthIdpy4PI/"
  94. #url = "https://www.youtube.com/watch?v=Tx1K51_F99o"
  95. #url = "https://www.youtube.com/watch?v=8BkcX7O1890"
  96. #url = "https://www.youtube.com/watch?v=Se07R8SYsg0"
  97. #url = "https://kinostok.tv/embed/731f3437e3c53104dd56d04039a0b15a"
  98. #url = "http://vk.com/video_ext.php?oid=246066565&id=169244575&hash=d430ab0e76c9f7a1&hd=3"
  99. #url ="https://openload.co/embed/rPMXJYPTkw4/"
  100. #url = "https://openload.co/embed/bE7WfZ-vz_A/"
  101. #url = "https://openload.co/embed/bE7WfZ/"
  102. #url = "https://openload.co/embed/OuskaKyC2GU/"
  103. url = "http://hqq.tv/player/embed_player.php?vid=235238210241210222228241233208212245&autoplay=no"
  104. url = "https://hqq.tv/player/embed_player.php?vid=235242211228257255206246241253244213194271217261258"
  105. #url = "https://openload.co/embed/rmNcP-0QopE/"
  106. #url = "https://openload.co/embed/gpLF6Grzy80/"
  107. #url = "https://openload.co/embed/oQLXcU1ITAY/"
  108. #url = "http://hqq.tv/player/embed_player.php?vid=245208228234224222241224221239207212&autoplay=no"
  109. url = "https://goo.gl/yMTzqf"
  110. url = "http://cdn.kapnob.ru/video/5e67c8b1ad018ffa/iframe"
  111. url = "http://kodik.cc/video/10830/4269a802d1a9d9bdc53fe38488d53a52/720p"
  112. streams = resolve(url)
  113. if not streams:
  114. print "No streams found"
  115. sys.exit()
  116. for s in streams:
  117. print s
  118. print streams[0]["url"]
  119. util.play_video(streams)
  120. ##call([r"c:\Program Files\VideoLAN\VLC\vlc.exe",streams[0]["url"]])
  121. pass