Ivars před 7 roky
rodič
revize
aef24b4564

+ 74
- 0
context_download.py Zobrazit soubor

@@ -0,0 +1,74 @@
1
+import sys, os, urllib2, re
2
+from kodiswift import xbmc, xbmcgui, CLI_MODE
3
+from kodiswift import Plugin, storage
4
+from resources.lib.content import util, ContentSources, Downloader
5
+from twisted.web import client
6
+from twisted.internet import reactor, defer
7
+
8
+#plugin = Plugin()
9
+#plugin.load_addon_settings()
10
+#playlist = plugin.get_setting("general_playlist",str)
11
+#proxy_url = plugin.get_setting("general_proxy_url",str)
12
+
13
+cunicode = lambda s: s.decode("utf8") if isinstance(s, str) else s
14
+cstr = lambda s: s.encode("utf8") if isinstance(s, unicode) else s
15
+
16
+cmd = sys.argv[1]
17
+title = sys.argv[2]
18
+data = sys.argv[3]
19
+download_dir = sys.argv[4]
20
+
21
+cur_directory = os.path.dirname(__file__)
22
+sources_directory = os.path.join(cur_directory,"resources","lib", "content", "sources")
23
+sources = ContentSources.ContentSources(sources_directory)
24
+if not sources.is_video(data):
25
+    print "It is not video link"
26
+    sys.exit(1)
27
+
28
+streams = sources.get_streams(data)
29
+
30
+if not CLI_MODE:
31
+    ret = xbmcgui.Dialog().select("Select stream",streams)
32
+else:
33
+    ret = 0
34
+stream = streams[ret]
35
+#output =  stream["name"].replace("\\"," ").replace(":"," ").replace("|"," ")
36
+output = re.sub("[\\/\n\r\t,:\?\|'~\.]","_",title)
37
+
38
+for sub in stream["subs"]:
39
+    suburl = sub["url"]
40
+    slang = "_" + sub["lang"] if sub["lang"] else ""
41
+
42
+    try:
43
+        subs = urllib2.urlopen(suburl).read()
44
+    except:
45
+        subs = None
46
+    if subs:
47
+        if ".xml" in suburl:
48
+            subs = util.ttaf2srt(subs)
49
+            subext = ".srt"
50
+        elif ".vtt" in suburl:
51
+            subext = ".vtt"
52
+        elif ".srt" in suburl:
53
+            subext = ".srt"
54
+        else:
55
+            subext = ""
56
+        if subext:
57
+            subfile = cunicode(os.path.join(download_dir, output+slang+subext))
58
+            with open(subfile,"w") as f:
59
+                f.write(subs)
60
+    else:
61
+        print "\n Error downloading subtitle %s"%suburl
62
+
63
+d = Downloader.download_video(stream["url"], os.path.join(download_dir, output), stream["headers"])
64
+reactor.run()
65
+
66
+
67
+
68
+
69
+
70
+#xbmcgui.Dialog().ok("Info","Start download")
71
+
72
+#mode = "a" if os.path.exists("context_menu.log") else "w"
73
+#with open("context_menu.log", mode) as f:
74
+#    f.write("%s %s %s %s", sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])

binární
release/plugin.video.playstream-0.1.49.zip Zobrazit soubor


binární
release/plugin.video.playstream-0.1.50.zip Zobrazit soubor