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

movieplace.py 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 collections import OrderedDict
  16. from SourceBase import SourceBase
  17. import ssl
  18. if "_create_unverified_context" in dir(ssl):
  19. ssl._create_default_https_context = ssl._create_unverified_context
  20. import resolver
  21. try:
  22. import util
  23. except:
  24. sys.path.insert(0,'..')
  25. import util
  26. headers2dict = lambda h: dict([l.strip().split(": ") for l in h.strip().splitlines()])
  27. import HTMLParser
  28. h = HTMLParser.HTMLParser()
  29. class Source(SourceBase):
  30. def __init__(self, country="",cfg_path=None):
  31. self.hidden = True # nerāda menu nestrādājošos avotus
  32. self.name = "movieplace"
  33. self.title = "MoviePlace.lv"
  34. self.img = "http://movieplace.lv/images/logo.png"
  35. self.desc = "Movieplace.lv - filmas latviesu valodā"
  36. self.headers = headers2dict("""
  37. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
  38. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  39. Accept-Language: en-US,en;q=0.5
  40. """)
  41. self.headers2 = headers2dict("""
  42. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
  43. X-Requested-With: XMLHttpRequest
  44. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  45. """)
  46. self.url = "http://movieplace.lv/"
  47. ######### Entry point ########
  48. def get_content(self, data):
  49. print "[movieplace] get_content:", data
  50. source, data, path, plist, clist, params, qs = self.parse_data(data)
  51. content = []
  52. content.append(("..return", "back","","Return back"))
  53. if clist=="home":
  54. content.extend([
  55. ("Meklēt", "movieplace::search/?q={0}","","Meklēt"),
  56. ("Jaunākās filmas", "movieplace::load/?page1","","Visu žanru jaunākās filmas"),
  57. ("Jaunākie seriāli", "movieplace::dir/?page1","","Visu žanru jaunākās filmas"),
  58. #("Top50 filmas", "movieplace::index/top_50_filmas/0-4","","Top 50 filmas"),
  59. ])
  60. r = self.call("load/")
  61. #i = r.find('<div class="cat-title">Meklēt pēc žanriem</div>')
  62. #if i<=0:
  63. # return content
  64. i = 0
  65. for item in re.findall('<a href="/([^"]+)" class="catName">([^>]+)</a>', r[i:]):
  66. title = item[1]
  67. data2 = item[0]+"-1"
  68. img = self.img
  69. desc = title
  70. content.append((title,self.name+"::"+data2,img,desc))
  71. return content
  72. elif clist=="search":
  73. # TODO
  74. r=self.call(data)
  75. result = re.findall('<a href="([^"]+)"> (.+?) </a></div>.+?> (.+?)</div>', r, re.DOTALL)
  76. for item in result:
  77. title = item[1].replace("<b>","").replace("</b>","")
  78. data2 = item[0].replace("http://movieplace.lv/","")
  79. img = self.img
  80. desc = item[2].replace("<b>","").replace("</b>","")
  81. content.append((title,self.name+"::"+data2,img,desc))
  82. if '<span>&raquo;</span>' in r:
  83. m = re.search("p=(\d+)",data)
  84. if m:
  85. page = int(m.group(1))+1
  86. data2 = re.sub(r"p=\d+", r"p=%s"%page, data)
  87. content.append(("Next page",self.name+"::"+data2,self.img,"Next page"))
  88. return content
  89. # Filmu saraksti ##
  90. elif clist in ["load","dir"] and len(plist)<=3:
  91. if clist == "jaunakas":
  92. r = self.call("")
  93. else:
  94. r = self.call(data)
  95. #r = r.decode("cp1251").encode("utf8")
  96. if clist == "load":
  97. result = re.findall(r' <a href="/([^"]+)" alt="([^"]+)"><img src="/([^"]+)" title="([^"]+)">.+?<div class="years">([^<]+)</div>\s+<div class="country">([^<]+)</div>', r, re.DOTALL)
  98. else:
  99. result = re.findall(r' <a href="/([^"]+)" alt="([^"]+)"><img src="/([^"]+)" title="[^"]+">.+?<span>([^<]+)</span>\s*<div class="country">([^<]+)</div>', r, re.IGNORECASE | re.DOTALL)
  100. for item in result:
  101. title = item[1]+" [%s]"%item[4] if clist=="load" else item[1]+" / %s [%s]"%(item[3],item[4])
  102. img = "http://movieplace.lv/"+item[2]
  103. data2 = item[0]
  104. desc = "%s\n%s"%(title,item[5]) if clist=="load" else title
  105. content.append((title,self.name+"::"+data2,img,desc))
  106. m = re.search('<[ab] class="swchItemA*1"( href="/([^"]+)" onclick="[^"]+")*><span>([^<]+)</span></[ab]> </span>', r, re.DOTALL)
  107. if m:
  108. if m.group(1):
  109. page = int(re.search("\d+$",data).group())
  110. page = page+1
  111. data2 = re.sub("\d$","%s"%page,data)
  112. content.append(("Next page",self.name+"::"+data2,self.img,"Next page"))
  113. return content
  114. ### Seriāls ###
  115. elif clist=="dir" and len(plist)==4:
  116. r = self.call(path)
  117. title0 = re.search('<h2 class="title" itemprop="name">(.+?)</h2>', r, re.DOTALL).group(1)
  118. m = re.search(r'<span>VALODA:</span> <b><em itemprop="alternativeHeadline"><a href="[^"]*" class="entAllCats">([^<]+)</a></em></b></div>\s+?<div><span>SEZONA:</span> <b>([^<]+)</b></div>', r, re.IGNORECASE | re.DOTALL)
  119. if m:
  120. title0 = "%s / Season %s [%s]"%(title0,m.group(2),m.group(1))
  121. desc0 = title0
  122. img0 = "http://movieplace.lv" + re.search('<img src="(.+?)".+?itemprop="image">', r, re.DOTALL).group(1)
  123. #TODO
  124. result = re.findall(r'<summary>([^<]+)</summary><iframe src="https://openload\.co/embed/[^/]+/"', r, re.DOTALL)
  125. i = 1
  126. for item in result:
  127. title = title0+" - " + item
  128. data2 = data+"?e=%s"%i
  129. img = img0
  130. desc = desc0
  131. content.append((title,self.name+"::"+data2,img,desc))
  132. i += 1
  133. return content
  134. ### kaut kas neparedzets ###
  135. else:
  136. return content
  137. def is_video(self,data):
  138. source,data,path,plist,clist,params,qs = self.parse_data(data)
  139. if clist=="dir" and len(plist) == 4 and "e"in qs: # sērija
  140. return True
  141. elif clist=="load" and len(plist) == 4:
  142. return True
  143. else:
  144. return False
  145. def call(self, data,params=None,headers=None,lang=""):
  146. if not headers: headers = self.headers
  147. url = self.url+data
  148. result = self._http_request(url,params,headers=headers)
  149. return result
  150. def get_streams(self,data):
  151. print "[movieplace] get_streams:", data
  152. if not self.is_video(data):
  153. return []
  154. source,data,path,plist,clist,params,qs = self.parse_data(data)
  155. r = self.call(path)
  156. if clist=="load":
  157. m = re.search('<h2 class="title" itemprop="name">([^<]+)</h2>', r, re.DOTALL)
  158. title = re.search('<itemprop="name">(.+?)</itemprop="name">', r, re.DOTALL).group(1)
  159. m = re.search(r'<div role="tabpanel" class="tab-pane fade in active" id="heading-tab4">\s*(.+?)\s*</div>', r, re.DOTALL)
  160. desc = m.group(1) if m else title
  161. m = re.search('<meta property="og:image" content="([^"]+)" />', r, re.DOTALL)
  162. img = m.group(1) if m else ""
  163. rr = []
  164. for m in re.finditer("(RU|ENG|LAT|LAT SUB)<BR( /)*>.*?>?<BR( /)*>.*?<iframe", r, re.IGNORECASE | re.DOTALL):
  165. if len(rr)>0:
  166. rr[-1]["end"] = m.start()
  167. rr.append({"lang":m.group(1),"start":m.start(),"end":len(r)})
  168. streams = []
  169. for m in re.finditer(r'src="(https*://(goo\.gl|songs2dl|kodik|cdn\.kapnob|hqq|openload|sv1.servkino|vidwatch|online\.kinozz).+?)"', r, re.IGNORECASE | re.DOTALL):
  170. url = m.group(1)
  171. lang = "?"
  172. for rrr in rr:
  173. if m.start()>rrr["start"] and m.start()<rrr["end"]:
  174. lang = rrr["lang"]
  175. break
  176. for s in resolver.resolve(url):
  177. s["name"] = title
  178. s["desc"] = desc
  179. s["img"] = img
  180. s["type"] = self.stream_type(s["url"])
  181. s["lang"] = lang
  182. streams.append(s)
  183. return streams
  184. elif clist=="dir" and "e" in qs: # serialā sērija
  185. #TODO
  186. result = re.findall(r'<summary>([^<]+)</summary><iframe src="([^"]+)"', r, re.DOTALL)
  187. i = int(qs["s"])-1
  188. url0 = result[i][1]
  189. title = title + " - " + result[i][0]
  190. else:
  191. #iframe src="https://openload.co/embed/wlw6Vl9zwL0/"
  192. result = re.findall(r'<iframe src="([^"]+)"', r, re.DOTALL)
  193. if not result:
  194. return []
  195. url0 = result[0]
  196. return streams
  197. if __name__ == "__main__":
  198. country= "lv"
  199. c = Source(country)
  200. if len(sys.argv)>1:
  201. data= sys.argv[1]
  202. else:
  203. data = "home"
  204. content = c.get_content(data)
  205. for item in content:
  206. print item
  207. #cat = api.get_categories(country)
  208. #chan = api.get_channels("lv")
  209. #prog = api.get_programs(channel=6400)
  210. #prog = api.get_programs(category=55)
  211. #seas = api.get_seasons(program=6453)
  212. #str = api.get_streams(660243)
  213. #res = api.get_videos(802)
  214. #formats = api.getAllFormats()
  215. #det = api.detailed("1516")
  216. #vid = api.getVideos("13170")
  217. pass