Ivars hace 7 años
padre
commit
f9456aad09
Se han modificado 2 ficheros con 141 adiciones y 133 borrados
  1. 17
    31
      Downloader.py
  2. 124
    102
      project.wpr

+ 17
- 31
Downloader.py Ver fichero

@@ -189,7 +189,7 @@ class DownloadWithProgressFragmented:
189 189
         self.deferred.errback() # TODO
190 190
 
191 191
     def addProgress(self, progress_callback):
192
-        print "[addProgress]"
192
+        #print "[addProgress]"
193 193
         self.progress_callback = progress_callback
194 194
 
195 195
 #####################################################################################################
@@ -222,72 +222,58 @@ def get_ext(mtype):
222 222
         return ".mp4","http"
223 223
 
224 224
 
225
-
226 225
 ##############################################
227 226
 def print_progress(currentbytes, totalbytes):
228 227
     progress = float(currentbytes)/float(totalbytes)*100
229 228
     print "%s (%i/%i)"%(progress,currentbytes,totalbytes)
230 229
 
231 230
 def download_ok(*args):
232
-    print "Download OK"
233
-    reactor.stop()
231
+    print "Finished"
232
+    stop()
234 233
 
235 234
 def download_err(e):
236 235
     print "Download Error %s"%e.getBriefTraceback()
237
-    pass
236
+    stop()
237
+
238 238
 def stop():
239 239
     reactor.stop()
240
+
240 241
 ###############################################
241 242
 
242
-def download_video(stream):
243
-    stream = stream[0]
244
-    url = stream["url"]
245
-    headers = stream["headers"]
246
-    output = stream["name"].replace("\\"," ").replace(":"," ").replace("|"," ")
243
+def download_video(url,output,headers=None):
244
+    #output = stream["name"].replace("\\"," ").replace(":"," ").replace("|"," ")
245
+    if not headers:
246
+        headers = {"user-agent":"Enigma2"}
247 247
     try:
248
-        h = get_header(url,headers={"user-agent":"Enigma2"})
248
+        h = get_header(url,headers=headers)
249 249
         mtype = h.get("content-type")
250 250
         ext,stream_type = get_ext(mtype)
251 251
     except:
252 252
         ext,stream_type = (".ts","hls")
253
-    #output = urlparse.urlparse(url)[2].split('/')[-1] + ext
254 253
     output = output+ext
255
-    output = os.path.join("downloads", output)
256 254
     if stream_type == "hls":
257 255
         d = DownloadWithProgressFragmented(url,output,headers={"user-agent":"Enigma2"})
258 256
     else:
259 257
         d = DownloadWithProgress(url,output,headers={"user-agent":"Enigma2"})
260 258
     d.addProgress(print_progress)
261 259
     d.start().addCallback(download_ok).addErrback(download_err)
262
-    reactor.run()
260
+    return d
263 261
 
264 262
 
265 263
 if __name__ == "__main__":
266 264
     if len(sys.argv)>2:
267 265
         url= sys.argv[1]
268
-        output = sys.argv[1]
266
+        output = sys.argv[2]
269 267
     else:
270
-        url = "http://walterebert.com/playground/video/hls/ts/480x270.m3u8"
271
-        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"
268
+        url = url2 = "http://walterebert.com/playground/video/hls/ts/480x270.m3u8"
269
+        #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 270
         #url = "http://techslides.com/demos/sample-videos/small.mp4"
273 271
         #url = "http://wx17.poiuytrew.pw/s/c507282042b1bf25e0b72c34a68426f3/hd_30/Jackie.2016.D.iTunes.BDRip.1080p_720.mp4"
274 272
         #url = "http://player.tvnet.lv/live/amlst:11/chunklist_w361981294_b528000.m3u8"
275 273
         #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 274
         #url = "https://58174450afee9.streamlock.net/vod/mp4:_definst_/f/e/8e49fc32.mp4/playlist.m3u8?safwerwfasendtime=1490877870&safwerwfasstarttime=1490859339&safwerwfashash=hS2FfVZysQVazBQ6RJn1IhUevBkKxIF09Ly3BjfT43U="
277
-    try:
278
-        h = get_header(url,headers={"user-agent":"Enigma2"})
279
-        mtype = h.get("content-type")
280
-        ext,stream_type = get_ext(mtype)
281
-    except:
282
-        ext,stream_type = (".ts","hls")
283
-    output = urlparse.urlparse(url)[2].split('/')[-1] + ext
284
-    output = os.path.join("downloads", output)
285
-    if stream_type == "hls":
286
-        d = DownloadWithProgressFragmented(url,output,headers={"user-agent":"Enigma2"})
287
-    else:
288
-        d = DownloadWithProgress(url,output,headers={"user-agent":"Enigma2"})
289
-    d.addProgress(print_progress)
290
-    d.start().addCallback(download_ok).addErrback(download_err)
275
+    active = 2
276
+    d1 = download_video(url,output)
291 277
     reactor.run()
292 278
 
293 279
 

+ 124
- 102
project.wpr Ver fichero

@@ -13,6 +13,9 @@ 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',
16 19
          '')),
17 20
                       loc('iub_db.py'): ('project',
18 21
         (u'-d 90   -s -o',
@@ -39,7 +42,15 @@ proj.launch-config = {loc('ContentSources.py'): ('project',
39 42
         (u'home',
40 43
          ''))}
41 44
 [user attributes]
42
-debug.breakpoints = {loc('iub.py'): {102: (0,
45
+debug.breakpoints = {loc('Downloader.py'): {182L: (0,
46
+        None,
47
+        1,
48
+        0),
49
+        231: (0,
50
+              None,
51
+              1,
52
+              0)},
53
+                     loc('iub.py'): {102: (0,
43 54
         None,
44 55
         1,
45 56
         0),
@@ -145,6 +156,9 @@ debug.err-values = {None: {},
145 156
 debug.recent-run-args = {loc('ContentSources.py'): [u'config::home streams_bernu.cfg',
146 157
         u'ltc::home',
147 158
         u'config::home'],
159
+                         loc('Downloader.py'): [u'http://player.tvnet.lv/stream/amlst:75136/playlist.m3u8 downloads\\ccc',
160
+        u'http://player.tvnet.lv/stream/amlst:75136/playlist.m3u8 downloads\\bbb',
161
+        u'http://player.tvnet.lv/stream/amlst:75136/playlist.m3u8 aaa.mp4'],
148 162
                          loc('iub_db.py'): [u'-d 90   -s -o',
149 163
         u'-d 40   -rg -o',
150 164
         u'-d 40   -s -o',
@@ -225,7 +239,7 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
225 239
                                {'tree-state': {'file-sort-method': 'by name',
226 240
         'list-files-first': 0,
227 241
         'tree-states': {'deep': {'expanded-nodes': [(1,)],
228
-                                 'selected-nodes': [(13,)],
242
+                                 'selected-nodes': [(14,)],
229 243
                                  'top-node': (0,)}},
230 244
         'tree-style': 'deep'}}),
231 245
                               ('snippets',
@@ -818,7 +832,7 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
818 832
                                        'fRegexFlags': 46,
819 833
                                        'fReplaceText': u'www.shortcut.lv',
820 834
                                        'fReverse': False,
821
-                                       'fSearchText': u'order=',
835
+                                       'fSearchText': u'downloads',
822 836
                                        'fStartPos': 0,
823 837
                                        'fStyle': 'text',
824 838
                                        'fWholeWords': False,
@@ -892,9 +906,14 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
892 906
         -1,
893 907
         -1),
894 908
                        'attrib-starts': [],
895
-                       'first-line': 11L,
909
+                       'first-line': 19L,
896 910
                        'folded-linenos': [],
897 911
                        'history': {None: [],
912
+                                   u'file:C:/Data/Programming/enigma2/PlayStream2/content/Downloader.py': ['s'\
913
+        'elf\n',
914
+        'self.agent\n',
915
+        'self.url\n',
916
+        'args\n'],
898 917
                                    u'file:C:/Data/Programming/enigma2/PlayStream2/content/run.py': ['p'\
899 918
         'rint url\n',
900 919
         're.search(r"tracks\\|(\\w+)\\|(\\w+)\\|(\\w+)\\|files\\|(\\w+)\\|('\
@@ -969,10 +988,10 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
969 988
         'print data2\n',
970 989
         'item\n']},
971 990
                        'launch-id': None,
972
-                       'sel-line': 23L,
973
-                       'sel-line-start': 746L,
974
-                       'selection_end': 746L,
975
-                       'selection_start': 746L,
991
+                       'sel-line': 31L,
992
+                       'sel-line-start': 918L,
993
+                       'selection_end': 918L,
994
+                       'selection_start': 918L,
976 995
                        'zoom': 0L}),
977 996
                      ('debug-watch',
978 997
                       'wide',
@@ -1020,97 +1039,19 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
1020 1039
                        'selection_end': 374L,
1021 1040
                        'selection_start': 374L,
1022 1041
                        'zoom': 0L})],
1023
-        'primary_view_state': {'editor_states': ({'bookmarks': ([[loc('sources/ltc.py'),
1042
+        'primary_view_state': {'editor_states': ({'bookmarks': ([[loc('sources/mtgplay.py'),
1024 1043
         {'attrib-starts': [('Source',
1025
-                            27),
1026
-                           ('Source.__init__',
1027
-                            29)],
1028
-         'first-line': 56L,
1044
+                            40),
1045
+                           ('Source.get_content',
1046
+                            51)],
1047
+         'first-line': 82L,
1029 1048
          'folded-linenos': [],
1030
-         'sel-line': 56L,
1031
-         'sel-line-start': 2171L,
1032
-         'selection_end': 2171L,
1033
-         'selection_start': 2171L,
1049
+         'sel-line': 90L,
1050
+         'sel-line-start': 3441L,
1051
+         'selection_end': 3441L,
1052
+         'selection_start': 3441L,
1034 1053
          'zoom': 0L},
1035
-        1512899545.957],
1036
-        [loc('sources/ltc.py'),
1037
-         {'attrib-starts': [('Source',
1038
-                             27),
1039
-                            ('Source.get_content',
1040
-                             74)],
1041
-          'first-line': 96L,
1042
-          'folded-linenos': [],
1043
-          'sel-line': 105L,
1044
-          'sel-line-start': 4365L,
1045
-          'selection_end': 4365L,
1046
-          'selection_start': 4365L,
1047
-          'zoom': 0L},
1048
-         1512900011.185],
1049
-        [loc('sources/ltc.py'),
1050
-         {'attrib-starts': [('Source',
1051
-                             27),
1052
-                            ('Source.get_content',
1053
-                             74)],
1054
-          'first-line': 97L,
1055
-          'folded-linenos': [],
1056
-          'sel-line': 103L,
1057
-          'sel-line-start': 4140L,
1058
-          'selection_end': 4332L,
1059
-          'selection_start': 4140L,
1060
-          'zoom': 0L},
1061
-         1512900746.171],
1062
-        [loc('run.py'),
1063
-         {'attrib-starts': [('Main',
1064
-                             22),
1065
-                            ('Main.show_content',
1066
-                             183)],
1067
-          'first-line': 176L,
1068
-          'folded-linenos': [],
1069
-          'sel-line': 186L,
1070
-          'sel-line-start': 7392L,
1071
-          'selection_end': 7413L,
1072
-          'selection_start': 7413L,
1073
-          'zoom': 0L},
1074
-         1512900756.483],
1075
-        [loc('run.py'),
1076
-         {'attrib-starts': [('Main',
1077
-                             22),
1078
-                            ('Main.initUI',
1079
-                             47)],
1080
-          'first-line': 60L,
1081
-          'folded-linenos': [],
1082
-          'sel-line': 69L,
1083
-          'sel-line-start': 2705L,
1084
-          'selection_end': 2705L,
1085
-          'selection_start': 2705L,
1086
-          'zoom': 0L},
1087
-         1512901312.202],
1088
-        [loc('sources/ltc.py'),
1089
-         {'attrib-starts': [('Source',
1090
-                             27),
1091
-                            ('Source.get_content',
1092
-                             74)],
1093
-          'first-line': 78L,
1094
-          'folded-linenos': [],
1095
-          'sel-line': 83L,
1096
-          'sel-line-start': 3077L,
1097
-          'selection_end': 3168L,
1098
-          'selection_start': 3168L,
1099
-          'zoom': 0L},
1100
-         1512906372.564],
1101
-        [loc('sources/mtgplay.py'),
1102
-         {'attrib-starts': [('Source',
1103
-                             40),
1104
-                            ('Source.get_content',
1105
-                             51)],
1106
-          'first-line': 82L,
1107
-          'folded-linenos': [],
1108
-          'sel-line': 90L,
1109
-          'sel-line-start': 3441L,
1110
-          'selection_end': 3441L,
1111
-          'selection_start': 3441L,
1112
-          'zoom': 0L},
1113
-         1512906617.546],
1054
+        1512906617.546],
1114 1055
         [loc('run.py'),
1115 1056
          {'attrib-starts': [('Main',
1116 1057
                              22),
@@ -1268,9 +1209,77 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
1268 1209
           'selection_end': 4505L,
1269 1210
           'selection_start': 4505L,
1270 1211
           'zoom': 0L},
1271
-         1512908610.333]],
1212
+         1512908610.333],
1213
+        [loc('sources/mtgplay.py'),
1214
+         {'attrib-starts': [('Source',
1215
+                             40),
1216
+                            ('Source.get_content',
1217
+                             51)],
1218
+          'first-line': 155L,
1219
+          'folded-linenos': [],
1220
+          'sel-line': 162L,
1221
+          'sel-line-start': 8033L,
1222
+          'selection_end': 8077L,
1223
+          'selection_start': 8077L,
1224
+          'zoom': 0L},
1225
+         1512909177.038],
1226
+        [loc('run.py'),
1227
+         {'attrib-starts': [('Main',
1228
+                             22),
1229
+                            ('Main.list_action',
1230
+                             106)],
1231
+          'first-line': 105L,
1232
+          'folded-linenos': [],
1233
+          'sel-line': 110L,
1234
+          'sel-line-start': 4505L,
1235
+          'selection_end': 4505L,
1236
+          'selection_start': 4505L,
1237
+          'zoom': 0L},
1238
+         1512920924.388],
1239
+        [loc('Downloader.py'),
1240
+         {'attrib-starts': [],
1241
+          'first-line': 261L,
1242
+          'folded-linenos': [],
1243
+          'sel-line': 271L,
1244
+          'sel-line-start': 10976L,
1245
+          'selection_end': 11019L,
1246
+          'selection_start': 11019L,
1247
+          'zoom': 0L},
1248
+         1512921355.479],
1249
+        [loc('Downloader.py'),
1250
+         {'attrib-starts': [],
1251
+          'first-line': 276L,
1252
+          'folded-linenos': [],
1253
+          'sel-line': 283L,
1254
+          'sel-line-start': 11995L,
1255
+          'selection_end': 12030L,
1256
+          'selection_start': 12022L,
1257
+          'zoom': 0L},
1258
+         1512921359.313],
1259
+        [loc('Downloader.py'),
1260
+         {'attrib-starts': [('download_video',
1261
+                             241)],
1262
+          'first-line': 233L,
1263
+          'folded-linenos': [],
1264
+          'sel-line': 241L,
1265
+          'sel-line-start': 9270L,
1266
+          'selection_end': 9288L,
1267
+          'selection_start': 9274L,
1268
+          'zoom': 0L},
1269
+         1512921617.108],
1270
+        [loc('Downloader.py'),
1271
+         {'attrib-starts': [('DownloadWithProgressFragmented',
1272
+                             76)],
1273
+          'first-line': 154L,
1274
+          'folded-linenos': [],
1275
+          'sel-line': 191L,
1276
+          'sel-line-start': 7690L,
1277
+          'selection_end': 7699L,
1278
+          'selection_start': 7699L,
1279
+          'zoom': 0L},
1280
+         1512924911.716]],
1272 1281
         20),
1273
-        'current-loc': loc('sources/mtgplay.py'),
1282
+        'current-loc': loc('Downloader.py'),
1274 1283
         'editor-state-list': [(loc('ContentSources.py'),
1275 1284
                                {'attrib-starts': [('ContentSources',
1276 1285
         16),
@@ -1401,6 +1410,16 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
1401 1410
                                 'sel-line-start': 3299L,
1402 1411
                                 'selection_end': 3299L,
1403 1412
                                 'selection_start': 3299L,
1413
+                                'zoom': 0L}),
1414
+                              (loc('Downloader.py'),
1415
+                               {'attrib-starts': [('download_err',
1416
+        233)],
1417
+                                'first-line': 262L,
1418
+                                'folded-linenos': [],
1419
+                                'sel-line': 236L,
1420
+                                'sel-line-start': 9181L,
1421
+                                'selection_end': 9181L,
1422
+                                'selection_start': 9181L,
1404 1423
                                 'zoom': 0L})],
1405 1424
         'has-focus': True,
1406 1425
         'locked': False},
@@ -1415,7 +1434,8 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
1415 1434
          loc('sources/filmas.py'),
1416 1435
          loc('kivy_test2.py'),
1417 1436
          loc('kivy_test.py'),
1418
-         loc('sources/filmix.py')]),
1437
+         loc('sources/filmix.py'),
1438
+         loc('Downloader.py')]),
1419 1439
                                'open_files': [u'ContentSources.py',
1420 1440
         u'sources/filmas.py',
1421 1441
         u'sources/lmt.py',
@@ -1426,10 +1446,11 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
1426 1446
         u'sources/filmix.py',
1427 1447
         u'sources/ltc.py',
1428 1448
         u'kivy_test.py',
1449
+        u'sources/mtgplay.py',
1429 1450
         u'run.py',
1430
-        u'sources/mtgplay.py']},
1451
+        u'Downloader.py']},
1431 1452
         'saved_notebook_display': None,
1432
-        'split_percents': {0: 0.5261845386533666},
1453
+        'split_percents': {0: 0.48542458808618505},
1433 1454
         'splits': 2,
1434 1455
         'tab_location': 'top',
1435 1456
         'user_data': {}},
@@ -1442,8 +1463,9 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
1442 1463
                          -1080,
1443 1464
                          1858,
1444 1465
                          1080)}]}
1445
-guimgr.recent-documents = [loc('sources/mtgplay.py'),
1466
+guimgr.recent-documents = [loc('Downloader.py'),
1446 1467
                            loc('run.py'),
1468
+                           loc('sources/mtgplay.py'),
1447 1469
                            loc('kivy_test.py'),
1448 1470
                            loc('sources/ltc.py'),
1449 1471
                            loc('sources/filmix.py'),