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

movieplace.py 9.5KB

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