3 |
|
|
4 |
''' |
''' |
5 |
Todic plugin for XBMC |
Todic plugin for XBMC |
6 |
Version 0.0.2 |
Version 0.0.15 |
7 |
''' |
''' |
8 |
|
|
9 |
import sys |
import sys |
18 |
import urllib |
import urllib |
19 |
import urllib2 |
import urllib2 |
20 |
|
|
21 |
|
#import pprint |
22 |
|
|
23 |
from xml.dom.minidom import parseString |
from xml.dom.minidom import parseString |
24 |
|
|
25 |
__addon__ = xbmcaddon.Addon(id='plugin.video.todic') |
__addon__ = xbmcaddon.Addon(id='plugin.video.todic') |
26 |
__key__ = __addon__.getSetting('xbmckey').lower() |
__key__ = __addon__.getSetting('xbmckey').lower() |
27 |
__backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__ |
__backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__ |
28 |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'fanart.jpg') |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg') |
29 |
|
datapath = xbmc.translatePath('special://profile/addon_data/plugin.video.todic/') |
30 |
|
|
31 |
|
ADDON_PATH = __addon__.getAddonInfo('path') |
32 |
|
SkinMasterPath = os.path.join(ADDON_PATH, 'skins' ) + '/' |
33 |
|
MySkinPath = (os.path.join(SkinMasterPath, '720p')) + '/' |
34 |
|
MySkin = 'main.xml' |
35 |
|
|
36 |
|
|
37 |
|
class TodicMovieDialog(xbmcgui.WindowXMLDialog): |
38 |
|
def __new__(cls): |
39 |
|
return super(TodicMovieDialog, cls).__new__(cls, "main.xml", ADDON_PATH) |
40 |
|
|
41 |
|
def __init__(self): |
42 |
|
super(TodicMovieDialog, self).__init__() |
43 |
|
|
44 |
|
def onClick( self, controlId ): |
45 |
|
print "OnClick: " + str(controlId) |
46 |
|
|
47 |
|
if (controlId == 50): |
48 |
|
self.close() |
49 |
|
play_real_video(self.url, self.name) |
50 |
|
|
51 |
|
if ( controlId == 98 ): |
52 |
|
self.close() |
53 |
|
|
54 |
|
|
55 |
|
def onInit(self): |
56 |
|
|
57 |
|
print "ONINIT" |
58 |
|
self.getControl( 1 ).setLabel( self.name); |
59 |
|
self.getControl( 2 ).setLabel( self.moviegroups ) |
60 |
|
self.getControl( 3 ).setLabel( self.description ) |
61 |
|
self.getControl( 10 ).setLabel( self.playlength ) |
62 |
|
self.getControl( 11 ).setLabel( self.codecdetails ) |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
orig_img_width = self.getControl(40).getWidth() |
67 |
|
self.starwidth = ( float(self.imdbrating) / 10.0) * orig_img_width; |
68 |
|
self.getControl(40).setWidth( int(self.starwidth) ) |
69 |
|
|
70 |
|
def setUrl( self, url): |
71 |
|
print "SETURL:" + url |
72 |
|
self.url = url |
73 |
|
self.fetchClipDetails() |
74 |
|
|
75 |
|
|
76 |
|
def fetchClipDetails(self): |
77 |
|
param1 = parse_parameter_string( self.url ) |
78 |
|
|
79 |
|
self.clipkey = param1[ "clipkey" ] |
80 |
|
print "CLIPKEY:" + self.clipkey |
81 |
|
detailurl = __backend__ + "&action=clipdetails&clipkey=" + self.clipkey |
82 |
|
|
83 |
|
xml = open_url(detailurl) |
84 |
|
|
85 |
|
doc = parseString(xml) |
86 |
|
self.imdbrating = getText( doc.getElementsByTagName("imdbrating") ) |
87 |
|
self.moviegroups = getText( doc.getElementsByTagName("moviegroups") ) |
88 |
|
self.playlength = getText( doc.getElementsByTagName("playlength") ) |
89 |
|
self.codecdetails = getText( doc.getElementsByTagName("codecdetails") ) |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
def setName( self, name ): |
96 |
|
self.name = name |
97 |
|
|
98 |
|
def setDescription( self, description ): |
99 |
|
self.description = description |
100 |
|
|
101 |
|
|
102 |
class TodicPlayer(xbmc.Player): |
class TodicPlayer(xbmc.Player): |
147 |
else: |
else: |
148 |
return nodelist[0].childNodes[0].nodeValue |
return nodelist[0].childNodes[0].nodeValue |
149 |
|
|
150 |
|
def SaveFile(path, data): |
151 |
|
file = open(path,'w') |
152 |
|
file.write(data) |
153 |
|
file.close() |
154 |
|
|
155 |
|
|
156 |
def open_url(url): |
def open_url(url): |
157 |
req = urllib2.Request(url) |
req = urllib2.Request(url) |
178 |
u = sys.argv[0] + "?mode=10&name=" |
u = sys.argv[0] + "?mode=10&name=" |
179 |
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) |
180 |
|
|
181 |
|
#add search series |
182 |
|
listitem = xbmcgui.ListItem(label = "Søg Serier ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
183 |
|
listitem.setProperty('Fanart_Image', fanartImage) |
184 |
|
|
185 |
|
u = sys.argv[0] + "?mode=11&name=" |
186 |
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) |
187 |
|
|
188 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
189 |
|
|
190 |
|
|
191 |
def buildList(url,title, endlist=True): |
def buildList(url,title, endlist=True): |
192 |
print '[TODIC]:'+str(url) |
print '[TODIC]:'+str(url) |
193 |
|
|
194 |
link = open_url(url) |
link = open_url(url) |
195 |
doc = parseString(link) |
doc = parseString(link) |
203 |
mode = '1' |
mode = '1' |
204 |
folder = True |
folder = True |
205 |
|
|
206 |
|
|
207 |
entries = doc.getElementsByTagName("entry") |
entries = doc.getElementsByTagName("entry") |
208 |
l=len(entries) |
l=len(entries) |
209 |
description = '' |
description = '' |
212 |
url = getText( entry.getElementsByTagName("url") ) |
url = getText( entry.getElementsByTagName("url") ) |
213 |
thumb = getText( entry.getElementsByTagName("cover") ) |
thumb = getText( entry.getElementsByTagName("cover") ) |
214 |
description = getText( entry.getElementsByTagName("description") ) |
description = getText( entry.getElementsByTagName("description") ) |
215 |
|
playcount = getText( entry.getElementsByTagName("playcount") ) |
216 |
|
|
217 |
|
if playcount == '': |
218 |
|
playcount = '0' |
219 |
|
playcount = int(playcount) |
220 |
|
|
|
name = name.encode('latin-1') |
|
|
description = description.encode('latin-1') |
|
221 |
|
|
222 |
## print "name:" + name |
## print "name:" + name |
223 |
# print "url:" + url |
# print "url:" + url |
230 |
if mode == '50': |
if mode == '50': |
231 |
infoLabels = {} |
infoLabels = {} |
232 |
infoLabels['title'] = name |
infoLabels['title'] = name |
233 |
infoLabels['plot'] = description |
infoLabels['plot'] = description |
234 |
|
infoLabels['playcount'] = playcount |
235 |
listitem.setInfo('video', infoLabels) |
listitem.setInfo('video', infoLabels) |
236 |
|
|
237 |
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(name) + "&url=" + urllib.quote(url) |
name = name.encode('UTF-8') |
238 |
|
description = description.encode('UTF-8') |
239 |
|
|
240 |
|
|
241 |
|
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description) |
242 |
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) |
243 |
|
|
244 |
if (endlist == True): |
if (endlist == True): |
247 |
|
|
248 |
|
|
249 |
|
|
250 |
def play_video(url, name): |
def play_video(url, name,description): |
251 |
xml = open_url(url) |
if (description == None or description == ""): |
252 |
|
play_real_video(url,name) |
253 |
|
else: |
254 |
|
d = TodicMovieDialog() |
255 |
|
d.setUrl( url) |
256 |
|
d.setName( name ) |
257 |
|
d.setDescription( description ) |
258 |
|
|
259 |
|
d.doModal() |
260 |
|
|
261 |
|
|
262 |
|
def play_real_video(url, name): |
263 |
|
xml = open_url(url) |
264 |
|
print 'TODIC url: ' + str(url) |
265 |
|
print 'TODIC xml: '+ xml |
266 |
|
|
267 |
doc = parseString(xml) |
doc = parseString(xml) |
268 |
url = getText( doc.getElementsByTagName("url") ) |
url = getText( doc.getElementsByTagName("url") ) |
269 |
|
|
270 |
print '[TODIC]:'+str(url) |
subtitleurl = getText( doc.getElementsByTagName("subtitles") ) |
271 |
|
subtitlesfile = os.path.join(datapath,'temp.srt') |
272 |
|
|
273 |
|
#if old srt file exists delete it first |
274 |
|
if os.path.isfile(subtitlesfile): |
275 |
|
os.unlink(subtitlesfile) |
276 |
|
|
277 |
|
print '[TODIC] subs: '+str(subtitleurl) |
278 |
|
if len(subtitleurl) > 0: |
279 |
|
subtitles = open_url(subtitleurl) |
280 |
|
SaveFile(subtitlesfile, subtitles) |
281 |
|
print 'TODIC downloaded subtitles' |
282 |
|
|
283 |
|
|
284 |
|
|
285 |
image = xbmc.getInfoImage( 'ListItem.Thumb' ) |
image = xbmc.getInfoImage( 'ListItem.Thumb' ) |
286 |
listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image) |
listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image) |
287 |
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
288 |
|
|
289 |
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
290 |
player.play(str(url), listitem) |
player.play(str(url), listitem) |
291 |
|
|
292 |
|
#kan ikke loade subtitles hvis foerend playeren koerer |
293 |
|
count = 0 |
294 |
|
while not xbmc.Player().isPlaying(): |
295 |
|
xbmc.sleep(500) |
296 |
|
count += 1 |
297 |
|
if count > 10: |
298 |
|
break |
299 |
|
|
300 |
|
|
301 |
|
if xbmc.Player().isPlaying(): |
302 |
|
if os.path.isfile(subtitlesfile): |
303 |
|
player.setSubtitles(subtitlesfile) |
304 |
|
print 'TODIC started subtitles' |
305 |
|
else: |
306 |
|
player.disableSubtitles() |
307 |
|
|
308 |
# player.callbackLoop() |
# player.callbackLoop() |
309 |
|
|
310 |
|
|
320 |
|
|
321 |
buildList(url, "søgning") |
buildList(url, "søgning") |
322 |
|
|
323 |
|
def searchSeries(): |
324 |
|
search = getUserInput("Todic Serie Søgning") |
325 |
|
|
326 |
|
if (search != None and search != ""): |
327 |
|
url = __backend__ + "&action=searchseries&search=" + urllib.quote_plus(search) |
328 |
|
|
329 |
|
#print "[TODIC] Search start: " + search |
330 |
|
#print "[TODIC] Search url: " + url |
331 |
|
|
332 |
|
buildList(url, "serie søgning") |
333 |
|
|
334 |
|
|
335 |
|
|
336 |
|
|
361 |
|
|
362 |
|
|
363 |
def get_params(): |
def get_params(): |
364 |
|
return parse_parameter_string( sys.argv[2] ) |
365 |
|
|
366 |
|
def parse_parameter_string( paramstring ): |
367 |
param=[] |
param=[] |
|
paramstring=sys.argv[2] |
|
368 |
if len(paramstring)>=2: |
if len(paramstring)>=2: |
369 |
params=sys.argv[2] |
params = paramstring |
370 |
cleanedparams=params.replace('?','') |
cleanedparams=params.replace('?','') |
371 |
if (params[len(params)-1]=='/'): |
if (params[len(params)-1]=='/'): |
372 |
params=params[0:len(params)-2] |
params=params[0:len(params)-2] |
384 |
url = None |
url = None |
385 |
name = None |
name = None |
386 |
mode = None |
mode = None |
387 |
|
description = None |
388 |
|
|
389 |
try: |
try: |
390 |
url = urllib.unquote_plus(params["url"]) |
url = urllib.unquote_plus(params["url"]) |
398 |
mode = int(params["mode"]) |
mode = int(params["mode"]) |
399 |
except: |
except: |
400 |
pass |
pass |
401 |
|
try: |
402 |
|
description = urllib.unquote_plus(params["description"]) |
403 |
|
except: |
404 |
|
pass |
405 |
|
|
406 |
|
try: |
407 |
|
open_url("http://todic.dk") |
408 |
|
except: |
409 |
|
showMessage("Fejl", "Kunne ikke forbinde til todic.dk") |
410 |
|
exit() |
411 |
|
|
412 |
|
|
413 |
if mode == None: |
if url == 'refresh': |
414 |
|
#xbmc.output("[tvserver] Container.Refresh") #20130418 xbmc.output virker ikke med XBMC12 |
415 |
|
xbmc.executebuiltin("Container.Refresh") |
416 |
|
|
417 |
|
|
418 |
|
elif mode == None: |
419 |
#build main menu |
#build main menu |
420 |
rootMenu() |
rootMenu() |
421 |
|
|
425 |
|
|
426 |
elif mode == 10: |
elif mode == 10: |
427 |
search() |
search() |
428 |
|
|
429 |
|
elif mode == 11: |
430 |
|
searchSeries() |
431 |
|
|
432 |
|
|
433 |
elif mode == 50: |
elif mode == 50: |
434 |
play_video(url, name) |
play_video(url, name, description) |
435 |
|
|
436 |
|
|
437 |
|
|