Browse Source

darba versija

Ivars 6 years ago
parent
commit
ac3e334e38
4 changed files with 100 additions and 74 deletions
  1. 30
    18
      Downloader.py
  2. 4
    0
      file.py
  3. 62
    52
      project.wpr
  4. 4
    4
      sources/ltc.py

+ 30
- 18
Downloader.py View File

@@ -88,24 +88,35 @@ class DownloadWithProgressFragmented:
88 88
 
89 89
     def start_download(self):
90 90
         print "Start download"
91
-        try:
92
-            r = requests.get(self.url,headers=self.headers)
93
-        except Exception as e:
94
-            #self.deferred.errback("Cannot open manifsest file - %s"%url)
95
-            self.deferred.errback(e)
96
-        if not r.content.startswith("#EXTM3U"):
97
-            self.deferred.errback(Exception("Not valid manifest file - %s"%self.url))
98
-        streams = re.findall(r"#EXT-X-STREAM-INF:.*?BANDWIDTH=(\d+).*?\n(.+?)$", r.content, re.IGNORECASE | re.MULTILINE)
99
-        if streams:
100
-            streams = sorted(streams, key=lambda item: int(item[0]), reverse=True)
101
-            url = streams[0][1]
102
-            if not url.startswith("http"):
103
-                url = self.base_url + url
91
+        url = self.url
92
+        while True:
93
+            base_url = url.split("?")[0]
94
+            base_url = "/".join(base_url.split("/")[:-1])+"/"
104 95
             try:
105
-                r = requests.get(url, headers=self.headers)
96
+                r = requests.get(url,headers=self.headers)
106 97
             except Exception as e:
107
-                self.deferred.errback(Exception("Cannot open manifsest file - %s"%url))
108
-        self.base_url = "/".join(url.split("/")[:-1])+"/"
98
+                #self.deferred.errback("Cannot open manifsest file - %s"%url)
99
+                self.deferred.errback(e)
100
+            if not r.content.startswith("#EXTM3U"):
101
+                self.deferred.errback(Exception("Not valid manifest file - %s"%self.url))
102
+            streams = re.findall(r"#EXT-X-STREAM-INF:.*?BANDWIDTH=(\d+).*?\n(.+?)$", r.content, re.IGNORECASE | re.MULTILINE)
103
+            if streams:
104
+                streams = sorted(streams, key=lambda item: int(item[0]), reverse=True)
105
+                url = streams[0][1]
106
+                if not url.startswith("http"):
107
+                    url = base_url + url
108
+                try:
109
+                    r = requests.get(url, headers=self.headers)
110
+                except Exception as e:
111
+                    self.deferred.errback(Exception("Cannot open manifsest file - %s"%url))
112
+                if "#EXT-X-STREAM-INF" in r.content:
113
+                    continue
114
+                else:
115
+                    break
116
+            else:
117
+                self.deferred.errback(Exception("No streams found for - %s"%url))
118
+
119
+        self.base_url = base_url
109 120
         self.ts_list = re.findall(r"#EXTINF:([\d\.]+),.*?\n(.+?)$", r.content, re.IGNORECASE | re.MULTILINE)
110 121
         if not len(self.ts_list):
111 122
             self.deferred.errback(Exception("Cannot read fragment list in  manifsest file - %s"%url))
@@ -241,7 +252,7 @@ def stop():
241 252
 
242 253
 ###############################################
243 254
 
244
-def download_video(url,output,headers=None):
255
+def download_video_file(url,output,headers=None):
245 256
     #output = stream["name"].replace("\\"," ").replace(":"," ").replace("|"," ")
246 257
     if not headers:
247 258
         headers = {"user-agent":"Enigma2"}
@@ -267,6 +278,7 @@ if __name__ == "__main__":
267 278
         output = sys.argv[2]
268 279
     else:
269 280
         url = url2 = "http://walterebert.com/_/playground/videos/sintel-trailer.m3u8"
281
+        url = "http://str5e.lattelecom.tv/mobile-vod/mp4:sv_ka_sapni_lv_hq.mp4/playlist.m3u8?resource_id=like_a_dream&auth_token=ISVlUKAuwHJEFFKlHQ9e/GVIoKExOwcu0ymn2AEyeOhn2BAwzmy+csGxUe9MeKooEdjS+xJfmP6XPCuqlZIpe4k/UfGAwn0BQ/chunklist_w1465619955.m3u8?resource_id=like_a_dream&auth_token=ISVlUKAuwHJEFFKlHQ9e%2FGVIoKExOwcu0ymn2AEyeOhn2BAwzmy+csGxUe9MeKooEdjS+xJfmP6XPCuqlZIpe4k%2FUfGAwn0BQ%2FuGk9oBsD4%3D"
270 282
         output = "tmp\\test"
271 283
         #url = "https://r3---sn-bavc5ajvh-gpme.googlevideo.com/videoplayback?key=yt6&mime=video%2Fmp4&sparams=clen%2Cdur%2Cei%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cupn%2Cexpire&expire=1490986184&lmt=1490940183963773&dur=1302.639&itag=18&ratebypass=yes&mm=31&requiressl=yes&ipbits=0&upn=azFGj8gY02w&ip=85.254.87.15&pl=23&ei=aFDeWLzqDcn-dLC_gdAM&signature=083F353AC09CD98A70AD7D9438DD3C91C781166B.715456B9C35F040BDC4728CA76A0D1779B684A90&source=youtube&mv=m&mt=1490964451&ms=au&mn=sn-bavc5ajvh-gpme&gir=yes&clen=73596250&id=o-AGH9y-hWn1MtW1VzCyI_8XYYEWODsTDBZbfagQH3BrfQ&initcwndbps=4493750"
272 284
         #url = "http://techslides.com/demos/sample-videos/small.mp4"
@@ -275,7 +287,7 @@ if __name__ == "__main__":
275 287
         #url = "http://vod-hls-uk-live.akamaized.net/usp/auth/vod/piff_abr_full_hd/a3e90e-b08ktytr/vf_b08ktytr_f9d55583-afc7-49bb-9bf4-d8f1ac99f56f.ism.hlsv2.ism/vf_b08ktytr_f9d55583-afc7-49bb-9bf4-d8f1ac99f56f.ism.hlsv2-audio=128000-video=5070000.m3u8"
276 288
         #url = "https://58174450afee9.streamlock.net/vod/mp4:_definst_/f/e/8e49fc32.mp4/playlist.m3u8?safwerwfasendtime=1490877870&safwerwfasstarttime=1490859339&safwerwfashash=hS2FfVZysQVazBQ6RJn1IhUevBkKxIF09Ly3BjfT43U="
277 289
     active = 2
278
-    d1 = download_video(url,output)
290
+    d1 = download_video_file(url,output)
279 291
     reactor.run()
280 292
 
281 293
 

+ 4
- 0
file.py View File

@@ -87,6 +87,8 @@ def open(url, mode="r", encoding=""):
87 87
 def exists(url):
88 88
     p = parse_url(url)
89 89
     if p["protocol"] == "file":
90
+        if isinstance(url, str):
91
+            url = url.decode("utf8")
90 92
         return os.path.exists(url)
91 93
     elif p["protocol"] in ("ftp", "http", "https"):
92 94
         try:
@@ -101,6 +103,8 @@ def exists(url):
101 103
 def isdir(url):
102 104
     p = parse_url(url)
103 105
     if p["protocol"] == "file":
106
+        if isinstance(url, str):
107
+            url = url.decode("utf8")
104 108
         return os.path.isdir(url)
105 109
     elif p["protocol"] in ("ftp"):
106 110
         file = ftplib.FTP(p["host"], p["user"], p["password"])

+ 62
- 52
project.wpr View File

@@ -13,9 +13,6 @@ proj.directory-list = [{'dirloc': loc('.'),
13 13
 proj.file-type = 'normal'
14 14
 proj.launch-config = {loc('ContentSources.py'): ('project',
15 15
         (u'config::home streams_bernu.cfg',
16
-         '')),
17
-                      loc('Downloader.py'): ('project',
18
-        (u'http://player.tvnet.lv/stream/amlst:75136/playlist.m3u8 downloads\\ccc',
19 16
          '')),
20 17
                       loc('iub_db.py'): ('project',
21 18
         (u'-d 90   -s -o',
@@ -42,14 +39,18 @@ proj.launch-config = {loc('ContentSources.py'): ('project',
42 39
         (u'home',
43 40
          ''))}
44 41
 [user attributes]
45
-debug.breakpoints = {loc('Downloader.py'): {182L: (0,
42
+debug.breakpoints = {loc('Downloader.py'): {94: (0,
46 43
         None,
47 44
         1,
48 45
         0),
49
-        231: (0,
50
-              None,
51
-              1,
52
-              0)},
46
+        102L: (0,
47
+               None,
48
+               1,
49
+               0),
50
+        193L: (0,
51
+               None,
52
+               1,
53
+               0)},
53 54
                      loc('iub.py'): {102: (0,
54 55
         None,
55 56
         1,
@@ -200,6 +201,7 @@ debug.breakpoints = {loc('Downloader.py'): {182L: (0,
200 201
         0)}}
201 202
 debug.err-values = {None: {},
202 203
                     loc('ContentSources.py'): {},
204
+                    loc('Downloader.py'): {},
203 205
                     loc('iub_db.py'): {},
204 206
                     loc('iub_email.py'): {},
205 207
                     loc('iubx.py'): {},
@@ -276,8 +278,8 @@ debug.recent-run-args = {loc('ContentSources.py'): [u'config::home streams_bernu
276 278
         u'home cli'],
277 279
                          loc('sources/ltc.py'): [u'ltc::videonoma']}
278 280
 debug.run-args = {}
279
-debug.var-col-widths = [0.41872791519434627,
280
-                        0.5812720848056537]
281
+debug.var-col-widths = [0.15347490347490347,
282
+                        0.8465250965250966]
281 283
 edit.bookmarks = {'list_action': (loc('run.py'),
282 284
                                   {'attrib-starts': [('Main',
283 285
         17),
@@ -827,11 +829,11 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
827 829
                                        'expanded-nodes': [],
828 830
                                        'selected-nodes': [],
829 831
                                        'top-node': None},
830
-        loc('unknown:<untitled> #6'): {'column-widths': [1.0],
831
-                                       'expanded-nodes': [],
832
+        loc('unknown:<untitled> #6'): {'expanded-nodes': [],
832 833
                                        'selected-nodes': [],
833 834
                                        'top-node': None},
834
-        loc('unknown:<untitled> #4'): {'expanded-nodes': [],
835
+        loc('unknown:<untitled> #4'): {'column-widths': [1.0],
836
+                                       'expanded-nodes': [],
835 837
                                        'selected-nodes': [],
836 838
                                        'top-node': None},
837 839
         loc('unknown:<untitled> #5'): {'expanded-nodes': [],
@@ -971,14 +973,18 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
971 973
         -1,
972 974
         -1),
973 975
                        'attrib-starts': [],
974
-                       'first-line': 0L,
976
+                       'first-line': 92L,
975 977
                        'folded-linenos': [],
976
-                       'history': {},
978
+                       'history': {u'file:C:/Data/Programming/Kodi/plugin.video.playstream/resources/lib/content/Downloader.py': ['p'\
979
+        'rint self.url\n',
980
+        'print url\n',
981
+        'print base_url\n',
982
+        'print r.content\n']},
977 983
                        'launch-id': None,
978
-                       'sel-line': 0L,
979
-                       'sel-line-start': 0L,
980
-                       'selection_end': 0L,
981
-                       'selection_start': 0L,
984
+                       'sel-line': 92L,
985
+                       'sel-line-start': 6549L,
986
+                       'selection_end': 6683L,
987
+                       'selection_start': 6683L,
982 988
                        'zoom': 0L}),
983 989
                      ('debug-watch',
984 990
                       'wide',
@@ -990,10 +996,12 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
990 996
                                        ('eval',
991 997
         u'theme'),
992 998
                                        ('eval',
993
-        u'item')],
999
+        u'item'),
1000
+                                       ('eval',
1001
+        u'url')],
994 1002
                        'tree-state': {'expanded-nodes': [(0,),
995 1003
         (1,)],
996
-                                      'selected-nodes': [(2,)],
1004
+                                      'selected-nodes': [(3,)],
997 1005
                                       'top-node': (0,)}}),
998 1006
                      ('messages',
999 1007
                       'wide',
@@ -1035,22 +1043,9 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
1035 1043
          'sel-line': 362L,
1036 1044
          'sel-line-start': 16151L,
1037 1045
          'selection_end': 16181L,
1038
-         'selection_start': 16181L,
1046
+         'selection_start': 16172L,
1039 1047
          'zoom': 0L},
1040
-        1526594111.402],
1041
-        [loc('sources/filmix.py'),
1042
-         {'attrib-starts': [('Source',
1043
-                             31),
1044
-                            ('Source.get_movie_info',
1045
-                             355)],
1046
-          'first-line': 354L,
1047
-          'folded-linenos': [],
1048
-          'sel-line': 362L,
1049
-          'sel-line-start': 16151L,
1050
-          'selection_end': 16181L,
1051
-          'selection_start': 16172L,
1052
-          'zoom': 0L},
1053
-         1526594111.565],
1048
+        1526594111.565],
1054 1049
         [loc('sources/filmix.py'),
1055 1050
          {'attrib-starts': [('Source',
1056 1051
                              31),
@@ -1284,9 +1279,22 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
1284 1279
           'selection_end': 8610L,
1285 1280
           'selection_start': 8610L,
1286 1281
           'zoom': 0L},
1287
-         1527705483.405]],
1282
+         1527705483.405],
1283
+        [loc('sources/filmix.py'),
1284
+         {'attrib-starts': [('Source',
1285
+                             31),
1286
+                            ('Source.get_content',
1287
+                             56)],
1288
+          'first-line': 83L,
1289
+          'folded-linenos': [],
1290
+          'sel-line': 94L,
1291
+          'sel-line-start': 3471L,
1292
+          'selection_end': 3471L,
1293
+          'selection_start': 3471L,
1294
+          'zoom': 0L},
1295
+         1528141882.377]],
1288 1296
         20),
1289
-        'current-loc': loc('sources/filmix.py'),
1297
+        'current-loc': loc('Downloader.py'),
1290 1298
         'editor-state-list': [(loc('run.py'),
1291 1299
                                {'attrib-starts': [('Main',
1292 1300
         22),
@@ -1369,14 +1377,16 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
1369 1377
                                 'selection_start': 8920L,
1370 1378
                                 'zoom': 0L}),
1371 1379
                               (loc('Downloader.py'),
1372
-                               {'attrib-starts': [('get_header',
1373
-        195)],
1374
-                                'first-line': 175L,
1375
-                                'folded-linenos': [],
1376
-                                'sel-line': 198L,
1377
-                                'sel-line-start': 7992L,
1378
-                                'selection_end': 8012L,
1379
-                                'selection_start': 8012L,
1380
+                               {'attrib-starts': [('print_progress',
1381
+        237)],
1382
+                                'first-line': 248L,
1383
+                                'folded-linenos': [9L,
1384
+        47L,
1385
+        76L],
1386
+                                'sel-line': 239L,
1387
+                                'sel-line-start': 9698L,
1388
+                                'selection_end': 9724L,
1389
+                                'selection_start': 9724L,
1380 1390
                                 'zoom': 0L}),
1381 1391
                               (loc('sources/euronews.py'),
1382 1392
                                {'attrib-starts': [],
@@ -1429,7 +1439,7 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
1429 1439
                                 'selection_end': 3471L,
1430 1440
                                 'selection_start': 3471L,
1431 1441
                                 'zoom': 0L})],
1432
-        'has-focus': False,
1442
+        'has-focus': True,
1433 1443
         'locked': False},
1434 1444
         [loc('run.py'),
1435 1445
          loc('util.py'),
@@ -1444,7 +1454,6 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
1444 1454
          loc('changelog.md'),
1445 1455
          loc('sources/filmix.py')]),
1446 1456
                                'open_files': [u'ContentSources.py',
1447
-        u'Downloader.py',
1448 1457
         u'changelog.md',
1449 1458
         u'resolver.py',
1450 1459
         u'run.py',
@@ -1454,9 +1463,10 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
1454 1463
         u'sources/ltc.py',
1455 1464
         u'sources/replay.py',
1456 1465
         u'util.py',
1457
-        u'sources/filmix.py']},
1466
+        u'sources/filmix.py',
1467
+        u'Downloader.py']},
1458 1468
         'saved_notebook_display': None,
1459
-        'split_percents': {0: 0.5061155630535639},
1469
+        'split_percents': {0: 0.47474747474747475},
1460 1470
         'splits': 2,
1461 1471
         'tab_location': 'top',
1462 1472
         'user_data': {}},
@@ -1469,7 +1479,8 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
1469 1479
                          0,
1470 1480
                          2434,
1471 1481
                          1440)}]}
1472
-guimgr.recent-documents = [loc('sources/filmix.py'),
1482
+guimgr.recent-documents = [loc('Downloader.py'),
1483
+                           loc('sources/filmix.py'),
1473 1484
                            loc('util.py'),
1474 1485
                            loc('sources/ltc.py'),
1475 1486
                            loc('sources/replay.py'),
@@ -1479,7 +1490,6 @@ guimgr.recent-documents = [loc('sources/filmix.py'),
1479 1490
                            loc('ContentSources.py'),
1480 1491
                            loc('sources/euronews.py'),
1481 1492
                            loc('resolver.py'),
1482
-                           loc('Downloader.py'),
1483 1493
                            loc('sources/lmt.py')]
1484 1494
 guimgr.visual-state = {loc('../../../Python25/Lib/BeautifulSoup.py'): {'attr'\
1485 1495
         'ib-starts': [('NavigableString',

+ 4
- 4
sources/ltc.py View File

@@ -89,7 +89,7 @@ X-Requested-With: XMLHttpRequest
89 89
                 ("TV arhīvs", "ltc::arhivs","","TV arhīvs atseviškiem kanāliem"),
90 90
                 ("Bērnu", "ltc::videonoma/bernu","","Videonomas bērnu filmas un seriāli"),
91 91
                 ("Filmas", "ltc::videonoma/filmas","","Videonomas filmas"),
92
-                ("Premiere filas", "ltc::videonoma/premiere","","Videonomas premiere filmas"),
92
+                ("Premiere filmas", "ltc::videonoma/premiere","","Videonomas premiere filmas"),
93 93
                 ("Seriāli", "ltc::videonoma/series","","Videonomas seriāli"),
94 94
                 ("360 Play", "ltc::videonoma/360play","","Videonomas lattelecom saturs"),  # TODO
95 95
                 #("Videonoma", "ltc::videonoma","","Filmas (arī Priemiere) un seriāli"),
@@ -214,7 +214,7 @@ X-Requested-With: XMLHttpRequest
214 214
                 data2 = re.sub("until_id=\d+","until_id="+item["id"],data)
215 215
             else:
216 216
                 data2 = data + "&until_id=%s"%item["id"]
217
-            content.append(("Next page",self.name+"::"+data2,"","Go to next page"))
217
+            content.append(("Next page",self.name+"::"+data2,"next.png","Go to next page"))
218 218
             return content
219 219
 
220 220
         ### Arhīva kanānālu saraksts
@@ -343,7 +343,7 @@ X-Requested-With: XMLHttpRequest
343 343
             if m:
344 344
                 page = int(m.group(1))
345 345
                 data2 = re.sub("page=\d+","page=%s"%(page+1),data)
346
-                content.append(("Next page",self.name+"::"+data2,"","Go to next page"))
346
+                content.append(("Next page",self.name+"::"+data2,"next.png","Go to next page"))
347 347
             return content
348 348
 
349 349
         ### Filmas galvenā ###
@@ -452,7 +452,7 @@ X-Requested-With: XMLHttpRequest
452 452
                 else:
453 453
                     section = re.search('data-section="(\d+)"', r).group(1)
454 454
                     data2 = "load_more.json?pack=1&section=%s" % section
455
-                content.append(("Next page",self.name+"::"+data2,"","Go to next page"))
455
+                content.append(("Next page",self.name+"::"+data2,"next.png","Go to next page"))
456 456
             return content
457 457
 
458 458