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

movieplace.py 9.7KB

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