#!/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 requests import datetime, re, sys,os import ConfigParser from collections import OrderedDict from SourceBase import SourceBase import resolver try: import util except: sys.path.insert(0,'..') import util 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="",cfg_path=None): self.name = "lmt" self.title = "LMT straume" self.img = "http://www.lob.lv/images/logo/lmt_straume_vert_rgb.png" self.desc = "LMT straume - dažādi video latviesu valodā" self.headers = headers2dict(""" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 """) 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://straume.lmt.lv/lv/" ######### Entry point ######## def get_content(self, data): print "[lmt] get_content:", data source, data, path, plist, clist, params, qs = self.parse_data(data) content = [] content.append(("..return", "back","","Return back")) if clist=="home": content.extend([ ("Meklēt", "lmt::meklet?q={0}","","Meklēt"), ("Straumes", "lmt::straumes","","Tiešraides un aktuāli video"), #("TV", "lmt::tv","","TV tiešraides (tikai LMT tīklā)"), ("Jaunākie", "lmt::video/jaunakie?videoPage=1", "", "Visu žanru jaunākie video"), ("Sports", "lmt::video/sports?videoPage=1", "", "Sports"), ("Kultūra un māksla", "lmt::video/kultura?videoPage=1", "", "Kultūra un māksla"), ("Konferences", "lmt::video/konferences?videoPage=1", "", "Konferences"), ("Raidījumi", "lmt::video/raidijumi?videoPage=1", "", "Raidījumi"), ("Notikumi", "lmt::video/notikumi?videoPage=1", "", "Notikumi"), ("Filmas un seriāli", "lmt::video/filmas?videoPage=1", "", "Filmas un seriāli"), ("Dažādi video", "lmt::video/dazadi?videoPage=1", "", "Dažādi video"), ]) return content elif clist in ("meklet","video", "straumes","video-saraksts"): r=self.call(data) result = re.findall('', r, re.IGNORECASE | re.MULTILINE) for r2 in result: m = re.search('([^<]+)<', r2) title = m.group(2) data2 = m.group(1) m = re.search("([^ ]+) 2x", r2) if m: img = m.group(1) else: m = re.search('([^<]+)', r2) overlay = m.group(1) if m else "" m = re.search('([^<]+)', r2) categories = "".join(categories) if overlay: title = "%s [%s]"%(title,overlay) if badge: title = "%s [%s]"%(title,badge) desc = title if categories: desc = desc + "\n"+ categories content.append((title,self.name+"::"+data2,img,desc)) m = re.search("videoPage=(\d+)",data) if m: page = int(m.group(1))+1 data2 = re.sub(r"videoPage=\d+", r"videoPage=%s"%page, data) content.append(("Next page",self.name+"::"+data2,self.img,"Next page")) #print content return content ### kaut kas neparedzets ### else: return content def is_video(self,data): source,data,path,plist,clist,params,qs = self.parse_data(data) if not clist in ("meklet","video", "straumes","video-saraksts","home"): return True def call(self, data,params=None,headers=None,lang=""): if not headers: headers = self.headers url = self.url+data r = requests.get(url,headers = headers) return r.content #result = self._http_request(url,params,headers=headers) return result def get_streams(self,data): print "[lmt] get_streams:", data if not self.is_video(data): return [] source,data,path,plist,clist,params,qs = self.parse_data(data) r = self.call(path) title = re.search("

(.+?)]+>([^<]+)<', r, re.IGNORECASE | re.DOTALL) categories = m.group(1) if m else "" m = re.search('([^<]+).+?

', r, re.IGNORECASE | re.DOTALL) if m: categories = categories + m.group(1) if categories: tite = "%s [%s]"%(title,categories) img = re.search('', r, re.IGNORECASE | re.DOTALL).group(1) desc = title + "\n" + re.search('', r, re.IGNORECASE | re.DOTALL).group(1) m = re.search('file: "([^"]+)"', r, re.IGNORECASE) if m: data2 = m.group(1) stream = util.item() stream["name"] = title stream["url"] = data2 stream["img"] = img stream["desc"] = desc stream["resolver"] = "lmt" return [stream] else: m = re.search('src="(http://www.youtube.com/[^"]+)"',r) if m: url = m.group(1) else: raise Exception("No stream found") streams = resolver.resolve(url) for s in streams: s["name"] = title s["desc"] = desc s["img"] = img streams.append(s) return streams 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