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

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