|
@@ -18,9 +18,20 @@ import traceback
|
18
|
18
|
#from twisted.internet import reactor, defer
|
19
|
19
|
|
20
|
20
|
plugin = Plugin(addon_id="plugin.video.playstream")
|
|
21
|
+prefix = "plugin://%s/" % plugin.id
|
21
|
22
|
#plugin.load_addon_settings()
|
22
|
23
|
use_storage = plugin.get_setting("general_use_storage",bool) # TODO vajag nočekot vai nav labāk lietot pickle
|
|
24
|
+storage_ttl = plugin.get_setting("general_ttl",int)
|
|
25
|
+use_proxy = plugin.get_setting("general_proxy_use",bool)
|
|
26
|
+proxy_url = plugin.get_setting("general_proxy_url",str)
|
|
27
|
+playlist = plugin.get_setting("general_playlist",str)
|
|
28
|
+#download_dir = plugin.get_setting("general_download_dir",str)
|
|
29
|
+view_mode = plugin.get_setting("general_view_mode",str)
|
|
30
|
+streams_file = plugin.get_setting("general_streams_file",str)
|
|
31
|
+streams_file_remote = plugin.get_setting("general_streams_file_remote",str)
|
|
32
|
+use_streams_file_remote = plugin.get_setting("general_use_streams_file_remote",bool)
|
23
|
33
|
overwrite = plugin.get_setting("general_download_overwrite",bool)
|
|
34
|
+
|
24
|
35
|
sleep_time = 5 # TODO jāliek iekš parametriem
|
25
|
36
|
|
26
|
37
|
cunicode = lambda s: s.decode("utf8") if isinstance(s, str) else s
|
|
@@ -28,9 +39,9 @@ cstr = lambda s: s.encode("utf8") if isinstance(s, unicode) else s
|
28
|
39
|
|
29
|
40
|
#print "argv=",sys.argv
|
30
|
41
|
cmd = sys.argv[1]
|
31
|
|
-title = sys.argv[2]
|
32
|
|
-data = sys.argv[3]
|
33
|
|
-download_dir = sys.argv[4]
|
|
42
|
+title = urllib.unquote(sys.argv[2])
|
|
43
|
+data = urllib.unquote(sys.argv[3])
|
|
44
|
+download_dir = urllib.unquote(sys.argv[4])
|
34
|
45
|
#overwrite = sys.argv[5] if len(sys.argv)>5 else False
|
35
|
46
|
|
36
|
47
|
queue_dir = os.path.join(xbmc.translatePath("special://temp"), "download_queue") if not CLI_MODE else "download_queue"
|
|
@@ -54,8 +65,20 @@ if cmd in ["download2", "download3"] and not CLI_MODE:
|
54
|
65
|
|
55
|
66
|
cur_directory = os.path.dirname(__file__)
|
56
|
67
|
sources_directory = os.path.join(cur_directory,"resources","lib", "content", "sources")
|
57
|
|
-sources = ContentSources.ContentSources(sources_directory)
|
58
|
|
-
|
|
68
|
+#sources = ContentSources.ContentSources(sources_directory)
|
|
69
|
+#print "[playstream] Create sources objects"
|
|
70
|
+if use_streams_file_remote:
|
|
71
|
+ cfg_file = streams_file_remote
|
|
72
|
+ cfg_file2 = streams_file
|
|
73
|
+else:
|
|
74
|
+ cfg_file = streams_file
|
|
75
|
+ cfg_file2 = None
|
|
76
|
+try:
|
|
77
|
+ sources = ContentSources.ContentSources(sources_directory, cfg_file, cfg_file2)
|
|
78
|
+except Exception as e:
|
|
79
|
+ #xbmc.executebuiltin("Notification(Error,%s" % e.message)
|
|
80
|
+ #xbmc.executebuiltin("XBMC.ActivateWindow(Home)")
|
|
81
|
+ plugin.notify(e.message)
|
59
|
82
|
|
60
|
83
|
def main():
|
61
|
84
|
if not sources.is_video(data): # Folderis
|
|
@@ -96,8 +119,10 @@ def download_video(title, data, download_dir, overwrite, cb_notify=None, num=Non
|
96
|
119
|
stream = streams[res]
|
97
|
120
|
else:
|
98
|
121
|
stream = streams[0]
|
99
|
|
-
|
100
|
|
- download_stream(stream, download_dir, overwrite, notify, num=num)
|
|
122
|
+ try:
|
|
123
|
+ download_stream(stream, download_dir, overwrite, notify, num=num)
|
|
124
|
+ except Exception as e:
|
|
125
|
+ notify(e.message, title="Error")
|
101
|
126
|
|
102
|
127
|
#d = Downloader.download_video(stream["url"], os.path.join(download_dir, output), stream["headers"])
|
103
|
128
|
#reactor.run()
|
|
@@ -123,12 +148,14 @@ def notify(text, title="Info", time=10000):
|
123
|
148
|
####################################################################################################
|
124
|
149
|
|
125
|
150
|
def download_stream(stream, download_dir, overwrite=True, cb_notify=None, num=False):
|
|
151
|
+ UA = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0"
|
|
152
|
+
|
126
|
153
|
#output = stream["name"].replace("\\"," ").replace(":"," ").replace("|"," ")
|
127
|
154
|
url = stream["url"]
|
128
|
155
|
title = stream["name"].strip()
|
129
|
156
|
output = file.make_fname(title)
|
130
|
157
|
|
131
|
|
- headers = stream["headers"] if "headers" in stream and stream["headers"] else {"user-agent":"Enigma2"}
|
|
158
|
+ headers = stream["headers"] if "headers" in stream and stream["headers"] else {"user-agent":UA}
|
132
|
159
|
try:
|
133
|
160
|
h = get_header(url,headers=headers)
|
134
|
161
|
mtype = h.get("content-type")
|
|
@@ -327,7 +354,7 @@ def download_hls(url, outputfile, headers=None, overwrite=True, limit=None, cb_n
|
327
|
354
|
progress = float(currentbytes)/float(totalbytes)*100
|
328
|
355
|
msg = "%.1f%% (%iMB/%iMB)"%(progress,currentbytes / 1024 / 1024,totalbytes / 1024 / 1024)
|
329
|
356
|
#print msg
|
330
|
|
- #notify(msg)
|
|
357
|
+ notify(msg)
|
331
|
358
|
|
332
|
359
|
if type == "vod":
|
333
|
360
|
if ts_num >= len(ts_list) or (limit and currenttime>limit):
|