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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 = "kinofilmnet"
  25. self.title = "KinoFilmNet.lv"
  26. self.img = "http://kinofilmnet.lv/MusuBaneri/1268.png"
  27. self.desc = "Kinofilmnet.lv satura skatīšanās"
  28. self.country=country
  29. self.headers = headers2dict("""
  30. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
  31. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  32. Accept-Language: en-US,en;q=0.5
  33. """)
  34. self.headers2 = headers2dict("""
  35. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
  36. X-Requested-With: XMLHttpRequest
  37. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  38. """)
  39. self.url = "http://kinofilmnet.lv/"
  40. ######### Entry point ########
  41. def get_content(self, data):
  42. print "[kinofilmnet] get_content:", data
  43. source,data,path,plist,clist,params,qs = self.parse_data(data)
  44. content=[]
  45. content.append(("..return", "back","","Return back"))
  46. if clist=="home":
  47. content.extend([
  48. ("Meklēt", "kinofilmnet::search/?q={0}","","Meklēt"),
  49. ("Jaunākās", "kinofilmnet::jaunakas","","Visu žanru jaunākās filmas"),
  50. ("Top50", "kinofilmnet::top50","","Top 50 filmas"),
  51. ])
  52. r = self.call("")
  53. i = r.find('<div class="cat-title">Meklēt pēc žanriem</div>')
  54. if i<=0:
  55. return content
  56. for item in re.findall('<li><a href=".*load/([^"]+)">([^<]+)</a></li>', r[i:]):
  57. title = item[1]
  58. data2 = "filmas/" + item[0]
  59. img = self.img
  60. desc = title
  61. content.append((title,self.name+"::"+data2,img,desc))
  62. return content
  63. elif clist=="search":
  64. r=self.call(data)
  65. result = re.findall('<a href="([^"]+)"> (.+?) </a></div>.+?> (.+?)</div>', r, re.DOTALL)
  66. for item in result:
  67. title = item[1].replace("<b>","").replace("</b>","")
  68. data2 = item[0].replace("http://kinofilmnet.lv/","")
  69. img = self.img
  70. desc = item[2].replace("<b>","").replace("</b>","")
  71. content.append((title,self.name+"::"+data2,img,desc))
  72. if '<span>&raquo;</span>' in r:
  73. m = re.search("p=(\d+)",data)
  74. if m:
  75. page = int(m.group(1))+1
  76. data2 = re.sub(r"p=\d+", r"p=%s"%page, data)
  77. content.append(("Next page",self.name+"::"+data2,self.img,"Next page"))
  78. return content
  79. # Žanru saraksti ##
  80. elif clist in ("jaunakas","top50") or clist=="filmas" and len(plist)==3:
  81. if clist == "jaunakas":
  82. r = self.call("")
  83. else:
  84. r = self.call(data)
  85. #r = r.decode("cp1251").encode("utf8")
  86. result = re.findall(r'<div id="entryID\w+">.+?<img src="([^"]+)" alt="([^"]+)".+?data-link="([^"]+)".+?<span>([^<]*)</span>.+?<div class="movie-date">([^<]+)</div>.+?<div class="movie-director"><b>Žanrs:</b> ([^<]+)</div>.+?<div class="movie-text">([^<]+)</div>', r, re.DOTALL)
  87. for item in result:
  88. title = item[1]+"[%s]"%item[3]
  89. img = "http://kinofilmnet.lv"+item[0]
  90. data2 = item[2][1:]
  91. desc = "%s %s\n%s"%(item[4],item[5],item[6])
  92. content.append((title,self.name+"::"+data2,img,desc))
  93. m = re.search('href="/([^"]+)" onclick="[^"]+" ><span>&raquo;', r, re.DOTALL)
  94. if m:
  95. data2 = m.group(1)
  96. content.append(("Next page",self.name+"::"+data2,self.img,"Next page"))
  97. return content
  98. ### Seriāls ###
  99. elif clist=="filmas" and len(plist)==4:
  100. r = self.call(path)
  101. title0 = re.search("<h1>([^<]+)</h1>", r, re.DOTALL).group(1)
  102. desc0 = re.search('<div class="m-desc full-text clearfix">([^<]+)</div>', r, re.DOTALL).group(1)
  103. img0 = "http://kinofilmnet.lv" + re.search('<div class="m-img">.*?<img src="([^"]+)" alt', r, re.DOTALL).group(1)
  104. result = re.findall(r'<summary>([^<]+)</summary><iframe src="https://openload\.co/embed/[^/]+/"', r, re.DOTALL)
  105. i = 1
  106. for item in result:
  107. title = title0+" - " + item
  108. data2 = data+"?s=%s"%i
  109. img = img0
  110. desc = desc0
  111. content.append((title,self.name+"::"+data2,img,desc))
  112. i += 1
  113. return content
  114. ### kaut kas neparedzets ###
  115. else:
  116. return content
  117. def is_video(self,data):
  118. source,data,path,plist,clist,params,qs = self.parse_data(data)
  119. if clist=="filmas" and len(plist) == 4 and "s"in qs:
  120. return True
  121. if not (clist=="filmas" and len(plist) == 4):
  122. return False
  123. if "sezona" in data:
  124. return False
  125. r = self.call(path)
  126. result = re.findall(r'iframe src="https://openload\.co/embed/[^/]+/"', r, re.DOTALL)
  127. if len(result)>1:
  128. return False
  129. else:
  130. return True
  131. def call(self, data,params=None,headers=None,lang=""):
  132. if not headers: headers = self.headers
  133. url = self.url+data
  134. result = self._http_request(url,params,headers=headers)
  135. return result
  136. def get_streams(self,data):
  137. print "[kinofilmnet] get_streams:", data
  138. #if not self.is_video(data):
  139. #return []
  140. source,data,path,plist,clist,params,qs = self.parse_data(data)
  141. r = self.call(path)
  142. title = re.search("<h1>([^<]+)</h1>", r, re.DOTALL).group(1)
  143. desc = re.search('<div class="m-desc full-text clearfix">([^<]+)</div>', r, re.DOTALL).group(1)
  144. img = "http://kinofilmnet.lv" + re.search('<div class="m-img">.*?<img src="([^"]+)" alt', r, re.DOTALL).group(1)
  145. if "s" in qs: # serialā sērija
  146. result = re.findall(r'<summary>([^<]+)</summary><iframe src="([^"]+)"', r, re.DOTALL)
  147. i = int(qs["s"])-1
  148. url0 = result[i][1]
  149. title = title + " - " + result[i][0]
  150. else:
  151. #iframe src="https://openload.co/embed/wlw6Vl9zwL0/"
  152. result = re.findall(r'<iframe src="([^"]+)"', r, re.DOTALL)
  153. if not result:
  154. return []
  155. url0 = result[0]
  156. streams = resolver.resolve(url0)
  157. for s in streams:
  158. if "hqq." in url0 or "goo.gl" in url0:
  159. s["url"] = util.streamproxy_encode(s["url"],s["headers"])
  160. s["headers"]={}
  161. s["name"] = title
  162. s["desc"] = desc
  163. s["img"] = img
  164. s["type"] = self.stream_type(s["url"])
  165. #s["lang"] = lang
  166. return streams
  167. if __name__ == "__main__":
  168. country= "lv"
  169. c = Source(country)
  170. if len(sys.argv)>1:
  171. data= sys.argv[1]
  172. else:
  173. data = "home"
  174. content = c.get_content(data)
  175. for item in content:
  176. print item
  177. #cat = api.get_categories(country)
  178. #chan = api.get_channels("lv")
  179. #prog = api.get_programs(channel=6400)
  180. #prog = api.get_programs(category=55)
  181. #seas = api.get_seasons(program=6453)
  182. #str = api.get_streams(660243)
  183. #res = api.get_videos(802)
  184. #formats = api.getAllFormats()
  185. #det = api.detailed("1516")
  186. #vid = api.getVideos("13170")
  187. pass