123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- #!/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('<a class="video-picture" (.+?)</li>', r, re.IGNORECASE | re.MULTILINE)
- for r2 in result:
- m = re.search('<a class="video-title" href="/lv/([^"]+)">([^<]+)<', r2)
- title = m.group(2)
- data2 = m.group(1)
- m = re.search("([^ ]+) 2x", r2)
- if m:
- img = m.group(1)
- else:
- m = re.search('<img src="([^"]+)', r2)
- img = m.group(1) if m else ""
- m = re.search('<span class="playlist-overlay">([^<]+)</span>', r2)
- overlay = m.group(1) if m else ""
- m = re.search('<span class="badge badge-[^>]+>([^<]+)(<[^>]+>([^<]+))*</span>', r2, re.IGNORECASE)
- badge = ""
- if m:
- badge = m.group(1)
- if m.group(3):
- badge = badge + m.group(3)
- categories = re.findall('<span class="category-title">([^<]+)</span>', 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("<h1>(.+?)</h1", r, re.IGNORECASE).group(1)
- m = re.search('<a class="category-title".+?[^>]+>([^<]+)<', r, re.IGNORECASE | re.DOTALL)
- categories = m.group(1) if m else ""
- m = re.search('<span class="category-title">([^<]+)</span>.+?</p>', r, re.IGNORECASE | re.DOTALL)
- if m:
- categories = categories + m.group(1)
- if categories:
- tite = "%s [%s]"%(title,categories)
- img = re.search('<meta property="twitter:image" content="([^"]+)">', r, re.IGNORECASE | re.DOTALL).group(1)
- desc = title + "\n" + re.search('<meta property="og:description" content="([^"]+)">', 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
|