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

cinemalive.py 8.8KB

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