|
@@ -0,0 +1,143 @@
|
|
1
|
+import os, re, sys, traceback, urllib
|
|
2
|
+
|
|
3
|
+from plex_test_case import PlexTestCase, PlexCall
|
|
4
|
+from Framework.api.objectkit import ObjectContainer
|
|
5
|
+from content.util import stream_type
|
|
6
|
+import syspath
|
|
7
|
+#for f in syspath.folders:
|
|
8
|
+
|
|
9
|
+def get_content(data, title="Title"):
|
|
10
|
+ if not data.startswith("search"):
|
|
11
|
+ data = data.replace("/", "%2F")
|
|
12
|
+ data = urllib.quote(data)
|
|
13
|
+ status, headers, body = t.request(u'/video/playstream/%s?title=%s' % (data, title))
|
|
14
|
+ else: # Search object
|
|
15
|
+ query = raw_input("Search: ")
|
|
16
|
+ data = data.format(query)
|
|
17
|
+ status, headers, body = t.request(u'/video/playstream/%s&query=%s' % (data, query))
|
|
18
|
+ #print body
|
|
19
|
+ #result = re.findall('title="([^"]+)"\s+thumb="([^"]+)"\s+key="([^"]+)"\s+summary="([^"]+)"', body)
|
|
20
|
+ result = re.findall('<(\w+)\s(.+?)/>', body)
|
|
21
|
+ result2 = []
|
|
22
|
+ for item0 in result:
|
|
23
|
+ item_type = item0[0]
|
|
24
|
+ data2 = re.search('key="(.+?)"', item0[1]).group(1) if re.search('key="(.+?)"',item0[1]) else ""
|
|
25
|
+ data2 = data2.replace("/video/playstream/", "")
|
|
26
|
+ if not data2.startswith("search"):
|
|
27
|
+ data2 = data2.split("?")[0]
|
|
28
|
+ data2 = urllib.unquote(data2)
|
|
29
|
+ data2 = data2.replace("%2F", "/")
|
|
30
|
+ title = re.search('title="(.+?)"', item0[1]).group(1) if re.search('title="(.+?)"',item0[1]) else ""
|
|
31
|
+ desc = re.search('summary="(.+?)"', item0[1]).group(1) if re.search('summary="(.+?)"',item0[1]) else ""
|
|
32
|
+ result2.append((title, data2, "", desc, item_type))
|
|
33
|
+ return result2
|
|
34
|
+
|
|
35
|
+def get_streams(data, title="Title"):
|
|
36
|
+ data = data.replace("/", "%2F")
|
|
37
|
+ data = urllib.quote(data)
|
|
38
|
+ status, headers, body = t.request(u'/video/playstream/%s?title=%s' % (data, title))
|
|
39
|
+ print body
|
|
40
|
+ #TODO
|
|
41
|
+ return []
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+# os.environ["PLEXBUNDLEDPLUGINSPATH"] = r"C:\Data\Programming\Plex"
|
|
45
|
+os.environ["PLEXLOCALAPPDATA"] = r"C:\Data\Programming\Plex"
|
|
46
|
+t = PlexCall()
|
|
47
|
+#for item in get_content("config::home", "Home"):
|
|
48
|
+# print item
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+if len(sys.argv)>1:
|
|
52
|
+ data= sys.argv[1]
|
|
53
|
+else:
|
|
54
|
+ data = "config::home"
|
|
55
|
+
|
|
56
|
+#options = sources.options_read("ltc")
|
|
57
|
+#print options
|
|
58
|
+history = []
|
|
59
|
+cur = ("Home",data,None,None)
|
|
60
|
+content = get_content(cur[1])
|
|
61
|
+
|
|
62
|
+exit_loop = False
|
|
63
|
+while True:
|
|
64
|
+ print "\n======================================================="
|
|
65
|
+ print "data= ", cur[1]
|
|
66
|
+ print "======================================================="
|
|
67
|
+ for i,item in enumerate(content):
|
|
68
|
+ s = "%i: %s - %s %s"%(i,item[0],item[1],item[2])
|
|
69
|
+ print s #.encode(sys.stdout.encoding,"replace")
|
|
70
|
+
|
|
71
|
+ while True:
|
|
72
|
+ a = raw_input("Enter number, (-) for download, q for exit: ")
|
|
73
|
+ if a in ("q","Q","x","X"):
|
|
74
|
+ exit_loop = True
|
|
75
|
+ print "Exiting"
|
|
76
|
+ break
|
|
77
|
+ try:
|
|
78
|
+ n = int(a)
|
|
79
|
+ break
|
|
80
|
+ except:
|
|
81
|
+ print "Not number!"
|
|
82
|
+ if exit_loop: break
|
|
83
|
+ download = False
|
|
84
|
+ if n<0:
|
|
85
|
+ n = abs(n)
|
|
86
|
+ download = True
|
|
87
|
+ cur2 = content[n]
|
|
88
|
+ data0 = cur2[1].split("::")[1] if "::" in cur2[1] else cur2[1]
|
|
89
|
+ if not data0:
|
|
90
|
+ pass
|
|
91
|
+# elif cur2[1] == "back":
|
|
92
|
+# cur = history.pop()
|
|
93
|
+ elif cur2[4] == "Video": #is_video(cur2[1]):
|
|
94
|
+ if stream_type(cur2[1]):
|
|
95
|
+ stream = util.item()
|
|
96
|
+ stream["url"] = cur2[1]
|
|
97
|
+ stream["name"] = cur2[0]
|
|
98
|
+ streams = [stream]
|
|
99
|
+ else:
|
|
100
|
+ try:
|
|
101
|
+ if not download:
|
|
102
|
+ streams = get_streams(cur2[1])
|
|
103
|
+ else:
|
|
104
|
+ stream = util.item()
|
|
105
|
+ stream["url"] = cur2[1]
|
|
106
|
+ stream["name"] = cur2[0]
|
|
107
|
+ stream["url"] = util.streamproxy_encode2(stream["url"])
|
|
108
|
+ print stream["url"]
|
|
109
|
+ streams = [stream]
|
|
110
|
+ except Exception as e:
|
|
111
|
+ print unicode(e)
|
|
112
|
+ traceback.print_exc()
|
|
113
|
+ streams = []
|
|
114
|
+ if streams:
|
|
115
|
+ if not download:
|
|
116
|
+ util.play_video(streams)
|
|
117
|
+ else:
|
|
118
|
+ #urlp = util.streamproxy_encode2(streams[0]["url"])
|
|
119
|
+ #print urlp
|
|
120
|
+ #util.player(urlp)
|
|
121
|
+ #Downloader.download_video(streams)
|
|
122
|
+ pass
|
|
123
|
+ else:
|
|
124
|
+ print "**No stream to play - %s "%(
|
|
125
|
+ cur2[1])
|
|
126
|
+ raw_input("Press any key")
|
|
127
|
+ #import os
|
|
128
|
+ #os.system('"c:\Program Files (x86)\VideoLAN\VLC\vlc.exe" "%s"'%cur2[1])
|
|
129
|
+
|
|
130
|
+ else:
|
|
131
|
+ if "{0}" in cur2[1]:
|
|
132
|
+ a = raw_input("Enter value:")
|
|
133
|
+ cur2 = (cur2[0],cur2[1].format(a),cur2[2],cur2[3])
|
|
134
|
+ history.append(cur)
|
|
135
|
+ cur = cur2
|
|
136
|
+ try:
|
|
137
|
+ # Regular item
|
|
138
|
+ content = get_content(cur[1])
|
|
139
|
+ except Exception as e:
|
|
140
|
+ print unicode(e)
|
|
141
|
+ traceback.print_exc()
|
|
142
|
+ raw_input("Continue?")
|
|
143
|
+
|