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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 ConfigParser
  15. from SourceBase import SourceBase
  16. #from collections import OrderedDict
  17. import os
  18. import ssl
  19. if "_create_unverified_context" in dir(ssl):
  20. ssl._create_default_https_context = ssl._create_unverified_context
  21. #sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  22. from resolver import resolve
  23. import util
  24. headers2dict = lambda h: dict([l.strip().split(": ") for l in h.strip().splitlines()])
  25. import HTMLParser
  26. h = HTMLParser.HTMLParser()
  27. class Source(SourceBase):
  28. def __init__(self,country="",cfg_path=None):
  29. self.hidden = True # nerāda menu nestrādājošos avotus
  30. self.name = "cinemalive"
  31. self.title = "cinemalive.tv"
  32. self.img = "picons/cinemalive.png" #"https://cinemalive.tv/assets/img/logo.png"
  33. self.desc = "cinemalive.tv satura skatīšanās"
  34. self.country=country
  35. self.headers = headers2dict("""
  36. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0
  37. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,application/json
  38. """)
  39. self.headers2 = headers2dict("""
  40. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36
  41. Content-Type: application/x-www-form-urlencoded; charset=UTF-8
  42. Accept-Language: en-US,en;q=0.8
  43. """)
  44. self.url = "https://cinemalive.tv/"
  45. #self.login()
  46. ######### Entry point ########
  47. def get_content(self, data):
  48. print "[cinemalive] get_content:", data
  49. source,data,path,plist,clist,params,qs = self.parse_data(data)
  50. content=[]
  51. content.append(("..return", "back","","Return back"))
  52. if clist=="home":
  53. content.extend([
  54. ("Search", "cinemalive::scripts/search.php?search={0}","","Search"),
  55. ("Filmas latviski - visas", "cinemalive::filmaslatviski/visas/lapa/1","","Filmas latviski - visas"),
  56. ("Filmas angliski", "cinemalive::home_en","","Filmas angliski"),
  57. ("Filmas latviski - jaunākās", "cinemalive::filmaslatviski/jaunakas/lapa/1","","Filmas latviski - jaunākās"),
  58. ("Filmas latviski - vertētākās", "cinemalive::filmaslatviski/vertetakas/lapa/1","","Filmas latviski - vērtētākās"),
  59. ("Filmas latviski - skatitakās", "cinemalive::filmaslatviski/skatitakas/lapa/1","","Filmas latviski - skatītākās"),
  60. ])
  61. r = self.call("filmaslatviski")
  62. for item in re.findall(r'<li class="nav-submenu-item"><a href="/([\w/]+)">(.+?)</a></li>', r):
  63. title = "Filmas latviski - "+item[1]
  64. data2 = item[0]+"/lapa/1"
  65. img = self.img
  66. desc = title
  67. content.append((title,self.name+"::"+data2,img,desc))
  68. return content
  69. elif clist=="home_en":
  70. content.extend([
  71. ("Search", "cinemalive::scripts/search.php?search={0}","","Search"),
  72. ("Movies English - all", "cinemalive::moviesenglish/all/page/1","","Movies English - all"),
  73. ("Movies Latvian", "cinemalive::home","","Filmas latviski"),
  74. ("Movies English - newest", "cinemalive::moviesenglish/newestmovies/page/1","","Movies English - newest"),
  75. ("Movies English - top rated", "cinemalive::moviesenglish/toprated/page/1","","Movies English - top rated"),
  76. ("Movies English - most watched", "cinemalive::moviesenglish/mostwatched/page/1","","Movies English - most watched"),
  77. ])
  78. r = self.call("moviesenglish")
  79. for item in re.findall(r'<li class="nav-submenu-item"><a href="/([\w/]+)">(.+?)</a></li>', r):
  80. title = "Movies English - "+item[1]
  81. data2 = item[0]+"/page/1"
  82. img = self.img
  83. desc = title
  84. content.append((title,self.name+"::"+data2,img,desc))
  85. return content
  86. elif "search.php" in data:
  87. r=self.call(path,params=params[1:],headers=self.headers2)
  88. result = re.findall(r'<div class="results.+?<a href="https://cinemalive\.tv/(.+?)">.+?<img src="(.+?)".+?<span style="color:#bcbcbc">([^<]+)</span> <span style="color:#5a606d;font-size:12px;">([^<]+)</span><br/>.+?<p class="dec" style="font-size:12px; color:#777;line-height:14px;">([^<]+)</p>', r, re.DOTALL)
  89. for item in result:
  90. title = item[2]
  91. title0 = re.sub(" \(\d+\)","",title)
  92. if title0 == item[3]:
  93. title = title+" [EN]"
  94. else:
  95. title = title + "/"+ item[3]+" [LV]"
  96. title = util.unescape(title)
  97. data2 = item[0]
  98. img = item[1].replace("xs.","sm.")
  99. desc = util.unescape(item[4])
  100. content.append((title,self.name+"::"+data2,img,desc))
  101. return content
  102. elif clist in ("filmaslatviski","moviesenglish"):
  103. r = self.call(data)
  104. if not r:
  105. return content
  106. result = re.findall(r'<div class="base-used">.+?<a href="https://cinemalive.tv/([^"]+)">.+?<img class="img-thumbnail" src="/([^"]+)" alt="([^"]+)"/>.+?<p class="year">(\d+)</p>', r, re.DOTALL)
  107. for item in result:
  108. title = item[2] + " (%s)"%item[3]
  109. data2 = item[0]
  110. img = "https://cinemalive.tv/"+item[1]
  111. title = util.unescape(title)
  112. desc = title
  113. content.append((title,self.name+"::"+data2,img,desc))
  114. m = re.search(r"""<a href='https://cinemalive\.tv/([^']+)' style="border-right:none;">»</a>""", r, re.DOTALL)
  115. if m:
  116. data2 = m.group(1)
  117. content.append(("Next page",self.name+"::"+data2,self.img,"Next page"))
  118. return content
  119. else:
  120. return content
  121. def is_video(self,data):
  122. source,data,path,plist,clist,params,qs = self.parse_data(data)
  123. if clist=="movie":
  124. return True
  125. else:
  126. return False
  127. def get_streams(self, data):
  128. print "[cinemalive] get_streams:", data
  129. source,data,path,plist,clist,params,qs = self.parse_data(data)
  130. r = self.call(path)
  131. if not r:
  132. return []
  133. streams = []
  134. title0 = re.search("<title>([^<]+)</title>", r).group(1)
  135. lang = "LV" if "Filma Online Latviski" in title0 else "EN"
  136. title = title0.replace(" - Filma Online Latviski","").replace(" - Movie Online English HD","")
  137. desc = re.search('<p class="plot">(.+?)</p>', r).group(1)
  138. img = "http://cinemalive.tv"+re.search('<img src="(.+?)" class="img-thumbnail"', r).group(1)
  139. m = re.search(r'<video id=.+?<source src="([^"]+\.mp4)"', r, re.DOTALL)
  140. if m:
  141. s = util.item()
  142. s["url"] = m.group(1)
  143. s["name"] = util.unescape(title)
  144. s["desc"] = util.unescape(desc)
  145. s["img"] = img
  146. s["type"] = self.stream_type(s["url"])
  147. s["lang"] = lang
  148. return [s]
  149. #m = re.search('<div class="viboom-overroll"><iframe src="([^"]+)"', r)
  150. #if m:
  151. result = re.findall('<div id="video_container"><iframe.+?src="(.+?)"', r)
  152. if result:
  153. streams = resolve(result[0])
  154. for s in streams:
  155. s["name"] = util.unescape(title)
  156. s["desc"] = util.unescape(desc)
  157. s["img"] = img
  158. s["type"] = self.stream_type(s["url"])
  159. s["lang"] = lang
  160. if len(result)>1:
  161. lang2 = "EN" if lang=="LV" else "LV"
  162. streams2 = resolve(result[1])
  163. for s in streams2:
  164. s["name"] = util.unescape(title)
  165. s["desc"] = util.unescape(desc)
  166. s["img"] = img
  167. s["type"]= self.stream_type(s["url"])
  168. s["lang"] = lang2
  169. streams.append(s)
  170. return streams
  171. else:
  172. return []
  173. if __name__ == "__main__":
  174. country= "lv"
  175. c = Source(country)
  176. if len(sys.argv)>1:
  177. data= sys.argv[1]
  178. else:
  179. data = "home"
  180. content = c.get_content(data)
  181. for item in content:
  182. print item
  183. #cat = api.get_categories(country)
  184. #chan = api.get_channels("lv")
  185. #prog = api.get_programs(channel=6400)
  186. #prog = api.get_programs(category=55)
  187. #seas = api.get_seasons(program=6453)
  188. #str = api.get_streams(660243)
  189. #res = api.get_videos(802)
  190. #formats = api.getAllFormats()
  191. #det = api.detailed("1516")
  192. #vid = api.getVideos("13170")
  193. pass