1 |
|
|
2 |
|
# This Python file uses the following encoding: utf-8 |
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 |
10 |
import cgi as urlparse |
import cgi as urlparse |
11 |
|
import os |
12 |
|
|
13 |
|
|
14 |
import xbmc |
import xbmc |
15 |
import xbmcaddon |
import xbmcaddon |
16 |
import xbmcgui |
import xbmcgui |
17 |
import xbmcplugin |
import xbmcplugin |
18 |
import urllib |
import urllib |
19 |
import urllib2, re |
import urllib2 |
20 |
|
|
21 |
|
#import pprint |
22 |
|
|
23 |
|
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'), '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 |
|
def setUrl( self, url): |
65 |
|
print "SETURL:" + url |
66 |
|
self.url = url |
67 |
|
self.fetchClipDetails() |
68 |
|
|
69 |
|
|
70 |
|
def fetchClipDetails(self): |
71 |
|
param1 = parse_parameter_string( self.url ) |
72 |
|
|
73 |
|
self.clipkey = param1[ "clipkey" ] |
74 |
|
print "CLIPKEY:" + self.clipkey |
75 |
|
detailurl = __backend__ + "&action=clipdetails&clipkey=" + self.clipkey |
76 |
|
|
77 |
|
xml = open_url(detailurl) |
78 |
|
|
79 |
|
doc = parseString(xml) |
80 |
|
self.imdbrating = getText( doc.getElementsByTagName("imdbrating") ) |
81 |
|
self.moviegroups = getText( doc.getElementsByTagName("moviegroups") ) |
82 |
|
self.playlength = getText( doc.getElementsByTagName("playlength") ) |
83 |
|
self.codecdetails = getText( doc.getElementsByTagName("codecdetails") ) |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
def setName( self, name ): |
88 |
|
self.name = name |
89 |
|
|
90 |
|
def setDescription( self, description ): |
91 |
|
self.description = description |
92 |
|
|
93 |
|
|
94 |
|
class TodicPlayer(xbmc.Player): |
95 |
|
def __init__(self, *args, **kwargs): |
96 |
|
#xbmc.Player.__init__(selv,*args,**kwargs) |
97 |
|
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER ) |
98 |
|
self.stopped = False |
99 |
|
self.started = False |
100 |
|
print "[TodicPlayer] init" |
101 |
|
|
102 |
|
# @catchall |
103 |
|
def onPlayBackStarted(self): |
104 |
|
self.started = True |
105 |
|
print "[TodicPlayer] : started" |
106 |
|
# super.onPlayBackStarted() |
107 |
|
|
108 |
|
def onPlayBackStopped(self): |
109 |
|
self.stopped = True |
110 |
|
print "[TodicPlayer] : stopped" |
111 |
|
|
112 |
|
def onPlayBackEnded(self): |
113 |
|
self.stopped = True |
114 |
|
print "[TodicPlayer] : ended" |
115 |
|
|
116 |
|
def callbackLoop(self): |
117 |
|
print "[Todic] startLoop" |
118 |
|
while (self.stopped == False): |
119 |
|
if (self.started == True ): |
120 |
|
print "[todic] " + str(self.getTime()) |
121 |
|
xbmc.sleep(5000) |
122 |
|
|
123 |
|
|
124 |
|
def getText2(nodelist): |
125 |
|
rc = [] |
126 |
|
for node in nodelist: |
127 |
|
if node.nodeType == node.TEXT_NODE: |
128 |
|
rc.append(node.data) |
129 |
|
else: |
130 |
|
rc.append( getText(node.childNodes) ) |
131 |
|
return ''.join(rc) |
132 |
|
|
133 |
|
def getText(nodelist): |
134 |
|
if nodelist.length == 0: |
135 |
|
return '' |
136 |
|
else: |
137 |
|
if nodelist[0].childNodes.length == 0: |
138 |
|
return '' |
139 |
|
else: |
140 |
|
return nodelist[0].childNodes[0].nodeValue |
141 |
|
|
142 |
|
def SaveFile(path, data): |
143 |
|
file = open(path,'w') |
144 |
|
file.write(data) |
145 |
|
file.close() |
146 |
|
|
147 |
|
|
148 |
def open_url(url): |
def open_url(url): |
149 |
req = urllib2.Request(url) |
req = urllib2.Request(url) |
153 |
return data |
return data |
154 |
|
|
155 |
def rootMenu(): |
def rootMenu(): |
|
link = open_url(__backend__) |
|
|
m=re.compile('<title>(.+?)</title><url>(.+?)</url>').findall(link) |
|
|
l = len(m) |
|
|
for name,url in m: |
|
|
listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
|
|
u = sys.argv[0] + "?mode=1&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
|
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True, totalItems = l) |
|
|
|
|
|
listitem = xbmcgui.ListItem(label = "Søg ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
|
|
u = sys.argv[0] + "?mode=10&name=" + urllib.quote_plus(name) |
|
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True, totalItems = l) |
|
156 |
|
|
157 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
msg = open_url(__backend__ + "&action=messages") |
158 |
|
msg = msg.strip() |
159 |
|
|
160 |
|
if msg != "": |
161 |
|
dialog = xbmcgui.Dialog() |
162 |
|
dialog.ok('XBMC Todic', msg) |
163 |
|
|
164 |
|
buildList(__backend__, "", False) # call default list |
165 |
|
|
166 |
|
# Adde xtra items to root menu |
167 |
|
listitem = xbmcgui.ListItem(label = "Søg film ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
168 |
|
listitem.setProperty('Fanart_Image', fanartImage) |
169 |
|
|
170 |
|
u = sys.argv[0] + "?mode=10&name=" |
171 |
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) |
172 |
|
|
173 |
|
#add search series |
174 |
|
listitem = xbmcgui.ListItem(label = "Søg Serier ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
175 |
|
listitem.setProperty('Fanart_Image', fanartImage) |
176 |
|
|
177 |
|
u = sys.argv[0] + "?mode=11&name=" |
178 |
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) |
179 |
|
|
|
def buildList(url,title): |
|
|
print '[TODIC]:'+str(url) |
|
|
link = open_url(url) |
|
|
ty=re.compile('<meta type=\'(.+?)\'').findall(link) |
|
|
print '[TOD]'+str(ty[0]) |
|
|
m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover>').findall(link) |
|
|
l=len(m) |
|
|
for name,url,thumb in m: |
|
|
if ty[0] == 'clipList': |
|
|
mode = '50' |
|
|
folder = False |
|
|
else: |
|
|
mode = '2' |
|
|
folder = True |
|
|
|
|
|
listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
|
|
u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
|
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l) |
|
180 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
181 |
|
|
182 |
def buildSubList(url,title): |
|
183 |
|
def buildList(url,title, endlist=True): |
184 |
print '[TODIC]:'+str(url) |
print '[TODIC]:'+str(url) |
185 |
|
|
186 |
link = open_url(url) |
link = open_url(url) |
187 |
m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover>').findall(link) |
doc = parseString(link) |
188 |
l = len(m) |
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
189 |
for name,url,thumb in m: |
print '[TODIC]'+str(ty) |
190 |
listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
|
191 |
u = sys.argv[0] + "?mode=50&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
if ty == 'clipList': |
192 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = False, totalItems = l) |
mode = '50' |
193 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
folder = False |
194 |
|
else: |
195 |
|
mode = '1' |
196 |
|
folder = True |
197 |
|
|
198 |
|
|
199 |
|
entries = doc.getElementsByTagName("entry") |
200 |
|
l=len(entries) |
201 |
|
description = '' |
202 |
|
for entry in entries: |
203 |
|
name = getText( entry.getElementsByTagName("title") ) |
204 |
|
url = getText( entry.getElementsByTagName("url") ) |
205 |
|
thumb = getText( entry.getElementsByTagName("cover") ) |
206 |
|
description = getText( entry.getElementsByTagName("description") ) |
207 |
|
playcount = getText( entry.getElementsByTagName("playcount") ) |
208 |
|
|
209 |
|
if playcount == '': |
210 |
|
playcount = '0' |
211 |
|
playcount = int(playcount) |
212 |
|
|
213 |
|
|
214 |
|
## print "name:" + name |
215 |
|
# print "url:" + url |
216 |
|
# print "thumb:" + thumb |
217 |
|
# print "description:" + description |
218 |
|
|
219 |
|
|
220 |
|
listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
221 |
|
listitem.setProperty('Fanart_Image', fanartImage) |
222 |
|
if mode == '50': |
223 |
|
infoLabels = {} |
224 |
|
infoLabels['title'] = name |
225 |
|
infoLabels['plot'] = description |
226 |
|
infoLabels['playcount'] = playcount |
227 |
|
listitem.setInfo('video', infoLabels) |
228 |
|
|
229 |
|
name = name.encode('UTF-8') |
230 |
|
description = description.encode('UTF-8') |
231 |
|
|
232 |
|
|
233 |
|
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description) |
234 |
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l) |
235 |
|
|
236 |
|
if (endlist == True): |
237 |
|
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
def play_video(url, name,description): |
243 |
|
if (description == None or description == ""): |
244 |
|
play_real_video(url,name) |
245 |
|
else: |
246 |
|
d = TodicMovieDialog() |
247 |
|
d.setUrl( url) |
248 |
|
d.setName( name ) |
249 |
|
d.setDescription( description ) |
250 |
|
|
251 |
|
d.doModal() |
252 |
|
|
253 |
|
|
254 |
|
def play_real_video(url, name): |
255 |
|
xml = open_url(url) |
256 |
|
print 'TODIC url: ' + str(url) |
257 |
|
print 'TODIC xml: '+ xml |
258 |
|
|
259 |
|
doc = parseString(xml) |
260 |
|
url = getText( doc.getElementsByTagName("url") ) |
261 |
|
|
262 |
|
subtitleurl = getText( doc.getElementsByTagName("subtitles") ) |
263 |
|
subtitlesfile = os.path.join(datapath,'temp.srt') |
264 |
|
|
265 |
|
#if old srt file exists delete it first |
266 |
|
if os.path.isfile(subtitlesfile): |
267 |
|
os.unlink(subtitlesfile) |
268 |
|
|
269 |
|
print '[TODIC] subs: '+str(subtitleurl) |
270 |
|
if len(subtitleurl) > 0: |
271 |
|
subtitles = open_url(subtitleurl) |
272 |
|
SaveFile(subtitlesfile, subtitles) |
273 |
|
print 'TODIC downloaded subtitles' |
274 |
|
|
275 |
|
|
276 |
|
|
|
def play_video(url, name): |
|
|
link = open_url(url) |
|
|
match=re.compile('<url>(.+?)</url>').findall(link) |
|
|
url = match[0] |
|
|
print '[TODIC]:'+str(url) |
|
277 |
image = xbmc.getInfoImage( 'ListItem.Thumb' ) |
image = xbmc.getInfoImage( 'ListItem.Thumb' ) |
278 |
listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image) |
listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image) |
|
# listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = 'DefaultVideo.png') |
|
279 |
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
280 |
xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(str(url), listitem) |
|
281 |
xbmc.sleep(200) |
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
282 |
|
player.play(str(url), listitem) |
283 |
|
|
284 |
|
#kan ikke loade subtitles hvis foerend playeren koerer |
285 |
|
count = 0 |
286 |
|
while not xbmc.Player().isPlaying(): |
287 |
|
xbmc.sleep(500) |
288 |
|
count += 1 |
289 |
|
if count > 10: |
290 |
|
break |
291 |
|
|
292 |
|
|
293 |
|
if xbmc.Player().isPlaying(): |
294 |
|
if os.path.isfile(subtitlesfile): |
295 |
|
player.setSubtitles(subtitlesfile) |
296 |
|
print 'TODIC started subtitles' |
297 |
|
else: |
298 |
|
player.disableSubtitles() |
299 |
|
|
300 |
|
# player.callbackLoop() |
301 |
|
|
302 |
|
|
303 |
|
|
304 |
def search(): |
def search(): |
305 |
search = getUserInput("Todic Søgning") |
search = getUserInput("Todic Søgning") |
310 |
#print "[TODIC] Search start: " + search |
#print "[TODIC] Search start: " + search |
311 |
#print "[TODIC] Search url: " + url |
#print "[TODIC] Search url: " + url |
312 |
|
|
313 |
buildSubList(url, "søgning") |
buildList(url, "søgning") |
314 |
|
|
315 |
|
def searchSeries(): |
316 |
|
search = getUserInput("Todic Serie Søgning") |
317 |
|
|
318 |
|
if (search != None and search != ""): |
319 |
|
url = __backend__ + "&action=searchseries&search=" + urllib.quote_plus(search) |
320 |
|
|
321 |
|
#print "[TODIC] Search start: " + search |
322 |
|
#print "[TODIC] Search url: " + url |
323 |
|
|
324 |
|
buildList(url, "serie søgning") |
325 |
|
|
326 |
|
|
327 |
|
|
353 |
|
|
354 |
|
|
355 |
def get_params(): |
def get_params(): |
356 |
|
return parse_parameter_string( sys.argv[2] ) |
357 |
|
|
358 |
|
def parse_parameter_string( paramstring ): |
359 |
param=[] |
param=[] |
|
paramstring=sys.argv[2] |
|
360 |
if len(paramstring)>=2: |
if len(paramstring)>=2: |
361 |
params=sys.argv[2] |
params = paramstring |
362 |
cleanedparams=params.replace('?','') |
cleanedparams=params.replace('?','') |
363 |
if (params[len(params)-1]=='/'): |
if (params[len(params)-1]=='/'): |
364 |
params=params[0:len(params)-2] |
params=params[0:len(params)-2] |
371 |
param[splitparams[0]]=splitparams[1] |
param[splitparams[0]]=splitparams[1] |
372 |
return param |
return param |
373 |
|
|
|
params = get_params() |
|
|
url = None |
|
|
name = None |
|
|
mode = None |
|
374 |
|
|
375 |
params = get_params() |
params = get_params() |
376 |
url = None |
url = None |
377 |
name = None |
name = None |
378 |
mode = None |
mode = None |
379 |
|
description = None |
380 |
|
|
381 |
try: |
try: |
382 |
url = urllib.unquote_plus(params["url"]) |
url = urllib.unquote_plus(params["url"]) |
390 |
mode = int(params["mode"]) |
mode = int(params["mode"]) |
391 |
except: |
except: |
392 |
pass |
pass |
393 |
|
try: |
394 |
|
description = urllib.unquote_plus(params["description"]) |
395 |
|
except: |
396 |
|
pass |
397 |
|
|
398 |
|
try: |
399 |
|
open_url("http://todic.dk") |
400 |
|
except: |
401 |
|
showMessage("Fejl", "Kunne ikke forbinde til todic.dk") |
402 |
|
exit() |
403 |
|
|
404 |
|
|
405 |
|
if url == 'refresh': |
406 |
|
#xbmc.output("[tvserver] Container.Refresh") #20130418 xbmc.output virker ikke med XBMC12 |
407 |
|
xbmc.executebuiltin("Container.Refresh") |
408 |
|
|
409 |
|
|
410 |
if mode == None: |
elif mode == None: |
411 |
#build main menu |
#build main menu |
412 |
rootMenu() |
rootMenu() |
413 |
|
|
415 |
#build list of movie starting letters |
#build list of movie starting letters |
416 |
buildList(url, name) |
buildList(url, name) |
417 |
|
|
|
elif mode == 2: |
|
|
#build list of series |
|
|
buildSubList(url, name) |
|
|
|
|
418 |
elif mode == 10: |
elif mode == 10: |
419 |
search() |
search() |
420 |
|
|
421 |
|
elif mode == 11: |
422 |
|
searchSeries() |
423 |
|
|
424 |
|
|
425 |
elif mode == 50: |
elif mode == 50: |
426 |
play_video(url, name) |
play_video(url, name, description) |
427 |
|
|
428 |
|
|
429 |
|
|
|
# xbmcplugin.endOfDirectory(int(sys.argv[1])) |
|
430 |
|
|