123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- #!/usr/bin/env python
- # coding=utf8
- #
- # This file is part of PlayStream - enigma2 plugin to play video streams from various sources
- # Copyright (c) 2016 ivars777 (ivars777@gmail.com)
- # Distributed under the GNU GPL v3. For full terms see http://www.gnu.org/licenses/gpl-3.0.en.html
- #
- try:
- import json
- except:
- import simplejson as json
- import urllib2, urllib
- import datetime, re, sys,os
- import ConfigParser
- from SourceBase import SourceBase
- import base64
- from collections import OrderedDict
- import os
-
- #sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
- from resolver import resolve
-
-
- headers2dict = lambda h: dict([l.strip().split(": ") for l in h.strip().splitlines()])
- import HTMLParser
- h = HTMLParser.HTMLParser()
-
- class Source(SourceBase):
-
- def __init__(self,country=""):
- self.name = "kinofilmnet"
- self.title = "KinoFilmNet.lv"
- self.img = "https://pbs.twimg.com/profile_images/743461209563791361/08RooARb.jpg"
- self.desc = "Kinofilmnet.lv satura skatīšanās"
- self.country=country
- self.headers = headers2dict("""
- User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0
- Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,application/json
- """)
- self.headers2 = headers2dict("""
- User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
- X-Requested-With: XMLHttpRequest
- Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- """)
- self.url = "http://kinofilmnet.lv/"
- #self.login()
-
- def login(self,user="",password=""):
- return True
-
- ######### Entry point ########
- def get_content(self, data):
- print "[kinofilmnet] get_content:", data
- if "::" in data:
- data = data.split("::")[1]
- path = data.split("?")[0]
- clist = path.split("/")[0]
- params = data[data.find("?"):] if "?" in data else ""
- qs = dict(map(lambda x:x.split("="),re.findall("[%\w]+=\w+",params)))
- lang = qs["lang"] if "lang" in qs else self.country
-
- content=[]
- content.append(("..return", "back","","Return back"))
-
- if clist=="home":
- content.extend([
- ("Search", "kinofilmnet::search/?q={0};t=0;p=1 ","","Search"), #search/?q={0};t=0;p=1
- ("Last movies", "kinofilmnet::jaunakas","","Last movies all"),
- ("Top50", "kinofilmnet::top50","","Top 50 movies"),
- ])
- r = self.call("")
- for item in re.findall('<li><a href=".*load/([^"]+)">([^<]+)</a></li>', r):
- title = item[1]
- data2 = "filmas/" + item[0]+"-1"
- img = self.img
- desc = title
- content.append((title,self.name+"::"+data2,img,desc))
- return content
-
- elif clist=="search":
- r=self.call(data)
- for item in re.findall('<a href="([^"]+)"> (.+?) </a></div>.+?> (.+?)</div>', r, re.DOTALL):
- title = item[1].replace("<b>","").replace("</b>","")
- data2 = item[0].replace("http://kinofilmnet.lv/","")
- img = self.img
- desc = item[2].replace("<b>","").replace("</b>","")
- content.append((title,self.name+"::"+data2,img,desc))
- if '<span>»</span>' in r:
- m = re.search("p=(\d+)",data)
- if m:
- page = int(m.group(1))+1
- data2 = re.sub(r"p=\d+", r"p=%s"%page, data)
- content.append(("Next page",self.name+"::"+data2,self.img,"Next page"))
-
- return content
-
- elif data in ("jaunakas","top50") or (clist=="filmas" and len(path.split("/"))==3):
- if data=="jaunakas":
- data = ""
- r = self.call(data)
- if not r:
- return content
- 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)
- for item in result:
- title = item[1] + " [%s]"%item[3]
- data2 = item[2].replace("http://kinofilmnet.lv","")[1:]
- img = "http://kinofilmnet.lv"+item[0]
- desc = "%s %s %s\n%s"%(item[3],item[7],item[6],item[8])
- content.append((title,self.name+"::"+data2,img,desc))
- if '<span>»</span>' in r:
- m = re.search("filmas/\w+/\d+\-(\d+)",data)
- if m:
- page = int(m.group(1))+1
- data2 = re.sub(r"(filmas/\w+/\d+)\-\d+", r"\1-%s"%page, data)
- else:
- data2 = data+"-2"
- content.append(("Next page",self.name+"::"+data2,self.img,"Next page"))
-
- return content
-
- ## Seriāls
- elif len(path.split("/"))==4:
- r = self.call(data)
- if not r:
- return content
- title0 = re.search("<title>Filma online (.+?) ::", r).group(1)
- desc = re.search('<meta name="description" content="([^"]+)', r).group(1)
- img = "http://kinofilmnet.lv"+re.search('<div class="m-img">.*?<img src="([^"]+)"', r, re.DOTALL).group(1)
- result = re.findall('<details><summary>([^<]+)</summary><iframe src="([^"]+)"', r)
- for i,item in enumerate(result):
- title = title0 +' - '+item[0]
- data2 = path+"?s=%s"%(i+1)
- content.append((title,self.name+"::"+data2,img,desc))
- return content
-
- else:
- return content
-
- def is_video(self,data):
- source,data,path,plist,clist,params,qs = self.parse_data(data)
- if clist<>"filmas" or len(plist)<>4:
- return False
-
- r = self.call(path)
- if re.search('<div class="viboom-overroll"><iframe src="([^"]+)"', r):
- return True
- if re.search('<details><summary>([^<]+)</summary><iframe src="([^"]+)"', r) and "s" in qs:
- return True
- else:
- return False
-
- def get_streams(self, data):
- print "[kinofilmnet] get_streams:", data
- source,data,path,plist,clist,params,qs = self.parse_data(data)
- r = self.call(path)
- if not r:
- return []
- streams = []
- title0 = re.search("<title>Filma online (.+?) ::", r).group(1)
- desc = re.search('<meta name="description" content="([^"]+)', r).group(1)
- img = "http://kinofilmnet.lv"+re.search('<div class="m-img">.*?<img src="([^"]+)"', r, re.DOTALL).group(1)
- m = re.search('<div class="viboom-overroll"><iframe src="([^"]+)"', r)
- if m: # Video
- url0 = m.group(1)
- title = title0
- elif re.search('<details><summary>([^<]+)</summary><iframe src="([^"]+)"', r) and "s" in qs: # Serials
- serie = re.findall('<details><summary>([^<]+)</summary><iframe src="([^"]+)"', r)[int(qs["s"])-1]
- url0 = serie[1]
- title = title0 + " - "+ serie[0]
- else:
- return []
- streams = resolve(url0)
- for s in streams:
- s["name"] = title
- s["desc"] = desc
- s["img"] = img
- s["lang"]="LV"
- s["type"]= self.stream_type(s["url"])
- return streams
-
- def call(self, data,params=None,headers=None,lang=""):
- if not headers: headers = self.headers
- url = self.url+data
- result = self._http_request(url,params,headers=headers)
- return result
-
- def _http_request(self, url,params = None, headers=None):
- if not headers: headers = self.headers
- try:
- import requests
- r = requests.get(url, headers=headers)
- return r.content
-
- #r = urllib2.Request(url, data=params, headers=headers)
- #u = urllib2.urlopen(r)
- #content = u.read()
- #u.close()
- #return content
- except Exception as ex:
- return None
-
-
- if __name__ == "__main__":
- country= "lv"
- c = Source(country)
- if len(sys.argv)>1:
- data= sys.argv[1]
- else:
- data = "home"
- content = c.get_content(data)
- for item in content:
- print item
- #cat = api.get_categories(country)
- #chan = api.get_channels("lv")
- #prog = api.get_programs(channel=6400)
- #prog = api.get_programs(category=55)
- #seas = api.get_seasons(program=6453)
- #str = api.get_streams(660243)
- #res = api.get_videos(802)
- #formats = api.getAllFormats()
- #det = api.detailed("1516")
- #vid = api.getVideos("13170")
- pass
|