1 |
torben |
1629 |
''' |
2 |
|
|
Todic plugin for XBMC |
3 |
|
|
Version 0.0.2 |
4 |
|
|
''' |
5 |
|
|
|
6 |
|
|
import sys |
7 |
|
|
import cgi as urlparse |
8 |
|
|
|
9 |
|
|
import xbmc |
10 |
|
|
import xbmcaddon |
11 |
|
|
import xbmcgui |
12 |
|
|
import xbmcplugin |
13 |
|
|
import urllib |
14 |
|
|
import urllib2, re |
15 |
|
|
|
16 |
|
|
__addon__ = xbmcaddon.Addon(id='plugin.video.todic') |
17 |
|
|
__key__ = __addon__.getSetting('xbmckey').lower() |
18 |
|
|
__backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__ |
19 |
|
|
|
20 |
|
|
def open_url(url): |
21 |
|
|
req = urllib2.Request(url) |
22 |
|
|
content = urllib2.urlopen(req) |
23 |
|
|
data = content.read() |
24 |
|
|
content.close() |
25 |
|
|
return data |
26 |
|
|
|
27 |
|
|
def rootMenu(): |
28 |
|
|
link = open_url(__backend__) |
29 |
|
|
m=re.compile('<title>(.+?)</title><url>(.+?)</url>').findall(link) |
30 |
torben |
1630 |
l = len(m) |
31 |
torben |
1629 |
for name,url in m: |
32 |
|
|
listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
33 |
|
|
u = sys.argv[0] + "?mode=1&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
34 |
torben |
1630 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True, totalItems = l) |
35 |
torben |
1631 |
|
36 |
|
|
listitem = xbmcgui.ListItem(label = "Søg ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
37 |
|
|
u = sys.argv[0] + "?mode=10&name=" + urllib.quote_plus(name) |
38 |
|
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True, totalItems = l) |
39 |
|
|
|
40 |
torben |
1629 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
41 |
|
|
|
42 |
|
|
|
43 |
|
|
def buildList(url,title): |
44 |
|
|
print '[TODIC]:'+str(url) |
45 |
|
|
link = open_url(url) |
46 |
|
|
ty=re.compile('<meta type=\'(.+?)\'').findall(link) |
47 |
|
|
print '[TOD]'+str(ty[0]) |
48 |
|
|
m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover>').findall(link) |
49 |
torben |
1630 |
l=len(m) |
50 |
torben |
1629 |
for name,url,thumb in m: |
51 |
|
|
if ty[0] == 'clipList': |
52 |
|
|
mode = '50' |
53 |
|
|
folder = False |
54 |
|
|
else: |
55 |
|
|
mode = '2' |
56 |
|
|
folder = True |
57 |
|
|
|
58 |
|
|
listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
59 |
|
|
u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
60 |
torben |
1630 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l) |
61 |
torben |
1629 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
62 |
|
|
|
63 |
|
|
def buildSubList(url,title): |
64 |
|
|
print '[TODIC]:'+str(url) |
65 |
|
|
link = open_url(url) |
66 |
|
|
m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover>').findall(link) |
67 |
torben |
1630 |
l = len(m) |
68 |
torben |
1629 |
for name,url,thumb in m: |
69 |
|
|
listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
70 |
|
|
u = sys.argv[0] + "?mode=50&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
71 |
torben |
1630 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = False, totalItems = l) |
72 |
torben |
1629 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
73 |
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
def play_video(url, name): |
77 |
|
|
link = open_url(url) |
78 |
|
|
match=re.compile('<url>(.+?)</url>').findall(link) |
79 |
|
|
url = match[0] |
80 |
|
|
print '[TODIC]:'+str(url) |
81 |
|
|
image = xbmc.getInfoImage( 'ListItem.Thumb' ) |
82 |
|
|
listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image) |
83 |
|
|
# listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = 'DefaultVideo.png') |
84 |
|
|
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
85 |
|
|
xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(str(url), listitem) |
86 |
|
|
xbmc.sleep(200) |
87 |
|
|
|
88 |
torben |
1631 |
def search(): |
89 |
|
|
search = getUserInput("Todic Søgning") |
90 |
torben |
1629 |
|
91 |
torben |
1634 |
if (search != None and search != ""): |
92 |
|
|
url = __backend__ + "&action=search&search=" + urllib.quote_plus(search) |
93 |
torben |
1631 |
|
94 |
torben |
1634 |
#print "[TODIC] Search start: " + search |
95 |
|
|
#print "[TODIC] Search url: " + url |
96 |
torben |
1631 |
|
97 |
torben |
1634 |
buildSubList(url, "søgning") |
98 |
torben |
1631 |
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
#=================================== Tool Box ======================================= |
104 |
|
|
# shows a more userfriendly notification |
105 |
|
|
def showMessage(heading, message): |
106 |
|
|
duration = 15*1000 |
107 |
|
|
xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) ) |
108 |
|
|
|
109 |
|
|
|
110 |
|
|
# raise a keyboard for user input |
111 |
|
|
def getUserInput(title = "Input", default="", hidden=False): |
112 |
|
|
result = None |
113 |
|
|
|
114 |
|
|
# Fix for when this functions is called with default=None |
115 |
|
|
if not default: |
116 |
|
|
default = "" |
117 |
|
|
|
118 |
|
|
keyboard = xbmc.Keyboard(default, title) |
119 |
|
|
keyboard.setHiddenInput(hidden) |
120 |
|
|
keyboard.doModal() |
121 |
|
|
|
122 |
|
|
if keyboard.isConfirmed(): |
123 |
|
|
result = keyboard.getText() |
124 |
|
|
|
125 |
|
|
return result |
126 |
|
|
|
127 |
|
|
|
128 |
torben |
1629 |
def get_params(): |
129 |
|
|
param=[] |
130 |
|
|
paramstring=sys.argv[2] |
131 |
|
|
if len(paramstring)>=2: |
132 |
|
|
params=sys.argv[2] |
133 |
|
|
cleanedparams=params.replace('?','') |
134 |
|
|
if (params[len(params)-1]=='/'): |
135 |
|
|
params=params[0:len(params)-2] |
136 |
|
|
pairsofparams=cleanedparams.split('&') |
137 |
|
|
param={} |
138 |
|
|
for i in range(len(pairsofparams)): |
139 |
|
|
splitparams={} |
140 |
|
|
splitparams=pairsofparams[i].split('=') |
141 |
|
|
if (len(splitparams))==2: |
142 |
|
|
param[splitparams[0]]=splitparams[1] |
143 |
|
|
return param |
144 |
|
|
|
145 |
|
|
params = get_params() |
146 |
|
|
url = None |
147 |
|
|
name = None |
148 |
|
|
mode = None |
149 |
|
|
|
150 |
|
|
params = get_params() |
151 |
|
|
url = None |
152 |
|
|
name = None |
153 |
|
|
mode = None |
154 |
|
|
|
155 |
|
|
try: |
156 |
|
|
url = urllib.unquote_plus(params["url"]) |
157 |
|
|
except: |
158 |
|
|
pass |
159 |
|
|
try: |
160 |
|
|
name = urllib.unquote_plus(params["name"]) |
161 |
|
|
except: |
162 |
|
|
pass |
163 |
|
|
try: |
164 |
|
|
mode = int(params["mode"]) |
165 |
|
|
except: |
166 |
|
|
pass |
167 |
|
|
|
168 |
|
|
|
169 |
|
|
if mode == None: |
170 |
|
|
#build main menu |
171 |
|
|
rootMenu() |
172 |
|
|
|
173 |
|
|
elif mode == 1: |
174 |
|
|
#build list of movie starting letters |
175 |
|
|
buildList(url, name) |
176 |
|
|
|
177 |
|
|
elif mode == 2: |
178 |
|
|
#build list of series |
179 |
|
|
buildSubList(url, name) |
180 |
|
|
|
181 |
torben |
1631 |
elif mode == 10: |
182 |
|
|
search() |
183 |
|
|
|
184 |
|
|
|
185 |
torben |
1629 |
elif mode == 50: |
186 |
|
|
play_video(url, name) |
187 |
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
torben |
1632 |
# xbmcplugin.endOfDirectory(int(sys.argv[1])) |