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

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