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.13 |
7 |
''' |
''' |
8 |
|
|
9 |
import sys |
import sys |
16 |
import xbmcgui |
import xbmcgui |
17 |
import xbmcplugin |
import xbmcplugin |
18 |
import urllib |
import urllib |
19 |
import urllib2, re |
import urllib2 |
20 |
|
|
21 |
|
from xml.dom.minidom import parseString |
22 |
|
|
23 |
__addon__ = xbmcaddon.Addon(id='plugin.video.todic') |
__addon__ = xbmcaddon.Addon(id='plugin.video.todic') |
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): |
70 |
|
def __init__(self, *args, **kwargs): |
71 |
|
#xbmc.Player.__init__(selv,*args,**kwargs) |
72 |
|
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER ) |
73 |
|
self.stopped = False |
74 |
|
self.started = False |
75 |
|
print "[TodicPlayer] init" |
76 |
|
|
77 |
|
# @catchall |
78 |
|
def onPlayBackStarted(self): |
79 |
|
self.started = True |
80 |
|
print "[TodicPlayer] : started" |
81 |
|
# super.onPlayBackStarted() |
82 |
|
|
83 |
|
def onPlayBackStopped(self): |
84 |
|
self.stopped = True |
85 |
|
print "[TodicPlayer] : stopped" |
86 |
|
|
87 |
|
def onPlayBackEnded(self): |
88 |
|
self.stopped = True |
89 |
|
print "[TodicPlayer] : ended" |
90 |
|
|
91 |
|
def callbackLoop(self): |
92 |
|
print "[Todic] startLoop" |
93 |
|
while (self.stopped == False): |
94 |
|
if (self.started == True ): |
95 |
|
print "[todic] " + str(self.getTime()) |
96 |
|
xbmc.sleep(5000) |
97 |
|
|
98 |
|
|
99 |
|
def getText2(nodelist): |
100 |
|
rc = [] |
101 |
|
for node in nodelist: |
102 |
|
if node.nodeType == node.TEXT_NODE: |
103 |
|
rc.append(node.data) |
104 |
|
else: |
105 |
|
rc.append( getText(node.childNodes) ) |
106 |
|
return ''.join(rc) |
107 |
|
|
108 |
|
def getText(nodelist): |
109 |
|
if nodelist.length == 0: |
110 |
|
return '' |
111 |
|
else: |
112 |
|
if nodelist[0].childNodes.length == 0: |
113 |
|
return '' |
114 |
|
else: |
115 |
|
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 |
ty=re.compile('<meta type=\'(.+?)\'').findall(link) |
doc = parseString(link) |
163 |
print '[TODIC]'+str(ty[0]) |
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
164 |
|
print '[TODIC]'+str(ty) |
165 |
|
|
166 |
if ty[0] == 'clipList': |
if ty == 'clipList': |
167 |
mode = '50' |
mode = '50' |
168 |
folder = False |
folder = False |
169 |
else: |
else: |
170 |
mode = '1' |
mode = '1' |
171 |
folder = True |
folder = True |
172 |
|
|
173 |
m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover><description>(.*)</description>').findall(link) |
|
174 |
l=len(m) |
entries = doc.getElementsByTagName("entry") |
175 |
for name,url,thumb,description in m: |
l=len(entries) |
176 |
|
description = '' |
177 |
|
for entry in entries: |
178 |
|
name = getText( entry.getElementsByTagName("title") ) |
179 |
|
url = getText( entry.getElementsByTagName("url") ) |
180 |
|
thumb = getText( entry.getElementsByTagName("cover") ) |
181 |
|
description = getText( entry.getElementsByTagName("description") ) |
182 |
|
playcount = getText( entry.getElementsByTagName("playcount") ) |
183 |
|
|
184 |
|
if playcount == '': |
185 |
|
playcount = '0' |
186 |
|
playcount = int(playcount) |
187 |
|
|
188 |
|
|
189 |
|
## print "name:" + name |
190 |
|
# print "url:" + url |
191 |
|
# print "thumb:" + thumb |
192 |
|
# print "description:" + description |
193 |
|
|
194 |
|
|
195 |
listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
196 |
listitem.setProperty('Fanart_Image', fanartImage) |
listitem.setProperty('Fanart_Image', fanartImage) |
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_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(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 |
link = open_url(url) |
if (description == None or description == ""): |
219 |
match=re.compile('<url>(.+?)</url>').findall(link) |
play_real_video(url,name) |
220 |
url = match[0] |
else: |
221 |
print '[TODIC]:'+str(url) |
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) |
235 |
|
url = getText( doc.getElementsByTagName("url") ) |
236 |
|
|
237 |
|
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) |
|
# listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = 'DefaultVideo.png') |
|
254 |
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
255 |
xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(str(url), listitem) |
|
256 |
xbmc.sleep(200) |
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
257 |
|
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() |
276 |
|
|
277 |
|
|
278 |
|
|
279 |
def search(): |
def search(): |
280 |
search = getUserInput("Todic Søgning") |
search = getUserInput("Todic Søgning") |
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 |
|
|
|
# xbmcplugin.endOfDirectory(int(sys.argv[1])) |
|
403 |
|
|