#!/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 from collections import OrderedDict from SourceBase import SourceBase API_URL = 'http://replay.lsm.lv/' headers2dict = lambda h: dict([l.strip().split(": ") for l in h.strip().splitlines()]) headers0 = headers2dict(""" User-Agent: Mozilla/5.0 (Linux; U; Android 4.4.4; Nexus 5 Build/KTU84P) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 """) import HTMLParser h = HTMLParser.HTMLParser() class Source(SourceBase): def __init__(self,country="lv"): self.name = "tvdom" self.title = "TVDom.tv" self.img = "https://tvdom.tv/front/assets/images/logo.png" self.desc = "TVDom.tv portāla satura skatīšanās" self.headers = headers0 self.country=country self.session = None self.token = None cur_directory = os.path.dirname(os.path.abspath(__file__)) self.config_file = os.path.join(cur_directory,self.name+".cfg") self.options = OrderedDict([("user","lietotajs"),("password","parole")]) self.options_read() def login(self,user="",password=""): self.options_read() if not user: user=self.options["user"] if not password: password = self.options["password"] headers = headers2dict(""" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0 Accept: */* Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate, br Content-Type: application/x-www-form-urlencoded; charset=UTF-8 X-Requested-With: XMLHttpRequest Referer: https://tvdom.tv/ """) url = "https://tvdom.tv/infinity/on_register_user" params = "email=%s&password=%s&remember=false&auth_type=login"%(user,password) import requests try: from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(InsecureRequestWarning) except: pass r = requests.post(url, data=params, headers=headers) js = json.loads(r.content) if 'success' in r.content: self.token = js["access_token"] if 'PHPSESSID' in r.cookies: self.session = r.cookies["PHPSESSID"] return True else: raise Exception(js["error"]) def get_content(self, data): print "[tvdom] get_content:", data source,data,path,plist,clist,params,qs = self.parse_data(data) lang = qs["lang"] if "lang" in qs else self.country content=[] content.append(("..return", "back","","Return back")) if clist=="home": content.extend([ ("Live stream", "tvdom::tiesraides","","TV live streams"), ("Archive - categories", "tvdom::arhivs","","Video archive by categories"), ("Search", "tvdom::search/?srch-term={0}","","Search archive"), #("Archive - all", "tvdom::arhivs_all","","Video archive all"), ]) return content ### Tiesraides kanalu saraksts ### elif data=="tiesraides": ch_name = {"49":"Дом Кино","50":"Карусель","51":"Время","52":"Музыка Первого","53":"Телекафе"} url = "https://tvdom.tv/" r = self._http_request(url) #channels1 = re.findall(r'data-xprs_status="\d" data-href="/tiesraides/([^/]+)/[^"]+">.+?src="([^"]+)" alt="([^"]+)">', r, re.DOTALL) channels2 = re.findall(r'([^<]*)\s+
([^<]+)
', r, re.DOTALL) channels = {} for item in channels2: title = item[0] title = h.unescape(title.decode("utf8")).encode("utf8") img = "https://tvdom.tv"+item[2] data2 = "tiesraides/%s/"%item[1] desc = "%s\n%s\n%s"%(title,item[3],item[4]) channels[item[1]]={"title":title,"img":img,"desc":desc} #content.append((title,self.name+"::"+data2,img,desc)) for r2 in re.findall(r' ', r, re.DOTALL): ch = re.search('data-href="/tiesraides/([^/]+)/[^"]+"', r2, re.DOTALL).group(1) data2 = "tiesraides/"+ch m = re.search('src="(.+?)" alt="(.+?)">', r2, re.DOTALL) title = m.group(2) img = m.group(1) desc = title if ch in channels: img = channels[ch]["img"] desc = channels[ch]["desc"] else: m = re.search('([^<]+)
', r2, re.DOTALL) if m: desc = "%s\n%s\n%s"%(title,m.group(1),m.group(3)) img = m.group(2) content.append((title,self.name+"::"+data2,img,desc)) return content elif clist == "tiesraides": if not self.session: self.login() url = "https://tvdom.tv/" + data headers = self.headers headers["Cookie"] = "PHPSESSID=%s; neverending_story=1;"%self.session r = self._http_request(url,headers=headers) m = re.search("var streamConnectionUrl = '([^']+)'", r, re.DOTALL) if m: data2 = m.group(1) else: return ("No stream found %s"%data,"","","No stream found") m = re.search('title: "([^"]+)"', r, re.DOTALL) title = m.group(1) if m else data2 m = re.search('