Browse Source

pievienots TVPlay

Ivars 6 years ago
parent
commit
602d026bb0
5 changed files with 595 additions and 508 deletions
  1. BIN
      picons/mtg.png
  2. BIN
      picons/tvplay.png
  3. 323
    506
      project.wpr
  4. 2
    2
      sources/streams.cfg
  5. 270
    0
      sources/tvplay.py

BIN
picons/mtg.png View File


BIN
picons/tvplay.png View File


+ 323
- 506
project.wpr
File diff suppressed because it is too large
View File


+ 2
- 2
sources/streams.cfg View File

@@ -5,7 +5,7 @@ My TV archive|config::my_archive|my_archive.png|Mani TV arhīvu video
5 5
 My Video|config::my_video|my_video.png|Mani video
6 6
 My Kids|config::my_kids|my_kids.png|Mani bērnu video
7 7
 Replay.lv (LTV)|replay::home|replay.png|Latvijas TV tiešraides un arhīvs
8
-Skaties.lv (TV3)|mtgplay::home|skaties.png|MTG kanālu (LNT,TV3, TV6 u.c.) arhīvs
8
+TVPlay|tvplay::home|tvplay.png|tvplay.skaties.lv saturs
9 9
 Shortcut (lattelecom.tv)|ltc::home|shortcut.png|lattelecom TV, arhīves un video
10 10
 Play24.lv (Riga24TV)|play24::home|riga24.png|play24.lv (Riga24TV)tiešraide un arhīvs
11 11
 LMT straume|lmt::home|lmt.png|LMT straume - dažādi video latviesu valodā
@@ -20,7 +20,7 @@ Filmix.net|filmix::home|filmix.png|Filmix.net - filmas krievu valodā
20 20
 SerialGURU.ru|serialguru::home||Serialguru.ru - filmas krievu valodā
21 21
 USTVNow|ustvnow::home|ustvnow.png|USTVNow kanālu tiešraide
22 22
 FilmOn|filmon::home|filmon.png|FilmOn - tiešraides un video (dažādās valodās)
23
-TVPlay Baltic|config::mtg|tvplay.png|Other countries MTG media portals content
23
+MTG|config::mtg|mtg.png|Other countries MTG media portals content
24 24
 
25 25
 [my_tv]
26 26
 My Tv

+ 270
- 0
sources/tvplay.py View File

@@ -0,0 +1,270 @@
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
+import ConfigParser
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
+from YouTubeVideoUrl import YouTubeVideoUrl
28
+
29
+headers2dict = lambda  h: dict([l.strip().split(": ") for l in h.strip().splitlines()])
30
+import HTMLParser
31
+h = HTMLParser.HTMLParser()
32
+
33
+class Source(SourceBase):
34
+
35
+    def __init__(self, country="lv",cfg_path=None):
36
+        self.name = "tvplay"
37
+        self.title = "TVPlay"
38
+        self.img = "tvplay.png"
39
+        self.desc = "tvplay.skaties.lv saturs"
40
+        self.headers = headers2dict("""
41
+User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
42
+Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
43
+Accept-Language: en-US,en;q=0.5
44
+""")
45
+        self.headers2 = headers2dict("""
46
+User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
47
+X-Requested-With: XMLHttpRequest
48
+Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
49
+""")
50
+        self.url = "http://login.tvplayhome.lt:8081/sb/public/"
51
+        self.kategorijas = [
52
+            ("zinas", "Ziņas un aktualitātes", 33, "tvplay.png", "Ziņas un aktualitātes"),
53
+            ("berniem", "Bērniem", 52, "tvplay.png", "Bērniem"),
54
+            ("seriali", "Seriāli", 38, "tvplay.png", "Seriāli"),
55
+            ("filmas", "Filmas", 72, "tvplay.png", "Filmas"),
56
+            ("izklaide", "Izklaide", 21, "tvplay.png", "Izklaide"),
57
+            ("sovi", "Šovi un raidijumi", 44, "tvplay.png", "Šovi un raidijumi"),
58
+            ("sports", "Sports", 32, "tvplay.png", "Sports"),
59
+            ("rus", "rus.tvplay.lv", 35, "tvplay.png", "Krievu raidijumi"),
60
+        ]
61
+
62
+    ######### Entry point ########
63
+    def get_content(self, data):
64
+        print "[lmt] get_content:", data
65
+        source, data, path, plist, clist, params, qs = self.parse_data(data)
66
+        content = []
67
+        content.append(("..return", "back","back.png","Return back"))
68
+
69
+        if clist=="home":
70
+            content.extend([
71
+                ("Meklēt", "tvplay::meklet/{0}","tvplay.png","Meklēt"),
72
+                ("Tiešraides", "tvplay::tiesraides","tvplay.png","Tiešraides"),
73
+                ("Jaunākās epizodes", "tvplay::jaunakais/epizodes", "tvplay.png", "Visu kategoriju jaunākie video"),
74
+                ("Jaunākie klipi", "tvplay::jaunakais/klipi", "tvplay.png", "Visu kategoriju jaunākie video"),
75
+                ("Jaunākais pa kategorijām", "tvplay::jaunakais/kategorijas", "tvplay.png", "Jaunākie video pa kategorijām žanru jaunākie video"),
76
+                ("Raidijumi pa kategorijām", "tvplay::raidijumi/kategorijas", "tvplay.png", "Jaunākie video pa kategorijām žanru jaunākie video"),
77
+            ])
78
+            return content
79
+
80
+        elif clist in ("meklet"):
81
+            term = plist[1]
82
+            data = "tvplay::asset/search?size=30&page=0&f_title.title=%s&f_country=LV&f_metadata.contentType=EPISODE" % term
83
+            return self.get_content(data)
84
+
85
+        elif clist in ("tiesraides"):
86
+            data = "tvplay::asset/search?size=30&page=0&f_metadata.contentType=LIVE"
87
+            return self.get_content(data)
88
+
89
+        elif clist == "jaunakais":
90
+            if plist[1] == "epizodes":
91
+                data = "tvplay::asset/search?f_title.categories=15004&size=30&page=0&f_metadata.contentType=EPISODE"
92
+                return self.get_content(data)
93
+            elif plist[1] == "klipi":
94
+                data = "tvplay::asset/search?f_title.categories=15004&size=30&page=0&f_metadata.contentType=CLIP"
95
+                return self.get_content(data)
96
+            elif plist[1] == "kategorijas":
97
+                for kat in self.kategorijas:
98
+                    content.append(("Jaunākais - "+kat[1], "tvplay::jaunakais/%s" % kat[0], kat[3], kat[4]))
99
+                return content
100
+            elif plist[1] in zip(*self.kategorijas)[0]:
101
+                for k in self.kategorijas:
102
+                    if k[0] == plist[1]:
103
+                        kat_num = k[2]
104
+                        break
105
+                else:
106
+                    return content
107
+                data = "tvplay::asset/search?f_title.categories=%s&size=30&page=0" % kat_num
108
+                return self.get_content(data)
109
+
110
+        elif clist == "raidijumi":
111
+            if plist[1] == "kategorijas":
112
+                for kat in self.kategorijas:
113
+                    content.append(("Raidijumi - "+kat[1], "tvplay::raidijumi/%s" % kat[0], kat[3], kat[4]))
114
+                    #content.append(kat[1], "tvplay::tvSeries/category/id/%s?type=tvseries&size=500&sort=title.title&descending=true" % kat[2], kat[3], kat[4])
115
+                return content
116
+            else:
117
+                for k in self.kategorijas:
118
+                    if k[0] == plist[1]:
119
+                        kat_num = k[2]
120
+                        break
121
+                else:
122
+                    return content
123
+                data = "tvplay::tvSeries/category/id/%s?type=tvseries&size=500&sort=title.title&descending=true" % kat_num
124
+                return self.get_content(data)
125
+
126
+        elif path == "asset/search":
127
+            r = self.call(data)
128
+            for item in r["content"]:
129
+                data2 = "asset/%s" % item["id"]
130
+                title, img, desc = self.get_title_desc(item)
131
+                content.append((title, self.name+"::"+data2, img, desc))
132
+
133
+            if "page" in qs and len(r["content"]) == 30:
134
+                page = int(qs["page"]) + 1
135
+                data2 = re.sub("page=\d+", "page=%s" % page, data)
136
+                content.append(("Next page",self.name+"::"+data2,"next.png","Next page"))
137
+            return content
138
+
139
+        elif plist[0] == "tvSeries" and plist[1] == "category":
140
+            r = self.call(data)
141
+            for item in r["content"]:
142
+                tvseries = True if "type" in qs and qs["type"] == "tvseries" else False
143
+                if tvseries and not "seasonNumber" in item:  # tvseries (programma)
144
+                    #if len(item["seasonIds"]) > 1:
145
+                        #tvseries_id = item["id"]
146
+                    #else:
147
+                       # tvseries_id = item["seasonIds"][0]
148
+                    data2 = "tvSeries/%s" % item["id"]
149
+                    title = item["title"]["title"]
150
+                    img = "http://login.tvplayhome.lt:8081" + item["posterUrl"] if "posterUrl" in item else self.img
151
+                    desc = []
152
+                    if "summaryLong" in  item["title"]:
153
+                        desc.append(item["title"]["summaryLong"])
154
+                    desc = "\n".join(desc)
155
+                    content.append((title, self.name+"::"+data2, img, desc))
156
+            if "page" in qs:
157
+                page = int(qs["page"]) + 1
158
+                data2 = re.sub("page=\d+", "page=%s" % page, data)
159
+                content.append(("Next page",self.name+"::"+data2,"next.png","Next page"))
160
+            return content
161
+
162
+        elif plist[0] == "tvSeries":
163
+            item = self.call(data)
164
+            if "seasonIds" in item and len(item["seasonIds"]) > 1:
165
+                title0 = item["title"]["title"] + ". " + "Visi video"
166
+                data2 = "asset/search?f_metadata.tvSeriesId=%s&page=0&size=30" % item["id"]
167
+                img = "http://login.tvplayhome.lt:8081" + item["posterUrl"] if "posterUrl" in item else self.img
168
+                desc = []
169
+                if "summaryShort" in item["title"]:
170
+                    desc.append(item["title"]["summaryShort"])
171
+                if "summaryLong" in item["title"]:
172
+                    desc.append(item["title"]["summaryLong"])
173
+                desc = "\n".join(desc)
174
+                content.append((title0, self.name+"::"+data2, img, desc))
175
+                for season in item["seasonIds"]:
176
+                    data2 = "tvSeries/%s" % season
177
+                    item = self.call(data2)
178
+                    title = item["title"]["title"]
179
+                    img = "http://login.tvplayhome.lt:8081" + item["posterUrl"] if "posterUrl" in item else self.img
180
+                    desc = []
181
+                    if "summaryShort" in item["title"]:
182
+                        desc.append(item["title"]["summaryShort"])
183
+                    if "summaryLong" in item["title"]:
184
+                        desc.append(item["title"]["summaryLong"])
185
+                    desc = "\n".join(desc)
186
+                    content.append((title, self.name+"::"+data2, img, desc))
187
+                return content
188
+            else:
189
+                data1 = item["vodAssetsUrl"].replace("/sb/public/", "")
190
+                data1 += "&size=30&page=0"
191
+                return self.get_content(data1)
192
+
193
+        ### kaut kas neparedzets ###
194
+        else:
195
+            return content
196
+
197
+    def get_title_desc(self, item):
198
+        title = item["title"]["title"]
199
+        if "titleBrief" in item["title"]:
200
+            title += ". " + item["title"]["titleBrief"]
201
+        img = "http://login.tvplayhome.lt:8081" + item["posterUrl"]
202
+        desc = []
203
+        if "summaryShort" in  item["title"]:
204
+            desc.append(item["title"]["summaryShort"])
205
+        if "summaryLong" in  item["title"] and item["title"]["summaryLong"] <> item["title"]["summaryShort"]:
206
+            desc.append(item["title"]["summaryLong"])
207
+        if "metadata" in item:
208
+            if "contentType" in  item["metadata"]:
209
+                if item["metadata"]["contentType"] == "CLIP":
210
+                    desc.append("Klips")
211
+                    #desc.append(item["metadata"]["contentType"])
212
+            if "seasonNumber" in item["metadata"]:
213
+                desc.append("Season: %s, episode: %s" % (item["metadata"]["seasonNumber"], item["metadata"]["episodeNumber"] if "episodeNumber" in item["metadata"] else ""))
214
+            if "displayRunTime" in item:
215
+                desc.append("Lenght: %s" % item["displayRunTime"])
216
+            if "airDate" in item["metadata"]:
217
+                desc.append("Aired: %s" % item["metadata"]["airDate"])
218
+                dd =  item["metadata"]["airDate"].split("T")[0].split("-")
219
+                title = title + " [%s.%s.%s]" % (dd[2], dd[1], dd[0])
220
+            if "licensingWindowEnd" in item["metadata"]:
221
+                desc.append("Till: %s" %item["metadata"]["licensingWindowEnd"])
222
+        desc = "\n".join(desc)
223
+        return title, img, desc
224
+
225
+
226
+
227
+    def is_video(self,data):
228
+        source,data,path,plist,clist,params,qs = self.parse_data(data)
229
+        if clist == "asset" and re.search("\d+", plist[1]):
230
+            return True
231
+        else:
232
+            return False
233
+
234
+    def call(self, data,params=None,headers=None,lang=""):
235
+        if not headers: headers = self.headers
236
+        url = self.url+data
237
+        r = requests.get(url,headers = headers)
238
+        result = json.loads(r.content)
239
+        #result = self._http_request(url,params,headers=headers)
240
+        return result
241
+
242
+    def get_streams(self,data):
243
+        print "[tvplay] get_streams:", data
244
+        if not self.is_video(data):
245
+            return []
246
+        source,data,path,plist,clist,params,qs = self.parse_data(data)
247
+        r = self.call(data)
248
+        if not ("movie" in r and "contentUrl" in r["movie"]):
249
+            return []
250
+        data2 = r["movie"]["contentUrl"]
251
+        title, img, desc = self.get_title_desc(r)
252
+        stream = util.item()
253
+        stream["name"] = title
254
+        stream["url"] = data2
255
+        stream["img"] = img
256
+        stream["desc"] = desc
257
+        stream["resolver"] = "tvplay"
258
+        return [stream]
259
+
260
+
261
+if __name__ == "__main__":
262
+    sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
263
+    import run
264
+    source = Source()
265
+    data= sys.argv[1] if len(sys.argv)>1 else source.name+"::home"
266
+    if len(sys.argv) > 2:
267
+        run.run_cli(source, data)
268
+    else:
269
+        run.run(source, data)
270
+    sys.exit()