Kodi plugin to to play various online streams (mostly Latvian)

resolver.py 5.3KB

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