#!/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 import ssl if "_create_unverified_context" in dir(ssl): ssl._create_default_https_context = ssl._create_unverified_context from SourceBase import SourceBase import util headers2dict = lambda h: dict([l.strip().split(": ") for l in h.strip().splitlines()]) headers0 = headers2dict(""" User-Agent: Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.04 Accept: application/json, text/javascript, */*; q=0.01 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""") import HTMLParser h = HTMLParser.HTMLParser() class Source(SourceBase): def __init__(self,country="lv",cfg_path=None): self.name = "tvdom" self.title = "TVDom.tv" self.img = "tvdom.png" self.desc = "TVDom.tv portāla satura skatīšanās" self.headers = headers0 self.url = "https://tvdom.tv/" self.country=country self.session = None self.token = None cur_directory = os.path.dirname(os.path.abspath(__file__)) if not cfg_path: cfg_path = cur_directory self.config_file = os.path.join(cfg_path,self.name+".cfg") self.options = OrderedDict([("user","lietotajs"),("password","parole"), ("region", "lv"), ("lang", "lv")]) 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 = self.options["lang"] region = self.options["region"] content=[] content.append(("..return", "back","back.png","Return back")) if clist=="home": content.extend([ ("Live stream", "tvdom::tiesraides","","TV live streams"), ("Archive - last", "tvdom::arhivs?filter=new&page=0&limit=30®ion=%s&language=%s" % (region, lang),"","Video archive - last videos"), ("Archive - popular", "tvdom::arhivs?filter=new&page=0&limit=30®ion=%s&language=%s"% (region, lang),"","Video archive - popular video"), ("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": data1 = "infinity/on_front_filter_channels_list.json" params = "hd=&language=%s®ion=%s" % (self.options["lang"], self.options["region"]) r = self.call_json(data1, params) for genre in r["data"]: for item in r["data"][genre]: ch = item["channel_name"] title = u"%s - %s" % (item["channel_name"], item["program_title"]) img = "https://tvdom.tv"+item["channel_logo"] data2 = item["program_url"][1:] desc = u"%s\n%s-%s"%(title,item["time_start"],item["time_stop"]) 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('
(.+?)
', r, re.DOTALL) datums = m.group(1).strip() if m else "" title = title + " " + datums m = re.search('(.+?).+?\s*\s*([^<]*)\s*
', r2, re.DOTALL)
for item in result:
#if pname not in item[1]:
# continue
title = item[2] + " " + item[3].strip()
title = h.unescape(title.decode("utf8")).encode("utf8")
img = "https://tvdom.tv"+item[0]
data2 = item[1]
desc = title # TODO
content.append((title,self.name+"::"+data2,img,desc))
return content
### Arhīva video
# elif clist=="play_arhivs" and len(data.split("/"))==3 and re.search("_\d+",plist[2]):
# 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('program_title = "([^"]+)"', r, re.DOTALL)
# title = m.group(1) if m else data2
# m = re.search('Pārraides laiks ēterā: ([^<]+)', r, re.DOTALL)
# datums = m.group(1) if m else ""
# title = title + " " + datums
# m = re.search('
\s*([^<]*)\s*\s*