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

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