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

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