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

kapnob.py 3.3KB

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