1 |
''' |
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 |
l = len(m) |
31 |
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 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True, totalItems = l) |
35 |
|
36 |
listitem = xbmcgui.ListItem(label = "Søg film ...", 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 |
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 '[TODIC]'+str(ty[0]) |
48 |
|
49 |
if ty[0] == 'clipList': |
50 |
mode = '50' |
51 |
folder = False |
52 |
else: |
53 |
mode = '1' |
54 |
folder = True |
55 |
|
56 |
m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover>').findall(link) |
57 |
l=len(m) |
58 |
for name,url,thumb in m: |
59 |
listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
60 |
u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
61 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l) |
62 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
63 |
|
64 |
|
65 |
|
66 |
|
67 |
def play_video(url, name): |
68 |
link = open_url(url) |
69 |
match=re.compile('<url>(.+?)</url>').findall(link) |
70 |
url = match[0] |
71 |
print '[TODIC]:'+str(url) |
72 |
image = xbmc.getInfoImage( 'ListItem.Thumb' ) |
73 |
listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image) |
74 |
# listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = 'DefaultVideo.png') |
75 |
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
76 |
xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(str(url), listitem) |
77 |
xbmc.sleep(200) |
78 |
|
79 |
def search(): |
80 |
search = getUserInput("Todic Søgning") |
81 |
|
82 |
if (search != None and search != ""): |
83 |
url = __backend__ + "&action=search&search=" + urllib.quote_plus(search) |
84 |
|
85 |
#print "[TODIC] Search start: " + search |
86 |
#print "[TODIC] Search url: " + url |
87 |
|
88 |
buildList(url, "søgning") |
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
#=================================== Tool Box ======================================= |
95 |
# shows a more userfriendly notification |
96 |
def showMessage(heading, message): |
97 |
duration = 15*1000 |
98 |
xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) ) |
99 |
|
100 |
|
101 |
# raise a keyboard for user input |
102 |
def getUserInput(title = "Input", default="", hidden=False): |
103 |
result = None |
104 |
|
105 |
# Fix for when this functions is called with default=None |
106 |
if not default: |
107 |
default = "" |
108 |
|
109 |
keyboard = xbmc.Keyboard(default, title) |
110 |
keyboard.setHiddenInput(hidden) |
111 |
keyboard.doModal() |
112 |
|
113 |
if keyboard.isConfirmed(): |
114 |
result = keyboard.getText() |
115 |
|
116 |
return result |
117 |
|
118 |
|
119 |
def get_params(): |
120 |
param=[] |
121 |
paramstring=sys.argv[2] |
122 |
if len(paramstring)>=2: |
123 |
params=sys.argv[2] |
124 |
cleanedparams=params.replace('?','') |
125 |
if (params[len(params)-1]=='/'): |
126 |
params=params[0:len(params)-2] |
127 |
pairsofparams=cleanedparams.split('&') |
128 |
param={} |
129 |
for i in range(len(pairsofparams)): |
130 |
splitparams={} |
131 |
splitparams=pairsofparams[i].split('=') |
132 |
if (len(splitparams))==2: |
133 |
param[splitparams[0]]=splitparams[1] |
134 |
return param |
135 |
|
136 |
params = get_params() |
137 |
url = None |
138 |
name = None |
139 |
mode = None |
140 |
|
141 |
params = get_params() |
142 |
url = None |
143 |
name = None |
144 |
mode = None |
145 |
|
146 |
try: |
147 |
url = urllib.unquote_plus(params["url"]) |
148 |
except: |
149 |
pass |
150 |
try: |
151 |
name = urllib.unquote_plus(params["name"]) |
152 |
except: |
153 |
pass |
154 |
try: |
155 |
mode = int(params["mode"]) |
156 |
except: |
157 |
pass |
158 |
|
159 |
|
160 |
if mode == None: |
161 |
#build main menu |
162 |
rootMenu() |
163 |
|
164 |
elif mode == 1: |
165 |
#build list of movie starting letters |
166 |
buildList(url, name) |
167 |
|
168 |
elif mode == 10: |
169 |
search() |
170 |
|
171 |
|
172 |
elif mode == 50: |
173 |
play_video(url, name) |
174 |
|
175 |
|
176 |
|
177 |
# xbmcplugin.endOfDirectory(int(sys.argv[1])) |