|
@@ -0,0 +1,167 @@
|
|
1
|
+#!/usr/bin/env python
|
|
2
|
+# coding=utf8
|
|
3
|
+#
|
|
4
|
+# This file is part of PlayStream - enigma2 plugin to play video streams from various sources
|
|
5
|
+# Copyright (c) 2016 ivars777 (ivars777@gmail.com)
|
|
6
|
+# Distributed under the GNU GPL v3. For full terms see http://www.gnu.org/licenses/gpl-3.0.en.html
|
|
7
|
+#
|
|
8
|
+try:
|
|
9
|
+ import json
|
|
10
|
+except:
|
|
11
|
+ import simplejson as json
|
|
12
|
+import requests
|
|
13
|
+import datetime, re, sys,os
|
|
14
|
+from collections import OrderedDict
|
|
15
|
+import ssl
|
|
16
|
+if "_create_unverified_context" in dir(ssl):
|
|
17
|
+ ssl._create_default_https_context = ssl._create_unverified_context
|
|
18
|
+
|
|
19
|
+from SourceBase import SourceBase
|
|
20
|
+
|
|
21
|
+import resolver
|
|
22
|
+try:
|
|
23
|
+ import util
|
|
24
|
+except:
|
|
25
|
+ sys.path.insert(0,'..')
|
|
26
|
+ import util
|
|
27
|
+
|
|
28
|
+headers2dict = lambda h: dict([l.strip().split(": ") for l in h.strip().splitlines()])
|
|
29
|
+import HTMLParser
|
|
30
|
+h = HTMLParser.HTMLParser()
|
|
31
|
+
|
|
32
|
+class Source(SourceBase):
|
|
33
|
+
|
|
34
|
+ def __init__(self, country="lv",cfg_path=None):
|
|
35
|
+ self.name = "enigma2"
|
|
36
|
+ self.title = "Engima2"
|
|
37
|
+ self.img = "enigma2.png"
|
|
38
|
+ self.desc = "Get streams from engima2 sat receiver"
|
|
39
|
+ self.headers = headers2dict("""
|
|
40
|
+User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
|
|
41
|
+Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
|
|
42
|
+Accept-Language: en-US,en;q=0.5
|
|
43
|
+""")
|
|
44
|
+ #self.url = "http://login.tvplayhome.lt:8081/sb/public/"
|
|
45
|
+ cur_directory = os.path.dirname(os.path.abspath(__file__))
|
|
46
|
+ if not cfg_path: cfg_path = cur_directory
|
|
47
|
+ self.config_file = os.path.join(cfg_path,self.name+".cfg")
|
|
48
|
+ self.options = OrderedDict([("host", "localhost"), ("user",""),("password","")])
|
|
49
|
+ self.options_read()
|
|
50
|
+
|
|
51
|
+ if self.options["user"]:
|
|
52
|
+ self.url = "http://%s:%s@%s/api/" % (self.options["user"], self.options["password"],self.options["host"])
|
|
53
|
+ else:
|
|
54
|
+ self.url = "http://%s/api/" % (self.options["host"])
|
|
55
|
+
|
|
56
|
+ ######### Entry point ########
|
|
57
|
+ def get_content(self, data):
|
|
58
|
+ print "[enigma2] get_content:", data
|
|
59
|
+ source, data, path, plist, clist, params, qs = self.parse_data(data)
|
|
60
|
+ content = []
|
|
61
|
+ content.append(("..return", "back","back.png","Return back"))
|
|
62
|
+
|
|
63
|
+ if clist=="home":
|
|
64
|
+ data3 = "getcurrent"
|
|
65
|
+ r2 = self.call(data3)
|
|
66
|
+ event = r2["now"]
|
|
67
|
+ title, img, desc = self.get_title_desc(event)
|
|
68
|
+ content.append(("Current stream: "+title, self.name+"::"+"streamcurrent", img, desc))
|
|
69
|
+ r = self.call("bouquets?stype=tv")
|
|
70
|
+ for item in r["bouquets"]:
|
|
71
|
+ title = item[1]
|
|
72
|
+ data2 = "getservices?sRef=%s" % item[0]
|
|
73
|
+ #data2 = "epgbouquet?bRef=%s" % item[1]
|
|
74
|
+ content.append((title, self.name+"::"+data2, self.img, title))
|
|
75
|
+ return content
|
|
76
|
+
|
|
77
|
+ elif clist == "getservices":
|
|
78
|
+ r = self.call(data)
|
|
79
|
+ data3 = data.replace("getservices?sRef", "epgbouquet?bRef")
|
|
80
|
+ r2 = self.call(data3)
|
|
81
|
+ for item in r["services"]:
|
|
82
|
+ title = item["servicename"]
|
|
83
|
+ data2 = "stream?ref=%s&name=%s" % (item["servicereference"], title)
|
|
84
|
+ img = self.img
|
|
85
|
+ desc = title
|
|
86
|
+ for item2 in r2["events"]:
|
|
87
|
+ if item2["sref"] == item["servicereference"]:
|
|
88
|
+ title, img, desc = self.get_title_desc(item2)
|
|
89
|
+ break
|
|
90
|
+ content.append((title,self.name+"::"+data2, img,desc))
|
|
91
|
+ return content
|
|
92
|
+
|
|
93
|
+ ### kaut kas neparedzets ###
|
|
94
|
+ else:
|
|
95
|
+ return content
|
|
96
|
+
|
|
97
|
+ def get_title_desc(self, event):
|
|
98
|
+ t1 = event["begin_timestamp"]
|
|
99
|
+ t2 = event["begin_timestamp"] + event["duration_sec"]
|
|
100
|
+ t1 = datetime.datetime.fromtimestamp(t1).strftime("%H:%M")
|
|
101
|
+ t2 = datetime.datetime.fromtimestamp(t2).strftime("%H:%M")
|
|
102
|
+ title = "%s - %s [%s-%s]" % (event["sname"], event["title"], t1, t2)
|
|
103
|
+ desc = event["shortdesc"]
|
|
104
|
+ if event["longdesc"]:
|
|
105
|
+ desc += "\n" + event["longdesc"]
|
|
106
|
+ img = event["sref"][:-1].replace(":", "_") + ".png"
|
|
107
|
+ img = self.url.replace("/api/", "/picon/") + img
|
|
108
|
+ return title, img, desc
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+ def is_video(self,data):
|
|
112
|
+ source,data,path,plist,clist,params,qs = self.parse_data(data)
|
|
113
|
+ if clist in ("stream", "streamcurrent"):
|
|
114
|
+ return True
|
|
115
|
+ else:
|
|
116
|
+ return False
|
|
117
|
+
|
|
118
|
+ def call(self, data,params=None,headers=None,lang=""):
|
|
119
|
+ if not headers: headers = self.headers
|
|
120
|
+ url = self.url+data
|
|
121
|
+ r = requests.get(url,headers = headers)
|
|
122
|
+ result = json.loads(r.content)
|
|
123
|
+ #result = self._http_request(url,params,headers=headers)
|
|
124
|
+ return result
|
|
125
|
+
|
|
126
|
+ def get_streams(self,data):
|
|
127
|
+ print "[enigma2] get_streams:", data
|
|
128
|
+ if not self.is_video(data):
|
|
129
|
+ return []
|
|
130
|
+ source,data,path,plist,clist,params,qs = self.parse_data(data)
|
|
131
|
+ if "streamcurrent" in data:
|
|
132
|
+ data3 = "getcurrent"
|
|
133
|
+ r2 = self.call(data3)
|
|
134
|
+ event = r2["now"]
|
|
135
|
+ data = data.replace("streamcurrent", "streamcurrent.m3u")
|
|
136
|
+ else:
|
|
137
|
+ data3 = data.replace("stream?ref=","epgservicenow?sRef=")
|
|
138
|
+ r2 = self.call(data3)
|
|
139
|
+ event = r2["events"][0]
|
|
140
|
+ data = data.replace("stream", "stream.m3u")
|
|
141
|
+ title, img, desc = self.get_title_desc(event)
|
|
142
|
+
|
|
143
|
+ r = self._http_request(self.url+data)
|
|
144
|
+ m = re.search("(http(s)*:.+)", r)
|
|
145
|
+ if not m:
|
|
146
|
+ raise Exception("No streams found!")
|
|
147
|
+ data2 = m.group(1)
|
|
148
|
+ #data2 = "http://videolink"
|
|
149
|
+ stream = util.item()
|
|
150
|
+ stream["name"] = title
|
|
151
|
+ stream["url"] = data2
|
|
152
|
+ stream["img"] = img
|
|
153
|
+ stream["desc"] = desc
|
|
154
|
+ stream["resolver"] = "enigma2"
|
|
155
|
+ return [stream]
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+if __name__ == "__main__":
|
|
159
|
+ sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
|
160
|
+ import run
|
|
161
|
+ source = Source()
|
|
162
|
+ data= sys.argv[1] if len(sys.argv)>1 else source.name+"::home"
|
|
163
|
+ if len(sys.argv) > 2:
|
|
164
|
+ run.run_cli(source, data)
|
|
165
|
+ else:
|
|
166
|
+ run.run(source, data)
|
|
167
|
+ sys.exit()
|