Browse Source

Salabots vēlreiz replay, custom headeri iekš run player

Ivars 6 years ago
parent
commit
57e8c02483
4 changed files with 512 additions and 616 deletions
  1. 398
    569
      project.wpr
  2. 7
    0
      run.py
  3. 84
    32
      sources/replay.py
  4. 23
    15
      util.py

+ 398
- 569
project.wpr
File diff suppressed because it is too large
View File


+ 7
- 0
run.py View File

@@ -708,6 +708,13 @@ def player(url, title = "", subfile = "",headers={}, player="ffplay"):
708 708
         subfile = re.sub("\w:", "", subfile)
709 709
         vf = 'subtitles=%s,' % subfile + vf
710 710
     cmd3 = ["ffplay.exe",url, "-window_title", title, "-vf", vf]
711
+    if headers:
712
+        cmd3.append("-headers")
713
+        hd = []
714
+        for k in headers:
715
+            hd.append("%s:%s" % (k, headers[k]))
716
+        hd = "\n".join(hd)
717
+        cmd3.append(hd)
711 718
     if not player:
712 719
         cmd = cmd3 if url.startswith("https") else cmd2
713 720
     else:

+ 84
- 32
sources/replay.py View File

@@ -171,19 +171,23 @@ class Source(SourceBase):
171 171
                 m = re.search('datePublished" datetime="([^"]+)"', item, re.DOTALL)
172 172
                 if m:
173 173
                     published = m.group(1)
174
-                    published = datetime.datetime.strptime(published,"%Y-%m-%dT%H:%M:%SZ")
175
-                    published = util.datetime_from_utc_to_local(published)
176
-                    published_datetime = datetime.datetime.strftime(published,"%d.%m.%Y %H:%M")
177
-                    published_date = datetime.datetime.strftime(published,"%d.%m.%Y")
178
-                    title = title + " (%s)" % published_date
179
-                    desc = desc + "\nPublished: %s" % published_datetime
174
+                    try:
175
+                        published = util.datetime_from_zulu_to_utc(published)
176
+                        published = util.datetime_from_utc_to_local(published)
177
+                        published_datetime = datetime.datetime.strftime(published,"%d.%m.%Y %H:%M")
178
+                        published_date = datetime.datetime.strftime(published,"%d.%m.%Y")
179
+                        title = title + " (%s)" % published_date
180
+                        desc = desc + "\nPublished: %s" % published_datetime
181
+                    except:
182
+                        a = 1
183
+                        pass
180 184
                 m = re.search('thumbnail__duration">([^<]+)<', item, re.DOTALL)
181 185
                 if m:
182 186
                     desc = desc + "\nDuration: %s" % m.group(1)
183 187
                 m = re.search(r'<a href="https://replay\.lsm\.lv/lv/raidijums/[^"]+">([^<]+)</a>', item, re.DOTALL)
184 188
                 if m:
185 189
                     desc = desc + "\nProgram: %s" % m.group(1)
186
-                m = re.search('<li class="">(Vēl[^<]+)</li>', item, re.DOTALL)
190
+                m = re.search('<li class=".*?">(Vēl[^<]+)</li>', item, re.DOTALL)
187 191
                 if m:
188 192
                     desc = desc + "\nRemaining: %s" % m.group(1)
189 193
                 content.append((title,self.name+"::"+data2,img,desc))
@@ -202,28 +206,29 @@ class Source(SourceBase):
202 206
 
203 207
             return content
204 208
 
205
-
206
-
209
+    #===========================================================================
207 210
     def get_streams(self, data):
208 211
         source, data, path, plist, clist, params, qs = self.parse_data(data)
209
-        lang = qs["lang"] if "lang" in qs else self.country
212
+        lang = "ru" if clist == 'statja' else "lv"
213
+        headers2 = {}
214
+        nfo = {}
210 215
 
211 216
         ### Kanāla tiesraide
212
-        # TODO - jāuztaisa get_streams/get_info
213 217
         if clist == "tiesraide" and "/" in data:
214 218
             r = self.call(data, lang=lang)
215 219
             ch = data.split('/')[1]
220
+
216 221
             veids = "audio" if "lr" in ch else "video"
217
-            #url = "https://replay.lsm.lv/lv/tiesraide/ltv7/"
218 222
             url = "https://replay.lsm.lv/lv/tiesraide/%s/"%ch
219
-            r= self._http_request(url)
223
+            r = self._http_request(url)
220 224
 
221 225
             m = re.search('span class="badge badge-primary">Tagad</span>([^<]+)<.+?<time>([^<]+)</time>', r, re.DOTALL)
222 226
             tagad = m.group(1).strip() if m else ""
223 227
             laiks = m.group(2).strip() if m else ""
224 228
             laiks = h.unescape(laiks).encode("utf8")
225 229
             title = m.group(1).strip() if m else path.split("/")[1].upper()
226
-            title = "%s - %s [%s]"%(ch.upper(), title,laiks)
230
+            dd = datetime.datetime.now().strftime("%d.%m.%Y")
231
+            title = "%s - %s (%s) [%s]"%(ch.upper(), title, dd, laiks)
227 232
             desc = title
228 233
 
229 234
             if veids == "video":
@@ -241,16 +246,21 @@ class Source(SourceBase):
241 246
                 m = re.search(r'iframe src=\\"([^"]+)\\', r)
242 247
                 if not m:
243 248
                     raise Exception("No stream found")
244
-                url = m.group(1).replace('\\/', "/")
249
+                url2 = m.group(1).replace('\\/', "/")
245 250
                 m = re.search('poster":"([^"]+)"', r, re.DOTALL)
246 251
                 img =  "https://ltv.lsm.lv" + m.group(1).replace("\\","") if m else ch + '.png'
247 252
 
248
-                r = self._http_request(url,headers=headers)
253
+                r = self._http_request(url2,headers=headers)
249 254
                 m = re.search('"([^"]+m3u8[^"]+)"', r)
250 255
                 if not m:
251 256
                     raise Exception("No stream found")
252 257
                 data2 = m.group(1).replace("\\","")
253
-                #r = self._http_request(data2, headers=headers)
258
+                headers2["Referer"] = url2
259
+                headers2["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36"
260
+                headers2["Origin"] = "https://embed.lsm.lv"
261
+                headers2["Host"] = data2.split("/")[2]
262
+                #r = self._http_request(data2, headers=headers2)
263
+                a = 1
254 264
 
255 265
             else: # audio
256 266
                 lrn = ch.replace("lr","")
@@ -270,35 +280,74 @@ class Source(SourceBase):
270 280
             if not m:
271 281
                 raise Exception("No stream found")
272 282
             url2 = m.group(1).replace("&amp;", "&")
273
-            m = re.search('<h1 class="title">([^<]+)</h1>', r)
274
-            title = m.group(1).strip()
283
+            #m = re.search('<h1 class="title">([^<]+)</h1>', r)
284
+            m = re.search('<meta name="name" content="([^"]+)">', r)
285
+            title = m.group(1)
286
+            title = title.replace("- REplay.lv", "")
287
+            title = title.strip()
288
+            m = re.search('<meta content="([^"]+)" property="og:video:release_date"', r)
289
+            if m:
290
+                dd = m.group(1).split("T")[0].split("-")
291
+                title += " (%s.%s.%s)" % (dd[2], dd[1], dd[0])
275 292
             m = re.search('<meta content="([^"]+)" property="og:image">', r)
276 293
             img = m.group(1) if m else ""
277 294
             m = re.search('<div class="description">(.+?)</div>', r, re.DOTALL)
278 295
             if m:
279
-                desc = m.group(1)
296
+                plot = m.group(1)
280 297
                 rr = re.sub("<.+?>", " ", m.group(1))
281 298
                 rr = re.sub("[\t\n]", " ", rr)
282
-                desc =  re.sub(" {2,100}", " ", rr).strip()
299
+                plot =  re.sub(" {2,100}", " ", rr).strip()
283 300
             else:
284
-                desc = ""
301
+                plot = ""
302
+            desc = [title]
303
+            m = re.search(r'<figure><span class="channel-logo (\w+)"></span></figure>([^<]+)</a>', r, re.IGNORECASE)
304
+            if m:
305
+                desc.append("Programma: %s [%s]" % (m.group(2), m.group(1).upper()))
306
+            m = re.search('<ul class="media-info-list">(.+?)</ul>', r, re.DOTALL)
307
+            if m:
308
+                for m2 in re.finditer("<strong>([^<]+)</strong> *(<a[^<]+?>)*([^<]+)*<", m.group(1)):
309
+                    desc.append("%s %s" % (m2.group(1).strip(),m2.group(3).strip() if m2.group(3) else ""))
310
+                m2 = re.search('li class="[^"]*">(Pieejam.+)</li>', m.group(1))
311
+                if m2:
312
+                    desc.append(m2.group(1))
313
+            desc.append(plot)
314
+            desc = "\n".join(desc)
315
+
285 316
             headers = headers2dict("""
286 317
 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36
287 318
 Referer: https://replay.lsm.lv/%s/%s
288
-Host: ltv.lsm.lv
289 319
             """% (lang, data))
290 320
             r2 = self._http_request(url2,headers=headers)
291 321
             m = re.search(r"<script>LTV.Video.players.create\('videoplay', ({.+?})\);</script>", r2, re.DOTALL)
292 322
             #m = re.search('"file":"([^"]+)', r2)
293
-            if not m:
294
-                raise Exception("No stream found")
295
-            js = json.loads(m.group(1))
296
-            if "playlist" in js["player"]:
297
-                data2 = js["player"]["playlist"][0]["sources"][0]["file"]
298
-            elif "file" in  js["player"]:
299
-                data2 = js["player"]["file"]
300
-            else:
301
-                raise Exception("No stram found")
323
+            if m:
324
+                js = json.loads(m.group(1))
325
+                if js["ext_video_id"]:
326
+                    data2 = "https://www.youtube.com/watch?v=" + js["ext_video_id"]
327
+                elif "playlist" in js["player"]:
328
+                    data2 = js["player"]["playlist"][0]["sources"][0]["file"]
329
+                elif "clip" in js["player"]:
330
+                    if len(js["player"]["clip"]["sources"]) > 0:
331
+                        data2 = js["player"]["clip"]["sources"][0]["src"]
332
+                    else:
333
+                        raise Exception("No streams found!")
334
+                elif "file" in  js["player"]:
335
+                    data2 = js["player"]["file"]
336
+                else:
337
+                    raise Exception("No stram found")
338
+            else:  # futbols u.c.
339
+                m = re.search('<div class="video-player">.+?<iframe src="([^"]+)', r2, re.DOTALL)
340
+                if not m:
341
+                    raise Exception("No stream found")
342
+                url3 = "https:" + m.group(1)
343
+                headers["Referer"] = url2
344
+                r3 = self._http_request(url3, headers=headers)
345
+                m = re.search(r"src: '([^']+)',\s+?type: 'application/x-mpegurl'", r3, re.DOTALL)
346
+                if not m:
347
+                    raise Exception("No stream found")
348
+                data2 = "https:" + m.group(1)
349
+
350
+
302 351
             if "youtube" in data2:
303 352
                 video_id = re.search(r"/watch\?v=([^&]+)",data2).group(1)
304 353
                 data2 = YouTubeVideoUrl().extract(video_id)
@@ -311,6 +360,9 @@ Host: ltv.lsm.lv
311 360
         stream["img"] = img
312 361
         stream["desc"] = desc
313 362
         stream["resolver"] = "replay"
363
+        stream["headers"] = headers2
364
+        stream["nfo"] = nfo
365
+        #stream["filename"] = filename # TODO jāģenere jēdzigs faila nosaukums, kuru pēc tam izmanto downloadsb
314 366
         return [stream]
315 367
 
316 368
     def is_video(self,data):

+ 23
- 15
util.py View File

@@ -673,30 +673,38 @@ def datetime_from_utc_to_local(utc_datetime):
673 673
     offset = datetime.datetime.fromtimestamp(now_timestamp) - datetime.datetime.utcfromtimestamp(now_timestamp)
674 674
     return utc_datetime + offset
675 675
 
676
+def datetime_from_zulu_to_utc(data):
677
+    d = map(int, data.split("T")[0].split("-"))
678
+    h = map(int, data.split("T")[1][:-1].split(":"))
679
+    dt = datetime.datetime(d[0], d[1], d[2], h[0], h[1], h[2])
680
+    return dt
681
+
676 682
 #def parse_html(url):
677 683
 #    return BeautifulSoup(request(url), 'html5lib', from_encoding='utf-8')
678 684
 
679 685
 if __name__ == "__main__":
686
+
687
+    datetime_from_zulu_to_utc('2018-06-24T06:10:00Z')
680 688
     s = open("The LEGO Ninjago Movie (2017).lv.vtt").read()
681
-    s2 = vtt2srt(s)
682
-    open("The LEGO Ninjago Movie (2017).lv.srt", "w").write(s2)
689
+    #s2 = vtt2srt(s)
690
+    #open("The LEGO Ninjago Movie (2017).lv.srt", "w").write(s2)
683 691
 
684
-    s = 'B\xc4\x93thovena D\xc4\x81rgumu Taka (2014)/Beethoven&#x27;s Treasure [LV]'
692
+    #s = 'B\xc4\x93thovena D\xc4\x81rgumu Taka (2014)/Beethoven&#x27;s Treasure [LV]'
685 693
     #s = s.decode("utf8")
686 694
     #s=unescape(s)
687 695
     #url = "http://localhost:88/https://walterebert.com/playground/video/hls/ts/480x270.m3u8?token=xxxx~User-Agent=Enigma2~Cookie=xxxxx"
688
-    url = "http://hyt4d6.vkcache.com/secip/0/UMQ3q2gNjTlOPnEVm3iTiA/ODAuMjMyLjI0MC42/1479610800/hls-vod-s3/flv/api/files/videos/2015/09/11/144197748923a22.mp4.m3u8http://hyt4d6.vkcache.com/secip/0/Y-ZA1qRm8toplc0dN_L6_w/ODAuMjMyLjI0MC42/1479654000/hls-vod-s3/flv/api/files/videos/2015/09/11/144197748923a22.mp4.m3u8"
689
-    headers = {"User-Agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 9_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/47.0.2526.70 Mobile/13C71 Safari/601.1.46"}
690
-    url = "http://str1e.lattelecom.tv/mobile-vod/mp4:sf_fantastic_beasts_and_where_to_find_them_en_hd.mp4/playlist.m3u8?resource_id=fantastic_beasts_and_where_to_find_them&auth_token=6NAvMFDG+rYTAc4hb5JeL2bmsaRR7bAE23M6KDmhKYOGyXoo0gDpJUE9scYy+nQmfbgk03cWMe9MuXWSH1GqwolEk2jOQ/8Mrg7tOdbwrA8zM7nmkfCZPqQkwajZN4mfSJQVKHqXqJ8="
691
-    headers={}
692
-    print url
693
-    url = "replay::tiesraide/ltv1/"
694
-    url = "ltc::content/live-streams/103?include=quality"
695
-    urlp = streamproxy_encode2(url,headers)
696
-    print urlp
697
-    url2,headers2 = streamproxy_decode2(urlp)
698
-    print url2
699
-    player(urlp)
696
+    #url = "http://hyt4d6.vkcache.com/secip/0/UMQ3q2gNjTlOPnEVm3iTiA/ODAuMjMyLjI0MC42/1479610800/hls-vod-s3/flv/api/files/videos/2015/09/11/144197748923a22.mp4.m3u8http://hyt4d6.vkcache.com/secip/0/Y-ZA1qRm8toplc0dN_L6_w/ODAuMjMyLjI0MC42/1479654000/hls-vod-s3/flv/api/files/videos/2015/09/11/144197748923a22.mp4.m3u8"
697
+    #headers = {"User-Agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 9_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/47.0.2526.70 Mobile/13C71 Safari/601.1.46"}
698
+    #url = "http://str1e.lattelecom.tv/mobile-vod/mp4:sf_fantastic_beasts_and_where_to_find_them_en_hd.mp4/playlist.m3u8?resource_id=fantastic_beasts_and_where_to_find_them&auth_token=6NAvMFDG+rYTAc4hb5JeL2bmsaRR7bAE23M6KDmhKYOGyXoo0gDpJUE9scYy+nQmfbgk03cWMe9MuXWSH1GqwolEk2jOQ/8Mrg7tOdbwrA8zM7nmkfCZPqQkwajZN4mfSJQVKHqXqJ8="
699
+    #headers={}
700
+    #print url
701
+    #url = "replay::tiesraide/ltv1/"
702
+    #url = "ltc::content/live-streams/103?include=quality"
703
+    #urlp = streamproxy_encode2(url,headers)
704
+    #print urlp
705
+    #url2,headers2 = streamproxy_decode2(urlp)
706
+    #print url2
707
+    #player(urlp)
700 708
     pass
701 709
 
702 710