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

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