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

kapnob.py 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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__ = 'kapnob'
  36. headers2dict = lambda h: dict([l.strip().split(": ") for l in h.strip().splitlines()])
  37. headers = headers2dict("""
  38. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
  39. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  40. Accept-Language: en-US,en;q=0.5
  41. """)
  42. def supports(url):
  43. return True if "kapnob.ru" in url else False
  44. def resolve(url):
  45. HTTP_HEADER = {
  46. 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0',
  47. 'Referer': url} # 'Connection': 'keep-alive'
  48. stream = util.item()
  49. data = requests.get(url,headers = HTTP_HEADER).content
  50. m = re.search(r'subtitles: \[\s+{\s+src: "(.+?)",\s+label: "(.+?)",\s+language: "(.+?)"', data, re.DOTALL)
  51. if m:
  52. sub = {}
  53. sub["url"] = m.group(1)
  54. sub["name"] = m.group(2)
  55. sub["lang"] = m.group(3)
  56. sub["type"] = "srt"
  57. stream["subs"]=[sub]
  58. video_token = re.search("video_token: '(.+?)'",data).group(1)
  59. content_type = re.search("content_type: '(.+?)'",data).group(1)
  60. mw_key = re.search("mw_key: '(.+?)'",data).group(1)
  61. mw_domain_id = re.search("mw_domain_id: (\d+)",data).group(1)
  62. uuid = re.search("uuid: '(.+?)'",data).group(1)
  63. params = "video_token=%s&content_type=%s&mw_key=%s&mw_pid=&mw_domain_id=%s&ad_attr=0&debug=false&uuid=%s"%(
  64. video_token,content_type,mw_key,mw_domain_id,uuid)
  65. headers = headers2dict("""
  66. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0
  67. Content-Type: application/x-www-form-urlencoded; charset=UTF-8
  68. X-Iframe-Option: Direct
  69. X-Requested-With: XMLHttpRequest
  70. """)
  71. data = requests.post("http://cdn.kapnob.ru/sessions/new_session", data=params,headers=headers).content
  72. js = json.loads(data)
  73. stream["url"] = js["mans"]["manifest_m3u8"]
  74. stream["name"]= stream["url"]
  75. return [stream]
  76. if __name__ == "__main__":
  77. url = "http://cdn.kapnob.ru/video/5e67c8b1ad018ffa/iframe"
  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