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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 SourceBase import SourceBase
  16. import base64
  17. from collections import OrderedDict
  18. import os
  19. #sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  20. from resolver import resolve
  21. headers2dict = lambda h: dict([l.strip().split(": ") for l in h.strip().splitlines()])
  22. import HTMLParser
  23. h = HTMLParser.HTMLParser()
  24. class Source(SourceBase):
  25. def __init__(self,country=""):
  26. self.name = "kinofilmnet"
  27. self.title = "KinoFilmNet.lv"
  28. self.img = "https://pbs.twimg.com/profile_images/743461209563791361/08RooARb.jpg"
  29. self.desc = "Kinofilmnet.lv satura skatīšanās"
  30. self.country=country
  31. self.headers = headers2dict("""
  32. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0
  33. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,application/json
  34. """)
  35. self.headers2 = headers2dict("""
  36. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
  37. X-Requested-With: XMLHttpRequest
  38. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  39. """)
  40. self.url = "http://kinofilmnet.lv/"
  41. #self.login()
  42. def login(self,user="",password=""):
  43. return True
  44. ######### Entry point ########
  45. def get_content(self, data):
  46. print "[kinofilmnet] get_content:", data
  47. if "::" in data:
  48. data = data.split("::")[1]
  49. path = data.split("?")[0]
  50. clist = path.split("/")[0]
  51. params = data[data.find("?"):] if "?" in data else ""
  52. qs = dict(map(lambda x:x.split("="),re.findall("[%\w]+=\w+",params)))
  53. lang = qs["lang"] if "lang" in qs else self.country
  54. content=[]
  55. content.append(("..return", "back","","Return back"))
  56. if clist=="home":
  57. content.extend([
  58. ("Search", "kinofilmnet::search/?q={0};t=0;p=1 ","","Search"), #search/?q={0};t=0;p=1
  59. ("Last movies", "kinofilmnet::jaunakas","","Last movies all"),
  60. ("Top50", "kinofilmnet::top50","","Top 50 movies"),
  61. ])
  62. r = self.call("")
  63. for item in re.findall('<li><a href=".*load/([^"]+)">([^<]+)</a></li>', r):
  64. title = item[1]
  65. data2 = "filmas/" + 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. r=self.call(data)
  72. for item in re.findall('<a href="([^"]+)"> (.+?) </a></div>.+?> (.+?)</div>', r, re.DOTALL):
  73. title = item[1].replace("<b>","").replace("</b>","")
  74. data2 = item[0].replace("http://kinofilmnet.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. elif data in ("jaunakas","top50") or (clist=="filmas" and len(path.split("/"))==3):
  86. if data=="jaunakas":
  87. data = ""
  88. r = self.call(data)
  89. if not r:
  90. return content
  91. result = re.findall('<div class="movie-img img-box">.*?<img src="([^"]*)" alt="([^"]*)" />.+?data-link="([^"]*)"></i>.+?<span>([^<]+)</span>.+?class="movie-title" href="([^"]*)">([^<]+)</a>.+?<div class="movie-date">([^<]+)</div>.*?<div class="movie-director"><b>Žanrs:</b> ([^<]+)</div>.*?<div class="movie-text">([^<]+)</div>', r, re.DOTALL)
  92. for item in result:
  93. title = item[1] + " [%s]"%item[3]
  94. data2 = item[2].replace("http://kinofilmnet.lv","")[1:]
  95. img = "http://kinofilmnet.lv"+item[0]
  96. desc = "%s %s %s\n%s"%(item[3],item[7],item[6],item[8])
  97. content.append((title,self.name+"::"+data2,img,desc))
  98. if '<span>&raquo;</span>' in r:
  99. m = re.search("filmas/\w+/\d+\-(\d+)",data)
  100. if m:
  101. page = int(m.group(1))+1
  102. data2 = re.sub(r"(filmas/\w+/\d+)\-\d+", r"\1-%s"%page, data)
  103. else:
  104. data2 = data+"-2"
  105. content.append(("Next page",self.name+"::"+data2,self.img,"Next page"))
  106. return content
  107. ## Seriāls
  108. elif len(path.split("/"))==4:
  109. r = self.call(data)
  110. if not r:
  111. return content
  112. title0 = re.search("<title>Filma online (.+?) ::", r).group(1)
  113. desc = re.search('<meta name="description" content="([^"]+)', r).group(1)
  114. img = "http://kinofilmnet.lv"+re.search('<div class="m-img">.*?<img src="([^"]+)"', r, re.DOTALL).group(1)
  115. result = re.findall('<details><summary>([^<]+)</summary><iframe src="([^"]+)"', r)
  116. for i,item in enumerate(result):
  117. title = title0 +' - '+item[0]
  118. data2 = path+"?s=%s"%(i+1)
  119. content.append((title,self.name+"::"+data2,img,desc))
  120. return content
  121. else:
  122. return content
  123. def is_video(self,data):
  124. source,data,path,plist,clist,params,qs = self.parse_data(data)
  125. if clist<>"filmas" or len(plist)<>4:
  126. return False
  127. r = self.call(path)
  128. if re.search('<div class="viboom-overroll"><iframe src="([^"]+)"', r):
  129. return True
  130. if re.search('<details><summary>([^<]+)</summary><iframe src="([^"]+)"', r) and "s" in qs:
  131. return True
  132. else:
  133. return False
  134. def get_streams(self, data):
  135. print "[kinofilmnet] get_streams:", data
  136. source,data,path,plist,clist,params,qs = self.parse_data(data)
  137. r = self.call(path)
  138. if not r:
  139. return []
  140. streams = []
  141. title0 = re.search("<title>Filma online (.+?) ::", r).group(1)
  142. desc = re.search('<meta name="description" content="([^"]+)', r).group(1)
  143. img = "http://kinofilmnet.lv"+re.search('<div class="m-img">.*?<img src="([^"]+)"', r, re.DOTALL).group(1)
  144. m = re.search('<div class="viboom-overroll"><iframe src="([^"]+)"', r)
  145. if m: # Video
  146. url0 = m.group(1)
  147. title = title0
  148. elif re.search('<details><summary>([^<]+)</summary><iframe src="([^"]+)"', r) and "s" in qs: # Serials
  149. serie = re.findall('<details><summary>([^<]+)</summary><iframe src="([^"]+)"', r)[int(qs["s"])-1]
  150. url0 = serie[1]
  151. title = title0 + " - "+ serie[0]
  152. else:
  153. return []
  154. streams = resolve(url0)
  155. for s in streams:
  156. s["name"] = title
  157. s["desc"] = desc
  158. s["img"] = img
  159. s["lang"]="LV"
  160. s["type"]= self.stream_type(s["url"])
  161. return streams
  162. def call(self, data,params=None,headers=None,lang=""):
  163. if not headers: headers = self.headers
  164. url = self.url+data
  165. result = self._http_request(url,params,headers=headers)
  166. return result
  167. def _http_request(self, url,params = None, headers=None):
  168. if not headers: headers = self.headers
  169. try:
  170. import requests
  171. r = requests.get(url, headers=headers)
  172. return r.content
  173. #r = urllib2.Request(url, data=params, headers=headers)
  174. #u = urllib2.urlopen(r)
  175. #content = u.read()
  176. #u.close()
  177. #return content
  178. except Exception as ex:
  179. return None
  180. if __name__ == "__main__":
  181. country= "lv"
  182. c = Source(country)
  183. if len(sys.argv)>1:
  184. data= sys.argv[1]
  185. else:
  186. data = "home"
  187. content = c.get_content(data)
  188. for item in content:
  189. print item
  190. #cat = api.get_categories(country)
  191. #chan = api.get_channels("lv")
  192. #prog = api.get_programs(channel=6400)
  193. #prog = api.get_programs(category=55)
  194. #seas = api.get_seasons(program=6453)
  195. #str = api.get_streams(660243)
  196. #res = api.get_videos(802)
  197. #formats = api.getAllFormats()
  198. #det = api.detailed("1516")
  199. #vid = api.getVideos("13170")
  200. pass