1 |
''' |
2 |
Todic plugin for XBMC |
3 |
Version 0.0.2 |
4 |
''' |
5 |
|
6 |
import sys |
7 |
import cgi as urlparse |
8 |
import os |
9 |
|
10 |
|
11 |
import xbmc |
12 |
import xbmcaddon |
13 |
import xbmcgui |
14 |
import xbmcplugin |
15 |
import urllib |
16 |
import urllib2, re |
17 |
|
18 |
__addon__ = xbmcaddon.Addon(id='plugin.video.todic') |
19 |
__key__ = __addon__.getSetting('xbmckey').lower() |
20 |
__backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__ |
21 |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'fanart.jpg') |
22 |
|
23 |
def open_url(url): |
24 |
req = urllib2.Request(url) |
25 |
content = urllib2.urlopen(req) |
26 |
data = content.read() |
27 |
content.close() |
28 |
return data |
29 |
|
30 |
def rootMenu(): |
31 |
|
32 |
buildList(__backend__, "") # call default list |
33 |
|
34 |
# Adde xtra items to root menu |
35 |
listitem = xbmcgui.ListItem(label = "Søg film ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
36 |
listitem.setProperty('Fanart_Image', fanartImage) |
37 |
|
38 |
u = sys.argv[0] + "?mode=10&name=" |
39 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) |
40 |
|
41 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
42 |
|
43 |
|
44 |
def buildList(url,title): |
45 |
print '[TODIC]:'+str(url) |
46 |
link = open_url(url) |
47 |
ty=re.compile('<meta type=\'(.+?)\'').findall(link) |
48 |
print '[TODIC]'+str(ty[0]) |
49 |
|
50 |
if ty[0] == 'clipList': |
51 |
mode = '50' |
52 |
folder = False |
53 |
else: |
54 |
mode = '1' |
55 |
folder = True |
56 |
|
57 |
m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover><description>(.*)</description>').findall(link) |
58 |
l=len(m) |
59 |
for name,url,thumb,description in m: |
60 |
|
61 |
listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
62 |
listitem.setProperty('Fanart_Image', fanartImage) |
63 |
if mode == '50': |
64 |
infoLabels = {} |
65 |
infoLabels['title'] = name |
66 |
infoLabels['plot'] = description |
67 |
listitem.setInfo('video', infoLabels) |
68 |
|
69 |
u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
70 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l) |
71 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
72 |
|
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 |
def search(): |
89 |
search = getUserInput("Todic Søgning") |
90 |
|
91 |
if (search != None and search != ""): |
92 |
url = __backend__ + "&action=search&search=" + urllib.quote_plus(search) |
93 |
|
94 |
#print "[TODIC] Search start: " + search |
95 |
#print "[TODIC] Search url: " + url |
96 |
|
97 |
buildList(url, "søgning") |
98 |
|
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 |
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 == 10: |
178 |
search() |
179 |
|
180 |
|
181 |
elif mode == 50: |
182 |
play_video(url, name) |
183 |
|
184 |
|
185 |
|
186 |
# xbmcplugin.endOfDirectory(int(sys.argv[1])) |