3 |
|
|
4 |
''' |
''' |
5 |
Todic plugin for XBMC |
Todic plugin for XBMC |
6 |
Version 0.0.2 |
Version 0.0.14 |
7 |
''' |
''' |
8 |
|
|
9 |
import sys |
import sys |
24 |
__key__ = __addon__.getSetting('xbmckey').lower() |
__key__ = __addon__.getSetting('xbmckey').lower() |
25 |
__backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__ |
__backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__ |
26 |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'fanart.jpg') |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'fanart.jpg') |
27 |
|
datapath = xbmc.translatePath('special://profile/addon_data/plugin.video.todic/') |
28 |
|
|
29 |
|
ADDON_PATH = __addon__.getAddonInfo('path') |
30 |
|
SkinMasterPath = os.path.join(ADDON_PATH, 'skins' ) + '/' |
31 |
|
MySkinPath = (os.path.join(SkinMasterPath, '720p')) + '/' |
32 |
|
MySkin = 'main.xml' |
33 |
|
|
34 |
|
|
35 |
|
class TodicMovieDialog(xbmcgui.WindowXMLDialog): |
36 |
|
def __new__(cls): |
37 |
|
return super(TodicMovieDialog, cls).__new__(cls, "main.xml", ADDON_PATH) |
38 |
|
|
39 |
|
def __init__(self): |
40 |
|
super(TodicMovieDialog, self).__init__() |
41 |
|
|
42 |
|
def onClick( self, controlId ): |
43 |
|
print "OnClick: " + str(controlId) |
44 |
|
|
45 |
|
if (controlId == 50): |
46 |
|
self.close() |
47 |
|
play_real_video(self.url, self.name) |
48 |
|
|
49 |
|
if ( controlId == 98 ): |
50 |
|
self.close() |
51 |
|
|
52 |
|
|
53 |
|
def onInit(self): |
54 |
|
|
55 |
|
print "ONINIT" |
56 |
|
self.getControl( 1 ).setLabel( self.name); |
57 |
|
self.getControl( 2 ).setLabel( self.description ); |
58 |
|
|
59 |
|
def setUrl( self, url): |
60 |
|
self.url = url |
61 |
|
|
62 |
|
def setName( self, name ): |
63 |
|
self.name = name |
64 |
|
|
65 |
|
def setDescription( self, description ): |
66 |
|
self.description = description |
67 |
|
|
68 |
|
|
69 |
class TodicPlayer(xbmc.Player): |
class TodicPlayer(xbmc.Player): |
114 |
else: |
else: |
115 |
return nodelist[0].childNodes[0].nodeValue |
return nodelist[0].childNodes[0].nodeValue |
116 |
|
|
117 |
|
def SaveFile(path, data): |
118 |
|
file = open(path,'w') |
119 |
|
file.write(data) |
120 |
|
file.close() |
121 |
|
|
122 |
|
|
123 |
def open_url(url): |
def open_url(url): |
124 |
req = urllib2.Request(url) |
req = urllib2.Request(url) |
129 |
|
|
130 |
def rootMenu(): |
def rootMenu(): |
131 |
|
|
132 |
|
msg = open_url(__backend__ + "&action=messages") |
133 |
|
msg = msg.strip() |
134 |
|
|
135 |
|
if msg != "": |
136 |
|
dialog = xbmcgui.Dialog() |
137 |
|
dialog.ok('XBMC Todic', msg) |
138 |
|
|
139 |
buildList(__backend__, "", False) # call default list |
buildList(__backend__, "", False) # call default list |
140 |
|
|
141 |
# Adde xtra items to root menu |
# Adde xtra items to root menu |
145 |
u = sys.argv[0] + "?mode=10&name=" |
u = sys.argv[0] + "?mode=10&name=" |
146 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) |
147 |
|
|
148 |
|
#add search series |
149 |
|
listitem = xbmcgui.ListItem(label = "Søg Serier ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
150 |
|
listitem.setProperty('Fanart_Image', fanartImage) |
151 |
|
|
152 |
|
u = sys.argv[0] + "?mode=11&name=" |
153 |
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) |
154 |
|
|
155 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
156 |
|
|
157 |
|
|
158 |
def buildList(url,title, endlist=True): |
def buildList(url,title, endlist=True): |
159 |
print '[TODIC]:'+str(url) |
print '[TODIC]:'+str(url) |
160 |
|
|
161 |
link = open_url(url) |
link = open_url(url) |
162 |
doc = parseString(link) |
doc = parseString(link) |
170 |
mode = '1' |
mode = '1' |
171 |
folder = True |
folder = True |
172 |
|
|
173 |
|
|
174 |
entries = doc.getElementsByTagName("entry") |
entries = doc.getElementsByTagName("entry") |
175 |
l=len(entries) |
l=len(entries) |
176 |
description = '' |
description = '' |
179 |
url = getText( entry.getElementsByTagName("url") ) |
url = getText( entry.getElementsByTagName("url") ) |
180 |
thumb = getText( entry.getElementsByTagName("cover") ) |
thumb = getText( entry.getElementsByTagName("cover") ) |
181 |
description = getText( entry.getElementsByTagName("description") ) |
description = getText( entry.getElementsByTagName("description") ) |
182 |
|
playcount = getText( entry.getElementsByTagName("playcount") ) |
183 |
|
|
184 |
|
if playcount == '': |
185 |
|
playcount = '0' |
186 |
|
playcount = int(playcount) |
187 |
|
|
|
name = name.encode('latin-1') |
|
|
description = description.encode('latin-1') |
|
188 |
|
|
189 |
## print "name:" + name |
## print "name:" + name |
190 |
# print "url:" + url |
# print "url:" + url |
197 |
if mode == '50': |
if mode == '50': |
198 |
infoLabels = {} |
infoLabels = {} |
199 |
infoLabels['title'] = name |
infoLabels['title'] = name |
200 |
infoLabels['plot'] = description |
infoLabels['plot'] = description |
201 |
|
infoLabels['playcount'] = playcount |
202 |
listitem.setInfo('video', infoLabels) |
listitem.setInfo('video', infoLabels) |
203 |
|
|
204 |
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(name) + "&url=" + urllib.quote(url) |
name = name.encode('UTF-8') |
205 |
|
description = description.encode('UTF-8') |
206 |
|
|
207 |
|
|
208 |
|
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description) |
209 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l) |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l) |
210 |
|
|
211 |
if (endlist == True): |
if (endlist == True): |
214 |
|
|
215 |
|
|
216 |
|
|
217 |
def play_video(url, name): |
def play_video(url, name,description): |
218 |
xml = open_url(url) |
if (description == None or description == ""): |
219 |
|
play_real_video(url,name) |
220 |
|
else: |
221 |
|
d = TodicMovieDialog() |
222 |
|
d.setUrl( url) |
223 |
|
d.setName( name ) |
224 |
|
d.setDescription( description ) |
225 |
|
|
226 |
|
d.doModal() |
227 |
|
|
228 |
|
|
229 |
|
def play_real_video(url, name): |
230 |
|
xml = open_url(url) |
231 |
|
print 'TODIC url: ' + str(url) |
232 |
|
print 'TODIC xml: '+ xml |
233 |
|
|
234 |
doc = parseString(xml) |
doc = parseString(xml) |
235 |
url = getText( doc.getElementsByTagName("url") ) |
url = getText( doc.getElementsByTagName("url") ) |
236 |
|
|
237 |
print '[TODIC]:'+str(url) |
subtitleurl = getText( doc.getElementsByTagName("subtitles") ) |
238 |
|
subtitlesfile = os.path.join(datapath,'temp.srt') |
239 |
|
|
240 |
|
#if old srt file exists delete it first |
241 |
|
if os.path.isfile(subtitlesfile): |
242 |
|
os.unlink(subtitlesfile) |
243 |
|
|
244 |
|
print '[TODIC] subs: '+str(subtitleurl) |
245 |
|
if len(subtitleurl) > 0: |
246 |
|
subtitles = open_url(subtitleurl) |
247 |
|
SaveFile(subtitlesfile, subtitles) |
248 |
|
print 'TODIC downloaded subtitles' |
249 |
|
|
250 |
|
|
251 |
|
|
252 |
image = xbmc.getInfoImage( 'ListItem.Thumb' ) |
image = xbmc.getInfoImage( 'ListItem.Thumb' ) |
253 |
listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image) |
listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image) |
254 |
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
255 |
|
|
256 |
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
257 |
player.play(str(url), listitem) |
player.play(str(url), listitem) |
258 |
|
|
259 |
|
#kan ikke loade subtitles hvis foerend playeren koerer |
260 |
|
count = 0 |
261 |
|
while not xbmc.Player().isPlaying(): |
262 |
|
xbmc.sleep(500) |
263 |
|
count += 1 |
264 |
|
if count > 10: |
265 |
|
break |
266 |
|
|
267 |
|
|
268 |
|
if xbmc.Player().isPlaying(): |
269 |
|
if os.path.isfile(subtitlesfile): |
270 |
|
player.setSubtitles(subtitlesfile) |
271 |
|
print 'TODIC started subtitles' |
272 |
|
else: |
273 |
|
player.disableSubtitles() |
274 |
|
|
275 |
# player.callbackLoop() |
# player.callbackLoop() |
276 |
|
|
277 |
|
|
287 |
|
|
288 |
buildList(url, "søgning") |
buildList(url, "søgning") |
289 |
|
|
290 |
|
def searchSeries(): |
291 |
|
search = getUserInput("Todic Serie Søgning") |
292 |
|
|
293 |
|
if (search != None and search != ""): |
294 |
|
url = __backend__ + "&action=searchseries&search=" + urllib.quote_plus(search) |
295 |
|
|
296 |
|
#print "[TODIC] Search start: " + search |
297 |
|
#print "[TODIC] Search url: " + url |
298 |
|
|
299 |
|
buildList(url, "serie søgning") |
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
344 |
param[splitparams[0]]=splitparams[1] |
param[splitparams[0]]=splitparams[1] |
345 |
return param |
return param |
346 |
|
|
|
params = get_params() |
|
|
url = None |
|
|
name = None |
|
|
mode = None |
|
347 |
|
|
348 |
params = get_params() |
params = get_params() |
349 |
url = None |
url = None |
350 |
name = None |
name = None |
351 |
mode = None |
mode = None |
352 |
|
description = None |
353 |
|
|
354 |
try: |
try: |
355 |
url = urllib.unquote_plus(params["url"]) |
url = urllib.unquote_plus(params["url"]) |
363 |
mode = int(params["mode"]) |
mode = int(params["mode"]) |
364 |
except: |
except: |
365 |
pass |
pass |
366 |
|
try: |
367 |
|
description = urllib.unquote_plus(params["description"]) |
368 |
|
except: |
369 |
|
pass |
370 |
|
|
371 |
|
try: |
372 |
|
open_url("http://todic.dk") |
373 |
|
except: |
374 |
|
showMessage("Fejl", "Kunne ikke forbinde til todic.dk") |
375 |
|
exit() |
376 |
|
|
377 |
|
|
378 |
if mode == None: |
if url == 'refresh': |
379 |
|
#xbmc.output("[tvserver] Container.Refresh") #20130418 xbmc.output virker ikke med XBMC12 |
380 |
|
xbmc.executebuiltin("Container.Refresh") |
381 |
|
|
382 |
|
|
383 |
|
elif mode == None: |
384 |
#build main menu |
#build main menu |
385 |
rootMenu() |
rootMenu() |
386 |
|
|
390 |
|
|
391 |
elif mode == 10: |
elif mode == 10: |
392 |
search() |
search() |
393 |
|
|
394 |
|
elif mode == 11: |
395 |
|
searchSeries() |
396 |
|
|
397 |
|
|
398 |
elif mode == 50: |
elif mode == 50: |
399 |
play_video(url, name) |
play_video(url, name, description) |
400 |
|
|
401 |
|
|
402 |
|
|