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

cinemalive.py 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 = "cinemalive.png" #"https://cinemalive.tv/assets/img/logo.png"
  33. self.desc = "Filmas latviski"
  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","back.png","Return back"))
  52. if clist=="home":
  53. content.extend([
  54. ("Search", "cinemalive::?s={0}","","Search"),
  55. #("Filmas latviski - visas", "cinemalive::filmaslatviski/","","Filmas latviski - visas"),
  56. ("Filmas angliski", "cinemalive::home_en","","Filmas angliski"),
  57. #("Filmas latviski - jaunākās", "cinemalive::filmaslatviski/?get=jaunakas","","Filmas latviski - jaunākās"),
  58. #("Filmas latviski - vertētākās", "cinemalive::filmaslatviski/?get=vertetakas","","Filmas latviski - vērtētākās"),
  59. #("Filmas latviski - skatitakās", "cinemalive::filmaslatviski/?get=skatitakas","","Filmas latviski - skatītākās"),
  60. #("Filmas latviski - animācija", "cinemalive::genre/animacija/","","Filmas latviski - animacijas"),
  61. #("Filmas latviski - ģimenes", "cinemalive::genre/gimenes/","","Filmas latviski - ģimenes"),
  62. ])
  63. r = self.call("filmaslatviski")
  64. i0 = r.find('<div class="menu">')
  65. result = re.findall(r'menu-item-41\d+"><a href="([^"]+)">([^<]+)</a>', r[i0:])
  66. for item in result:
  67. title = "Filmas latviski - "+item[1]
  68. data2 = item[0].replace("https://cinemalive.tv", "") #+"lapa/1/"
  69. data2 = data2[1:]
  70. img = self.img
  71. desc = title
  72. content.append((title,self.name+"::"+data2,img,desc))
  73. return content
  74. elif clist=="home_en":
  75. content.extend([
  76. ("Search", "cinemalive::?s={0}","","Search"),
  77. #("Movies English - all", "cinemalive::moviesenglish/all/page/1","","Movies English - all"),
  78. #("Movies Latvian", "cinemalive::home","","Filmas latviski"),
  79. #("Movies English - newest", "cinemalive::moviesenglish/newestmovies/page/1","","Movies English - newest"),
  80. #("Movies English - top rated", "cinemalive::moviesenglish/toprated/page/1","","Movies English - top rated"),
  81. #("Movies English - most watched", "cinemalive::moviesenglish/mostwatched/page/1","","Movies English - most watched"),
  82. ])
  83. r = self.call("moviesenglish")
  84. i0 = r.find('<div class="menu">')
  85. result = re.findall(r'menu-item-4[23]\d+"><a href="([^"]+)">([^<]+)</a>', r[i0:])
  86. for item in result:
  87. title = "Movies English - "+item[1]
  88. data2 = item[0].replace("https://cinemalive.tv", "") #+"lapa/1/"
  89. data2 = data2[1:]
  90. if not (data2.startswith("movie") or data2.startswith("genre")):continue
  91. img = self.img
  92. desc = title
  93. content.append((title,self.name+"::"+data2,img,desc))
  94. return content
  95. elif clist == "" in data:
  96. r = self.call(data)
  97. result = re.findall("<article>(.+?)</article>", r)
  98. for r2 in result:
  99. m = re.search('<div class="title"><a href="https://cinemalive.tv/([^"]+)">(.+?)</a></div>', r2)
  100. title = m.group(2)
  101. data2 = m.group(1)
  102. title = re.sub("<[^>]+>", "", title)
  103. m = re.search('<img src="([^"]+)"', r2)
  104. img = m.group(1).replace("-150x150", "-185x278") if m else ""
  105. m = re.search(r'<span class="year">(\d+)</span>', r2)
  106. year = m.group(1) if m else ""
  107. if year:
  108. title = title + "(%s)" % year
  109. m = re.search(r"url\(https://cinemalive\.tv/static_main/assets/img/flags/(\w+)\.png\)", r2)
  110. flag = m.group(1) if m else ""
  111. if flag:
  112. title = title + "[%s]" % flag
  113. m = re.search('<div class="contenido"><p>([^<]+)</p>', r2)
  114. desc = m.group(1) if m else ""
  115. content.append((title,self.name+"::"+data2,img,desc))
  116. return content
  117. elif clist in ("filmaslatviski","moviesenglish", "genre"):
  118. r0 = self.call(data)
  119. if not r0:
  120. return content
  121. #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)
  122. result = re.findall('<article id="post.+?</article>', r0, re.IGNORECASE)
  123. for r in result:
  124. m = re.search('alt="([^"]+)"', r, re.IGNORECASE)
  125. title = m.group(1)
  126. m = re.search('class="quality">(.+?)</span>', r, re.IGNORECASE)
  127. sub = " [%s]" % m.group(1) if m else ""
  128. m = re.search(r"</h3><span>(\d+)</span>", r, re.IGNORECASE)
  129. gads = " (%s)" % m.group(1) if m else ""
  130. title = title + gads + sub
  131. m = re.search('<h3><a href="https://cinemalive.tv/([^"]+)"', r, re.IGNORECASE)
  132. data2 = m.group(1)
  133. m = re.search('img src="([^"]+)"', r, re.IGNORECASE)
  134. img = m.group(1) if m else ""
  135. m = re.search('class="texto">([^<]+)<', r, re.IGNORECASE)
  136. desc = m.group(1)
  137. #TODO - papildus info no apraksta
  138. content.append((title,self.name+"::"+data2,img,desc))
  139. m = re.search(r"""<span class="current">\d+</span><a href='https://cinemalive.tv/([^']+)'""", r0)
  140. if m:
  141. data2 = m.group(1)
  142. content.append(("Next page",self.name+"::"+data2,"next.png","Next page"))
  143. return content
  144. else:
  145. return content
  146. def is_video(self,data):
  147. source,data,path,plist,clist,params,qs = self.parse_data(data)
  148. if clist=="movie":
  149. return True
  150. else:
  151. return False
  152. def get_streams(self, data):
  153. print "[cinemalive] get_streams:", data
  154. source,data,path,plist,clist,params,qs = self.parse_data(data)
  155. r = self.call(path)
  156. if not r:
  157. return []
  158. streams = []
  159. title0 = re.search("<title>([^<]+)</title>", r).group(1)
  160. lang = "LV" if "Filma Online Latviski" in title0 else "EN"
  161. title = title0.replace(" - Filma Online Latviski","").replace(" - Movie Online English HD","")
  162. m = re.search(' class="wp-content"><p>(.+?)</p>', r, re.IGNORECASE)
  163. desc = m.group(1) if m else title
  164. m = re.search('<div class="poster"><img src="([^"]+)"', r, re.IGNORECASE)
  165. img = m.group(1) if m else ""
  166. # <iframe class="metaframe rptss" src="https://cloudsany.com/i/tqxkulkkcind"
  167. m = re.search('<iframe class="metaframe rptss" src="([^"]+)"', r, re.IGNORECASE)
  168. if not m:
  169. raise Exception("Can not find stream")
  170. url = m.group(1)
  171. if "openload" in url:
  172. s = resolve(url)
  173. return s
  174. elif "cloudsany" in url:
  175. s = resolve(url)
  176. for s2 in s:
  177. s2["name"] = util.unescape(title)
  178. s2["desc"] = util.unescape(desc)
  179. s2["img"] = img
  180. s2["lang"] = lang
  181. return s
  182. if __name__ == "__main__":
  183. sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
  184. import run
  185. source = Source()
  186. data= sys.argv[1] if len(sys.argv)>1 else source.name+"::home"
  187. run.run(source, data)
  188. sys.exit()
  189. #cat = api.get_categories(country)
  190. #chan = api.get_channels("lv")
  191. #prog = api.get_programs(channel=6400)
  192. #prog = api.get_programs(category=55)
  193. #seas = api.get_seasons(program=6453)
  194. #str = api.get_streams(660243)
  195. #res = api.get_videos(802)
  196. #formats = api.getAllFormats()
  197. #det = api.detailed("1516")
  198. #vid = api.getVideos("13170")
  199. pass