1 |
|
2 |
# This Python file uses the following encoding: utf-8 |
3 |
|
4 |
''' |
5 |
Todic plugin for XBMC |
6 |
Version 0.0.2 |
7 |
''' |
8 |
|
9 |
import sys |
10 |
import cgi as urlparse |
11 |
import os |
12 |
|
13 |
|
14 |
import xbmc |
15 |
import xbmcaddon |
16 |
import xbmcgui |
17 |
import xbmcplugin |
18 |
import urllib |
19 |
import urllib2 |
20 |
|
21 |
from xml.dom.minidom import parseString |
22 |
|
23 |
__addon__ = xbmcaddon.Addon(id='plugin.video.todic') |
24 |
__key__ = __addon__.getSetting('xbmckey').lower() |
25 |
__backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__ |
26 |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'fanart.jpg') |
27 |
|
28 |
|
29 |
class TodicPlayer(xbmc.Player): |
30 |
def __init__(self, *args, **kwargs): |
31 |
#xbmc.Player.__init__(selv,*args,**kwargs) |
32 |
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER ) |
33 |
self.stopped = False |
34 |
self.started = False |
35 |
print "[TodicPlayer] init" |
36 |
|
37 |
# @catchall |
38 |
def onPlayBackStarted(self): |
39 |
self.started = True |
40 |
print "[TodicPlayer] : started" |
41 |
# super.onPlayBackStarted() |
42 |
|
43 |
def onPlayBackStopped(self): |
44 |
self.stopped = True |
45 |
print "[TodicPlayer] : stopped" |
46 |
|
47 |
def onPlayBackEnded(self): |
48 |
self.stopped = True |
49 |
print "[TodicPlayer] : ended" |
50 |
|
51 |
def callbackLoop(self): |
52 |
print "[Todic] startLoop" |
53 |
while (self.stopped == False): |
54 |
if (self.started == True ): |
55 |
print "[todic] " + str(self.getTime()) |
56 |
xbmc.sleep(5000) |
57 |
|
58 |
|
59 |
def getText2(nodelist): |
60 |
rc = [] |
61 |
for node in nodelist: |
62 |
if node.nodeType == node.TEXT_NODE: |
63 |
rc.append(node.data) |
64 |
else: |
65 |
rc.append( getText(node.childNodes) ) |
66 |
return ''.join(rc) |
67 |
|
68 |
def getText(nodelist): |
69 |
if nodelist.length == 0: |
70 |
return '' |
71 |
else: |
72 |
if nodelist[0].childNodes.length == 0: |
73 |
return '' |
74 |
else: |
75 |
return nodelist[0].childNodes[0].nodeValue |
76 |
|
77 |
|
78 |
def open_url(url): |
79 |
req = urllib2.Request(url) |
80 |
content = urllib2.urlopen(req) |
81 |
data = content.read() |
82 |
content.close() |
83 |
return data |
84 |
|
85 |
def rootMenu(): |
86 |
|
87 |
msg = open_url(__backend__ + "&action=messages") |
88 |
msg = msg.strip() |
89 |
|
90 |
if msg != "": |
91 |
dialog = xbmcgui.Dialog() |
92 |
dialog.ok('XBMC Todic', msg) |
93 |
|
94 |
buildList(__backend__, "", False) # call default list |
95 |
|
96 |
# Adde xtra items to root menu |
97 |
listitem = xbmcgui.ListItem(label = "Søg film ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
98 |
listitem.setProperty('Fanart_Image', fanartImage) |
99 |
|
100 |
u = sys.argv[0] + "?mode=10&name=" |
101 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) |
102 |
|
103 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
104 |
|
105 |
|
106 |
def buildList(url,title, endlist=True): |
107 |
print '[TODIC]:'+str(url) |
108 |
|
109 |
link = open_url(url) |
110 |
doc = parseString(link) |
111 |
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
112 |
print '[TODIC]'+str(ty) |
113 |
|
114 |
if ty == 'clipList': |
115 |
mode = '50' |
116 |
folder = False |
117 |
else: |
118 |
mode = '1' |
119 |
folder = True |
120 |
|
121 |
entries = doc.getElementsByTagName("entry") |
122 |
l=len(entries) |
123 |
description = '' |
124 |
for entry in entries: |
125 |
name = getText( entry.getElementsByTagName("title") ) |
126 |
url = getText( entry.getElementsByTagName("url") ) |
127 |
thumb = getText( entry.getElementsByTagName("cover") ) |
128 |
description = getText( entry.getElementsByTagName("description") ) |
129 |
|
130 |
name = name.encode('latin-1') |
131 |
description = description.encode('latin-1') |
132 |
|
133 |
## print "name:" + name |
134 |
# print "url:" + url |
135 |
# print "thumb:" + thumb |
136 |
# print "description:" + description |
137 |
|
138 |
|
139 |
listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
140 |
listitem.setProperty('Fanart_Image', fanartImage) |
141 |
if mode == '50': |
142 |
infoLabels = {} |
143 |
infoLabels['title'] = name |
144 |
infoLabels['plot'] = description |
145 |
listitem.setInfo('video', infoLabels) |
146 |
|
147 |
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(name) + "&url=" + urllib.quote(url) |
148 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l) |
149 |
|
150 |
if (endlist == True): |
151 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
152 |
|
153 |
|
154 |
|
155 |
|
156 |
def play_video(url, name): |
157 |
xml = open_url(url) |
158 |
|
159 |
doc = parseString(xml) |
160 |
url = getText( doc.getElementsByTagName("url") ) |
161 |
|
162 |
print '[TODIC]:'+str(url) |
163 |
image = xbmc.getInfoImage( 'ListItem.Thumb' ) |
164 |
listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image) |
165 |
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
166 |
|
167 |
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
168 |
player.play(str(url), listitem) |
169 |
# player.callbackLoop() |
170 |
|
171 |
|
172 |
|
173 |
def search(): |
174 |
search = getUserInput("Todic Søgning") |
175 |
|
176 |
if (search != None and search != ""): |
177 |
url = __backend__ + "&action=search&search=" + urllib.quote_plus(search) |
178 |
|
179 |
#print "[TODIC] Search start: " + search |
180 |
#print "[TODIC] Search url: " + url |
181 |
|
182 |
buildList(url, "søgning") |
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
#=================================== Tool Box ======================================= |
189 |
# shows a more userfriendly notification |
190 |
def showMessage(heading, message): |
191 |
duration = 15*1000 |
192 |
xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) ) |
193 |
|
194 |
|
195 |
# raise a keyboard for user input |
196 |
def getUserInput(title = "Input", default="", hidden=False): |
197 |
result = None |
198 |
|
199 |
# Fix for when this functions is called with default=None |
200 |
if not default: |
201 |
default = "" |
202 |
|
203 |
keyboard = xbmc.Keyboard(default, title) |
204 |
keyboard.setHiddenInput(hidden) |
205 |
keyboard.doModal() |
206 |
|
207 |
if keyboard.isConfirmed(): |
208 |
result = keyboard.getText() |
209 |
|
210 |
return result |
211 |
|
212 |
|
213 |
def get_params(): |
214 |
param=[] |
215 |
paramstring=sys.argv[2] |
216 |
if len(paramstring)>=2: |
217 |
params=sys.argv[2] |
218 |
cleanedparams=params.replace('?','') |
219 |
if (params[len(params)-1]=='/'): |
220 |
params=params[0:len(params)-2] |
221 |
pairsofparams=cleanedparams.split('&') |
222 |
param={} |
223 |
for i in range(len(pairsofparams)): |
224 |
splitparams={} |
225 |
splitparams=pairsofparams[i].split('=') |
226 |
if (len(splitparams))==2: |
227 |
param[splitparams[0]]=splitparams[1] |
228 |
return param |
229 |
|
230 |
|
231 |
params = get_params() |
232 |
url = None |
233 |
name = None |
234 |
mode = None |
235 |
|
236 |
try: |
237 |
url = urllib.unquote_plus(params["url"]) |
238 |
except: |
239 |
pass |
240 |
try: |
241 |
name = urllib.unquote_plus(params["name"]) |
242 |
except: |
243 |
pass |
244 |
try: |
245 |
mode = int(params["mode"]) |
246 |
except: |
247 |
pass |
248 |
|
249 |
|
250 |
if mode == None: |
251 |
#build main menu |
252 |
rootMenu() |
253 |
|
254 |
elif mode == 1: |
255 |
#build list of movie starting letters |
256 |
buildList(url, name) |
257 |
|
258 |
elif mode == 10: |
259 |
search() |
260 |
|
261 |
|
262 |
elif mode == 50: |
263 |
play_video(url, name) |