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

xtv.py 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #!/usr/bin/env python
  2. # coding=utf8
  3. #
  4. # This file is part of PlayStream - enigma2 plugin to play video streams from various sources
  5. # Copyright (c) 2016 ivars777 (ivars777@gmail.com)
  6. # Distributed under the GNU GPL v3. For full terms see http://www.gnu.org/licenses/gpl-3.0.en.html
  7. #
  8. try:
  9. import json
  10. except:
  11. import simplejson as json
  12. import urllib2, urllib
  13. import datetime, re, sys, os
  14. import ssl
  15. if "_create_unverified_context" in dir(ssl):
  16. ssl._create_default_https_context = ssl._create_unverified_context
  17. try:
  18. import util
  19. except:
  20. sys.path.insert(0,'..')
  21. import util
  22. from SourceBase import SourceBase
  23. headers2dict = lambda h: dict([l.strip().split(": ") for l in h.strip().splitlines()])
  24. re_search = lambda p, s: re.search( p, s, re.DOTALL).group(1).strip() if re.search( p, s, re.DOTALL) else ""
  25. headers0 = headers2dict("""
  26. User-Agent: Mozilla/5.0 (Linux; U; Android 4.4.4; Nexus 5 Build/KTU84P) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
  27. """)
  28. import HTMLParser
  29. h = HTMLParser.HTMLParser()
  30. class Source(SourceBase):
  31. def __init__(self,country="lv",cfg_path=None):
  32. self.name = "xtv"
  33. self.title = "XTV.lv"
  34. self.img = "xtv.png"
  35. self.desc = "xtv.lv satura skatīšanās (TVRiga24,360TV,STV)"
  36. self.country=country
  37. def get_content(self, data):
  38. print "[xtv] get_content:", data
  39. source, data, path, plist, clist, params, qs = self.parse_data(data)
  40. content = []
  41. content.append(("..return", "back","back.png","Return back"))
  42. if clist=="home":
  43. content.extend([
  44. ("Jaunākie", "xtv::latest", self.img,"Jaunākie video"),
  45. ("Populārakie", "xtv::popular",self.img,"Populāraie video"),
  46. ("Visi raidījumi", "xtv::programs",self.img,"Visi raidījumi"),
  47. ("Ziņas", "xtv::category/6blmNmLpOPR-zinas/full_show?page=1",self.img,"Ziņu raidījumi un sižeti"),
  48. ("Diskusijas", "xtv::category/AZoQGEwNX89-diskusijas/full_show?page=1",self.img,"Diskusiju raidījumi un sižeti"),
  49. ("Izklaide", "xtv::category/gnPBGaJp8or-izklaide/full_show?page=1",self.img,"Izklaides raidījumi un sižeti"),
  50. ("Sports", "xtv::category/Lymz7BwGXEk-sports/full_show?page=1",self.img,"Sporta raidījumi un sižeti"),
  51. ("Meklēt", "xtv::search?q={0}",self.img,"Meklēt raidījumus un sižetus"),
  52. ])
  53. return content
  54. ### Saraksti ###
  55. elif clist in ("latest", "popular", "category", "programs", "search") or plist[1] == "program":
  56. r = self.call(data)
  57. for r0 in re.findall(r'<div class="(tvplot|broadcast)">(.+?)</a>\s+</div>\s+</div>', r, re.DOTALL):
  58. r2 = r0[1]
  59. title = util.unescape(re_search("<h5>([^<]+)<", r2))
  60. data2 = re_search('href="/(.+?)"', r2)
  61. if "/program/" in data2:
  62. data2 += "/full_show?page=1"
  63. img = re_search('src="(.+?)"', r2)
  64. duration = re_search('<span class="duration">(.+?)</span>', r2)
  65. when = re_search('<span>([^<]+)</span>', r2)
  66. category = re_search('<p>([^<]+)</p>', r2)
  67. chan = re_search('<img alt="(.+?) logo"', r2) # <img alt="RigaTV24 logo"
  68. desc = util.unescape(re_search('title="(.*?)"', r2))
  69. if when or duration:
  70. desc += "\n%s %s" % (when, duration)
  71. if category:
  72. desc += "\n%s" % (category)
  73. if "/video/" in data2:
  74. chan = data2.split("/")[0].upper()
  75. if chan:
  76. title = "%s [%s] " % (title, chan)
  77. content.append((title,self.name+"::"+data2,img,desc))
  78. if "page" in qs:
  79. page = int(qs["page"]) + 1
  80. data2 = re.sub("page=\d+", "page=%s" % page, data)
  81. content.append(("Next page",self.name+"::"+data2,"next.png","Next page"))
  82. return content
  83. ### Meklēt ###
  84. elif data == "search":
  85. return content
  86. else:
  87. return content
  88. def is_video(self,data):
  89. source,data,path,plist,clist,params,qs = self.parse_data(data)
  90. if len(plist) > 1 and plist[1] == "video":
  91. return True
  92. else:
  93. return False
  94. def get_streams(self,data):
  95. print "[xtv] get_streams:", data
  96. if not self.is_video(data):
  97. return []
  98. source,data,path,plist,clist,params,qs = self.parse_data(data)
  99. r = self.call(data)
  100. # src: "https://video.xtv.lv/files/cc/e5/cce5a0e95dea4404280dabb2a8470f0b/original.mp4", type: "video
  101. data2 = re_search('src: "([^"]+)", type: "video', r)
  102. if not data2:
  103. return []
  104. title = util.unescape(re_search('"og:title" content="([^"]+)"', r))
  105. desc = util.unescape(re_search('"description" content="([^"]+)"', r))
  106. img = re_search('"thumbnailUrl": "([^"]+)"', r) # "thumbnailUrl": "
  107. stream = util.item()
  108. stream["name"] = title
  109. stream["url"] = data2
  110. stream["img"] = img
  111. stream["desc"] = desc
  112. stream["lang"] = "lv"
  113. stream["resolver"] = "xtv"
  114. return [stream]
  115. def call(self, data,headers=headers0,lang=""):
  116. API_URL = "https://xtv.lv/"
  117. #if not lang: lang = self.country
  118. url = API_URL + data
  119. content = self._http_request(url)
  120. return content
  121. if __name__ == "__main__":
  122. sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
  123. import run
  124. source = Source()
  125. data= sys.argv[1] if len(sys.argv)>1 else source.name+"::home"
  126. run.run(source, data)
  127. sys.exit()