Python module (submodule repositary), which provides content (video streams) from various online stream sources to corresponding Enigma2, Kodi, Plex plugins

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # -*- coding: UTF-8 -*-
  2. # /*
  3. # * Copyright (C) 2016 Ivars777
  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,os,sys
  23. import json
  24. try:
  25. import util
  26. except:
  27. pp = os.path.dirname(os.path.abspath(__file__))
  28. sys.path.insert(0,os.sep.join(pp.split(os.sep)[:-1]))
  29. import util
  30. import requests
  31. try:
  32. from requests.packages.urllib3.exceptions import InsecureRequestWarning
  33. requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
  34. except:
  35. pass
  36. __author__ = 'ivars777'
  37. if __name__ <> "__main__":
  38. __name__ = 'kodik'
  39. headers2dict = lambda h: dict([l.strip().split(": ") for l in h.strip().splitlines()])
  40. headers0 = headers2dict("""
  41. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0
  42. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  43. Upgrade-Insecure-Requests: 1
  44. DNT: 1
  45. Connection: keep-alive
  46. Upgrade-Insecure-Requests: 1
  47. Cache-Control: max-age=0
  48. """)
  49. def supports(url):
  50. return True if "kodik.cc" in url else False
  51. def resolve(url):
  52. global headers0
  53. streams = []
  54. try:
  55. r = requests.get(url,headers=headers0)
  56. except:
  57. return []
  58. if r.status_code<>200:
  59. return []
  60. data = r.content
  61. hash = re.search('hash: "(.+?)"',data).group(1)
  62. vid = re.search('id: "(.+?)"',data).group(1)
  63. quality = re.search('quality: "(.+?)"',data).group(1)
  64. params = "domain=&url=&type=database&hash=%s&id=%s&quality=%s"%(hash,vid,quality)
  65. headers = headers2dict("""
  66. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0
  67. Accept: application/json, text/javascript, */*; q=0.01
  68. Content-Type: application/x-www-form-urlencoded; charset=UTF-8
  69. X-Requested-With: XMLHttpRequest
  70. Referer: %s
  71. """%url)
  72. data = requests.post("http://kodik.cc/get-video", data=params,headers=headers).content
  73. js = json.loads(data)
  74. for st in js["qualities"]:
  75. stream = util.item()
  76. stream["url"] = js["qualities"][st]["src"]
  77. stream["quality"]=int(st)
  78. stream["name"]= stream["url"]
  79. streams.append(stream)
  80. return streams
  81. if __name__ == "__main__":
  82. url = "http://kodik.cc/video/10830/4269a802d1a9d9bdc53fe38488d53a52/720p"
  83. streams = resolve(url)
  84. if not streams:
  85. print "No streams found"
  86. sys.exit()
  87. for s in streams:
  88. print s
  89. print streams[0]["url"]
  90. util.play_video(streams)
  91. pass