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

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