3 |
|
|
4 |
''' |
''' |
5 |
Todic plugin for XBMC |
Todic plugin for XBMC |
6 |
Version 0.0.14 |
Version 0.1.0 |
7 |
''' |
''' |
8 |
|
|
9 |
import sys |
import sys |
|
import cgi as urlparse |
|
10 |
import os |
import os |
11 |
|
|
12 |
|
|
17 |
import urllib |
import urllib |
18 |
import urllib2 |
import urllib2 |
19 |
|
|
20 |
|
# import pprint |
21 |
|
|
22 |
from xml.dom.minidom import parseString |
from xml.dom.minidom import parseString |
23 |
|
from time import time |
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__ = "https://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/') |
datapath = xbmc.translatePath( |
30 |
|
'special://profile/addon_data/plugin.video.todic/') |
31 |
|
|
32 |
ADDON_PATH = __addon__.getAddonInfo('path') |
ADDON_PATH = __addon__.getAddonInfo('path') |
33 |
SkinMasterPath = os.path.join(ADDON_PATH, 'skins' ) + '/' |
SkinMasterPath = os.path.join(ADDON_PATH, 'skins') + '/' |
34 |
MySkinPath = (os.path.join(SkinMasterPath, '720p')) + '/' |
MySkinPath = (os.path.join(SkinMasterPath, '720p')) + '/' |
35 |
MySkin = 'main.xml' |
MySkin = 'main.xml' |
36 |
|
|
37 |
|
|
38 |
class TodicMovieDialog(xbmcgui.WindowXMLDialog): |
class TodicMovieDialog(xbmcgui.WindowXMLDialog): |
|
def __new__(cls): |
|
|
return super(TodicMovieDialog, cls).__new__(cls, "main.xml", ADDON_PATH) |
|
|
|
|
|
def __init__(self): |
|
|
super(TodicMovieDialog, self).__init__() |
|
|
|
|
|
def onClick( self, controlId ): |
|
|
print "OnClick: " + str(controlId) |
|
|
|
|
|
if (controlId == 50): |
|
|
self.close() |
|
|
play_real_video(self.url, self.name) |
|
|
|
|
|
if ( controlId == 98 ): |
|
|
self.close() |
|
39 |
|
|
40 |
|
def __new__(cls): |
41 |
|
return super(TodicMovieDialog, cls).__new__(cls, "main.xml", ADDON_PATH) |
42 |
|
|
43 |
def onInit(self): |
def __init__(self): |
44 |
|
super(TodicMovieDialog, self).__init__() |
45 |
|
self.position = 0 |
46 |
|
|
47 |
|
def onClick(self, controlId): |
48 |
|
print "[Todic] MovieDialog OnClick: " + str(controlId) |
49 |
|
|
50 |
|
if (controlId == 50): |
51 |
|
self.close() |
52 |
|
play_real_video(self.url, self.name, 0) |
53 |
|
|
54 |
|
if (controlId == 51): |
55 |
|
self.close() |
56 |
|
play_real_video(self.url, self.name, self.position) |
57 |
|
|
58 |
|
if (controlId == 98): |
59 |
|
self.close() |
60 |
|
|
61 |
|
def onInit(self): |
62 |
|
|
63 |
|
print "[Todic] MovieDialog onInit" |
64 |
|
self.getControl(1).setLabel(self.name) |
65 |
|
self.getControl(2).setLabel(self.moviegroups) |
66 |
|
self.getControl(3).setLabel(self.description) |
67 |
|
self.getControl(10).setLabel(self.playlength) |
68 |
|
self.getControl(11).setLabel(self.codecdetails) |
69 |
|
|
70 |
|
if (self.position > 0): |
71 |
|
self.getControl(51).setVisible(True) |
72 |
|
self.getControl(50).setPosition(100, 570) |
73 |
|
self.getControl(51).setPosition(450, 570) |
74 |
|
self.getControl(50).controlLeft( self.getControl(51) ) |
75 |
|
self.getControl(50).controlRight( self.getControl(51) ) |
76 |
|
else: |
77 |
|
self.getControl(51).setVisible(False) |
78 |
|
|
79 |
print "ONINIT" |
#orig_img_width = self.getControl(40).getWidth() |
80 |
self.getControl( 1 ).setLabel( self.name); |
#self.starwidth = (float(self.imdbrating) / 10.0) * orig_img_width |
81 |
self.getControl( 2 ).setLabel( self.description ); |
#self.getControl(40).setWidth(int(self.starwidth)) |
82 |
|
|
83 |
|
def setDetailsDoc(self, detailsDoc): |
84 |
|
print "[Todic] MovieDialog setDetailsDoc:" |
85 |
|
self.imdbrating = getText(detailsDoc.getElementsByTagName("imdbrating")) |
86 |
|
self.moviegroups = getText(detailsDoc.getElementsByTagName("moviegroups")) |
87 |
|
self.playlength = getText(detailsDoc.getElementsByTagName("playlength")) |
88 |
|
self.codecdetails = getText(detailsDoc.getElementsByTagName("codecdetails")) |
89 |
|
self.position = int( getText(detailsDoc.getElementsByTagName("position")) ) |
90 |
|
|
|
def setUrl( self, url): |
|
|
self.url = url |
|
91 |
|
|
92 |
def setName( self, name ): |
def setName(self, name): |
93 |
self.name = name |
self.name = name |
94 |
|
|
95 |
def setDescription( self, description ): |
def setDescription(self, description): |
96 |
self.description = description |
self.description = description |
97 |
|
|
98 |
|
|
99 |
class TodicPlayer(xbmc.Player): |
class TodicPlayer(xbmc.Player): |
|
def __init__(self, *args, **kwargs): |
|
|
#xbmc.Player.__init__(selv,*args,**kwargs) |
|
|
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER ) |
|
|
self.stopped = False |
|
|
self.started = False |
|
|
print "[TodicPlayer] init" |
|
|
|
|
|
# @catchall |
|
|
def onPlayBackStarted(self): |
|
|
self.started = True |
|
|
print "[TodicPlayer] : started" |
|
|
# super.onPlayBackStarted() |
|
|
|
|
|
def onPlayBackStopped(self): |
|
|
self.stopped = True |
|
|
print "[TodicPlayer] : stopped" |
|
|
|
|
|
def onPlayBackEnded(self): |
|
|
self.stopped = True |
|
|
print "[TodicPlayer] : ended" |
|
|
|
|
|
def callbackLoop(self): |
|
|
print "[Todic] startLoop" |
|
|
while (self.stopped == False): |
|
|
if (self.started == True ): |
|
|
print "[todic] " + str(self.getTime()) |
|
|
xbmc.sleep(5000) |
|
|
|
|
100 |
|
|
101 |
def getText2(nodelist): |
def __init__(self, *args, **kwargs): |
102 |
rc = [] |
# xbmc.Player.__init__(selv,*args,**kwargs) |
103 |
for node in nodelist: |
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER) |
104 |
if node.nodeType == node.TEXT_NODE: |
self.stopped = False |
105 |
rc.append(node.data) |
self.started = False |
106 |
else: |
self.playingPosition = 0.0 |
107 |
rc.append( getText(node.childNodes) ) |
self.lastReport = 0 |
108 |
return ''.join(rc) |
print "[TodicPlayer] init" |
109 |
|
|
110 |
|
def onPlayBackStarted(self): |
111 |
|
self.started = True |
112 |
|
print "[TodicPlayer] : started" |
113 |
|
|
114 |
|
#When user presses stop, we report back the the position registered in the last call to self.tick() |
115 |
|
def onPlayBackStopped(self): |
116 |
|
self.stopped = True |
117 |
|
print "[TodicPlayer] : stopped" |
118 |
|
self.reportPlaytime("stopped") |
119 |
|
|
|
def getText(nodelist): |
|
|
if nodelist.length == 0: |
|
|
return '' |
|
|
else: |
|
|
if nodelist[0].childNodes.length == 0: |
|
|
return '' |
|
|
else: |
|
|
return nodelist[0].childNodes[0].nodeValue |
|
120 |
|
|
|
def SaveFile(path, data): |
|
|
file = open(path,'w') |
|
|
file.write(data) |
|
|
file.close() |
|
121 |
|
|
122 |
|
def onPlayBackEnded(self): |
123 |
|
self.stopped = True |
124 |
|
print "[TodicPlayer] : ended" |
125 |
|
self.reportPlaytime("ended") |
126 |
|
|
127 |
|
def tick(self): |
128 |
|
if ( self.isPlaying() ): |
129 |
|
self.playingPosition = self.getTime() |
130 |
|
now = time() |
131 |
|
#print "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport) |
132 |
|
if ( (now - self.lastReport) > 60.0): |
133 |
|
self.lastReport = now |
134 |
|
self.reportPlaytime("playing") |
135 |
|
|
136 |
|
def reportPlaytime(self, subaction): |
137 |
|
if (self.playingPosition > 60): |
138 |
|
url = __backend__ + "&action=playbacktime&subaction=" + subaction + "&time=" + str( self.playingPosition ) |
139 |
|
print "[Todic] reportPlaytime:" + url |
140 |
|
open_url_safe(url) |
141 |
|
|
142 |
def open_url(url): |
|
|
req = urllib2.Request(url) |
|
|
content = urllib2.urlopen(req) |
|
|
data = content.read() |
|
|
content.close() |
|
|
return data |
|
143 |
|
|
|
def rootMenu(): |
|
144 |
|
|
145 |
msg = open_url(__backend__ + "&action=messages") |
def getText2(nodelist): |
146 |
msg = msg.strip() |
rc = [] |
147 |
|
for node in nodelist: |
148 |
|
if node.nodeType == node.TEXT_NODE: |
149 |
|
rc.append(node.data) |
150 |
|
else: |
151 |
|
rc.append(getText(node.childNodes)) |
152 |
|
return ''.join(rc) |
153 |
|
|
154 |
|
|
155 |
if msg != "": |
def getText(nodelist): |
156 |
dialog = xbmcgui.Dialog() |
if nodelist.length == 0: |
157 |
dialog.ok('XBMC Todic', msg) |
return '' |
158 |
|
else: |
159 |
|
if nodelist[0].childNodes.length == 0: |
160 |
|
return '' |
161 |
|
else: |
162 |
|
return nodelist[0].childNodes[0].nodeValue |
163 |
|
|
|
buildList(__backend__, "", False) # call default list |
|
164 |
|
|
|
# Adde xtra items to root menu |
|
|
listitem = xbmcgui.ListItem(label = "Søg film ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
|
|
listitem.setProperty('Fanart_Image', fanartImage) |
|
165 |
|
|
166 |
u = sys.argv[0] + "?mode=10&name=" |
def SaveFile(path, data): |
167 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) |
file = open(path, 'w') |
168 |
|
file.write(data) |
169 |
|
file.close() |
170 |
|
|
|
#add search series |
|
|
listitem = xbmcgui.ListItem(label = "Søg Serier ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
|
|
listitem.setProperty('Fanart_Image', fanartImage) |
|
171 |
|
|
|
u = sys.argv[0] + "?mode=11&name=" |
|
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) |
|
172 |
|
|
173 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
def open_url(url): |
174 |
|
req = urllib2.Request(url) |
175 |
|
content = urllib2.urlopen(req) |
176 |
|
data = content.read() |
177 |
|
content.close() |
178 |
|
return data |
179 |
|
|
180 |
|
|
181 |
def buildList(url,title, endlist=True): |
# wraps open url in a catch-all exception handler |
182 |
print '[TODIC]:'+str(url) |
# usefull for periodic back-reporting that should not interrupt the program flow |
183 |
|
def open_url_safe(url): |
184 |
|
try: |
185 |
|
return open_url(url) |
186 |
|
except: |
187 |
|
print "[Todic ]Some error during open_url call to ", url |
188 |
|
|
|
link = open_url(url) |
|
|
doc = parseString(link) |
|
|
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
|
|
print '[TODIC]'+str(ty) |
|
189 |
|
|
|
if ty == 'clipList': |
|
|
mode = '50' |
|
|
folder = False |
|
|
else: |
|
|
mode = '1' |
|
|
folder = True |
|
190 |
|
|
191 |
|
def rootMenu(): |
192 |
|
|
193 |
entries = doc.getElementsByTagName("entry") |
msg = open_url(__backend__ + "&action=messages") |
194 |
l=len(entries) |
msg = msg.strip() |
|
description = '' |
|
|
for entry in entries: |
|
|
name = getText( entry.getElementsByTagName("title") ) |
|
|
url = getText( entry.getElementsByTagName("url") ) |
|
|
thumb = getText( entry.getElementsByTagName("cover") ) |
|
|
description = getText( entry.getElementsByTagName("description") ) |
|
|
playcount = getText( entry.getElementsByTagName("playcount") ) |
|
|
|
|
|
if playcount == '': |
|
|
playcount = '0' |
|
|
playcount = int(playcount) |
|
195 |
|
|
196 |
|
if msg != "": |
197 |
|
dialog = xbmcgui.Dialog() |
198 |
|
dialog.ok('XBMC Todic', msg) |
199 |
|
|
200 |
|
buildList(__backend__, "", False) # call default list |
201 |
|
|
202 |
|
# Adde xtra items to root menu |
203 |
|
listitem = xbmcgui.ListItem( |
204 |
|
label="Søg film ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png') |
205 |
|
listitem.setProperty('Fanart_Image', fanartImage) |
206 |
|
|
207 |
|
u = sys.argv[0] + "?mode=10&name=" |
208 |
|
xbmcplugin.addDirectoryItem( |
209 |
|
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True) |
210 |
|
|
211 |
|
# add search series |
212 |
|
listitem = xbmcgui.ListItem( |
213 |
|
label="Søg Serier ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png') |
214 |
|
listitem.setProperty('Fanart_Image', fanartImage) |
215 |
|
|
216 |
|
u = sys.argv[0] + "?mode=11&name=" |
217 |
|
xbmcplugin.addDirectoryItem( |
218 |
|
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True) |
219 |
|
|
220 |
|
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
221 |
|
|
222 |
|
|
223 |
|
def buildList(url, title, endlist=True): |
224 |
|
print '[TODIC]:' + str(url) |
225 |
|
|
226 |
|
link = open_url(url) |
227 |
|
doc = parseString(link) |
228 |
|
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
229 |
|
print '[TODIC]' + str(ty) |
230 |
|
|
231 |
|
if ty == 'clipList': |
232 |
|
mode = '50' |
233 |
|
folder = False |
234 |
|
else: |
235 |
|
mode = '1' |
236 |
|
folder = True |
237 |
|
|
238 |
|
entries = doc.getElementsByTagName("entry") |
239 |
|
l = len(entries) |
240 |
|
description = '' |
241 |
|
for entry in entries: |
242 |
|
name = getText(entry.getElementsByTagName("title")) |
243 |
|
url = getText(entry.getElementsByTagName("url")) |
244 |
|
thumb = getText(entry.getElementsByTagName("cover")) |
245 |
|
description = getText(entry.getElementsByTagName("description")) |
246 |
|
playcount = getText(entry.getElementsByTagName("playcount")) |
247 |
|
|
248 |
|
|
249 |
|
if playcount == '': |
250 |
|
playcount = '0' |
251 |
|
playcount = int(playcount) |
252 |
|
|
253 |
## print "name:" + name |
# print "name:" + name |
254 |
# print "url:" + url |
# print "url:" + url |
255 |
# print "thumb:" + thumb |
# print "thumb:" + thumb |
256 |
# print "description:" + description |
# print "description:" + description |
257 |
|
listitem = xbmcgui.ListItem( |
258 |
|
label=name, label2='test', iconImage='DefaultFolder.png', thumbnailImage=thumb) |
259 |
|
listitem.setProperty('Fanart_Image', fanartImage) |
260 |
|
if mode == '50': |
261 |
|
infoLabels = {} |
262 |
|
infoLabels['title'] = name |
263 |
|
infoLabels['plot'] = description |
264 |
|
infoLabels['playcount'] = playcount |
265 |
|
listitem.setInfo('video', infoLabels) |
266 |
|
|
267 |
|
name = name.encode('UTF-8') |
268 |
|
description = description.encode('UTF-8') |
269 |
|
|
270 |
|
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote( |
271 |
|
name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description) |
272 |
|
xbmcplugin.addDirectoryItem( |
273 |
|
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=folder, totalItems=l) |
274 |
|
|
275 |
|
if (endlist == True): |
276 |
|
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
277 |
|
|
278 |
|
|
279 |
|
def play_video(url, name, description): |
280 |
|
param1 = parse_parameter_string(url) |
281 |
|
clipkey = param1["clipkey"] |
282 |
|
|
283 |
|
print "[Todic] ClipKey:" + clipkey |
284 |
|
detailurl = __backend__ + "&action=clipdetails&clipkey=" + clipkey |
285 |
|
print "[Todic] detailURL = " + detailurl |
286 |
|
|
287 |
|
xml = open_url(detailurl) |
288 |
|
|
289 |
|
clipDetailsDoc = parseString(xml) |
290 |
|
savedPosition = int( getText(clipDetailsDoc.getElementsByTagName("position")) ) |
291 |
|
playPosition = 0 |
292 |
|
|
293 |
|
if (description == None or description == ""): |
294 |
|
if (savedPosition > 0): |
295 |
|
dialog = xbmcgui.Dialog() |
296 |
|
#yes / true -afspil fra position |
297 |
|
answer = dialog.yesno(heading='Todic', line1='Afspil fra gemt', nolabel='Fra start', yeslabel='Fortsæt') |
298 |
|
if (answer == True): |
299 |
|
playPosition = savedPosition |
300 |
|
|
301 |
|
play_real_video(url, name, playPosition) |
302 |
|
|
303 |
|
else: |
304 |
|
d = TodicMovieDialog() |
305 |
|
d.setDetailsDoc(clipDetailsDoc) |
306 |
|
d.setName(name) |
307 |
|
d.setDescription(description) |
308 |
|
|
309 |
|
d.doModal() |
310 |
|
|
311 |
|
|
312 |
|
def play_real_video(url, name, position): |
313 |
|
xml = open_url(url) |
314 |
|
print '[Todic] url: ' + str(url) |
315 |
|
print '[Todic] xml: ' + xml |
316 |
|
print '[Todic] pos: ' + str(position) |
317 |
|
|
318 |
|
doc = parseString(xml) |
319 |
|
url = getText(doc.getElementsByTagName("url")) |
320 |
|
|
321 |
|
subtitleurl = getText(doc.getElementsByTagName("subtitles")) |
322 |
|
subtitlesfile = os.path.join(datapath, 'temp.srt') |
323 |
|
|
324 |
|
# if old srt file exists delete it first |
325 |
|
if os.path.isfile(subtitlesfile): |
326 |
|
os.unlink(subtitlesfile) |
327 |
|
|
328 |
|
print '[TODIC] subs: ' + str(subtitleurl) |
329 |
|
if len(subtitleurl) > 0: |
330 |
|
subtitles = open_url(subtitleurl) |
331 |
|
SaveFile(subtitlesfile, subtitles) |
332 |
|
print 'TODIC downloaded subtitles' |
333 |
|
|
334 |
|
image = xbmc.getInfoImage('ListItem.Thumb') |
335 |
|
listitem = xbmcgui.ListItem( |
336 |
|
label=name, iconImage='DefaultVideo.png', thumbnailImage=image) |
337 |
|
listitem.setInfo(type="Video", infoLabels={"Title": name}) |
338 |
|
listitem.setProperty('ResumeTime', '300') |
339 |
|
listitem.setProperty('TotalTime', '3000') |
340 |
|
|
341 |
|
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
342 |
|
player.play(str(url), listitem) |
343 |
|
|
344 |
|
# kan ikke loade subtitles hvis foerend playeren koerer |
345 |
|
count = 0 |
346 |
|
while not xbmc.Player().isPlaying(): |
347 |
|
xbmc.sleep(250) |
348 |
|
count += 1 |
349 |
|
if count > 10: |
350 |
|
break |
351 |
|
|
352 |
|
|
353 |
|
|
354 |
|
if xbmc.Player().isPlaying(): |
355 |
|
if os.path.isfile(subtitlesfile): |
356 |
|
player.setSubtitles(subtitlesfile) |
357 |
|
print 'TODIC started subtitles' |
358 |
|
else: |
359 |
|
player.disableSubtitles() |
360 |
|
|
361 |
|
|
362 |
listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
if (position > 0): |
363 |
listitem.setProperty('Fanart_Image', fanartImage) |
while (player.getTotalTime() == 0.0): #Vent indtil vi har beregnet hvor langt klippet er |
364 |
if mode == '50': |
xbmc.sleep(250) |
|
infoLabels = {} |
|
|
infoLabels['title'] = name |
|
|
infoLabels['plot'] = description |
|
|
infoLabels['playcount'] = playcount |
|
|
listitem.setInfo('video', infoLabels) |
|
|
|
|
|
name = name.encode('UTF-8') |
|
|
description = description.encode('UTF-8') |
|
|
|
|
|
|
|
|
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description) |
|
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l) |
|
|
|
|
|
if (endlist == True): |
|
|
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def play_video(url, name,description): |
|
|
if (description == None or description == ""): |
|
|
play_real_video(url,name) |
|
|
else: |
|
|
d = TodicMovieDialog() |
|
|
d.setUrl( url) |
|
|
d.setName( name ) |
|
|
d.setDescription( description ) |
|
|
|
|
|
d.doModal() |
|
|
|
|
|
|
|
|
def play_real_video(url, name): |
|
|
xml = open_url(url) |
|
|
print 'TODIC url: ' + str(url) |
|
|
print 'TODIC xml: '+ xml |
|
|
|
|
|
doc = parseString(xml) |
|
|
url = getText( doc.getElementsByTagName("url") ) |
|
|
|
|
|
subtitleurl = getText( doc.getElementsByTagName("subtitles") ) |
|
|
subtitlesfile = os.path.join(datapath,'temp.srt') |
|
|
|
|
|
#if old srt file exists delete it first |
|
|
if os.path.isfile(subtitlesfile): |
|
|
os.unlink(subtitlesfile) |
|
|
|
|
|
print '[TODIC] subs: '+str(subtitleurl) |
|
|
if len(subtitleurl) > 0: |
|
|
subtitles = open_url(subtitleurl) |
|
|
SaveFile(subtitlesfile, subtitles) |
|
|
print 'TODIC downloaded subtitles' |
|
|
|
|
|
|
|
|
|
|
|
image = xbmc.getInfoImage( 'ListItem.Thumb' ) |
|
|
listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image) |
|
|
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
|
|
|
|
|
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
|
|
player.play(str(url), listitem) |
|
|
|
|
|
#kan ikke loade subtitles hvis foerend playeren koerer |
|
|
count = 0 |
|
|
while not xbmc.Player().isPlaying(): |
|
|
xbmc.sleep(500) |
|
|
count += 1 |
|
|
if count > 10: |
|
|
break |
|
365 |
|
|
366 |
|
print "[Todic] totalTime " + str( player.getTotalTime() ) |
367 |
|
player.seekTime(position) |
368 |
|
|
|
if xbmc.Player().isPlaying(): |
|
|
if os.path.isfile(subtitlesfile): |
|
|
player.setSubtitles(subtitlesfile) |
|
|
print 'TODIC started subtitles' |
|
|
else: |
|
|
player.disableSubtitles() |
|
369 |
|
|
370 |
# player.callbackLoop() |
#Holder python kørernde indtil at det bliver bedt om at stoppe |
371 |
|
while (not xbmc.abortRequested): |
372 |
|
player.tick() |
373 |
|
xbmc.sleep(500) |
374 |
|
|
375 |
|
|
376 |
|
|
377 |
def search(): |
def search(): |
378 |
search = getUserInput("Todic Søgning") |
search = getUserInput("Todic Søgning") |
379 |
|
|
380 |
if (search != None and search != ""): |
if (search != None and search != ""): |
381 |
url = __backend__ + "&action=search&search=" + urllib.quote_plus(search) |
url = __backend__ + "&action=search&search=" + \ |
382 |
|
urllib.quote_plus(search) |
383 |
|
|
384 |
#print "[TODIC] Search start: " + search |
# print "[TODIC] Search start: " + search |
385 |
#print "[TODIC] Search url: " + url |
# print "[TODIC] Search url: " + url |
386 |
|
|
387 |
buildList(url, "søgning") |
buildList(url, "søgning") |
388 |
|
|
|
def searchSeries(): |
|
|
search = getUserInput("Todic Serie Søgning") |
|
389 |
|
|
390 |
if (search != None and search != ""): |
def searchSeries(): |
391 |
url = __backend__ + "&action=searchseries&search=" + urllib.quote_plus(search) |
search = getUserInput("Todic Serie Søgning") |
392 |
|
|
393 |
#print "[TODIC] Search start: " + search |
if (search != None and search != ""): |
394 |
#print "[TODIC] Search url: " + url |
url = __backend__ + "&action=searchseries&search=" + \ |
395 |
|
urllib.quote_plus(search) |
396 |
|
|
397 |
buildList(url, "serie søgning") |
# print "[TODIC] Search start: " + search |
398 |
|
# print "[TODIC] Search url: " + url |
399 |
|
|
400 |
|
buildList(url, "serie søgning") |
401 |
|
|
402 |
|
|
403 |
|
#=================================== Tool Box ======================================= |
|
#=================================== Tool Box ======================================= |
|
404 |
# shows a more userfriendly notification |
# shows a more userfriendly notification |
405 |
def showMessage(heading, message): |
def showMessage(heading, message): |
406 |
duration = 15*1000 |
duration = 15 * 1000 |
407 |
xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) ) |
xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % |
408 |
|
(heading, message, duration)) |
409 |
|
|
410 |
|
|
411 |
# raise a keyboard for user input |
# raise a keyboard for user input |
412 |
def getUserInput(title = "Input", default="", hidden=False): |
def getUserInput(title="Input", default="", hidden=False): |
413 |
result = None |
result = None |
414 |
|
|
415 |
# Fix for when this functions is called with default=None |
# Fix for when this functions is called with default=None |
416 |
if not default: |
if not default: |
417 |
default = "" |
default = "" |
418 |
|
|
419 |
keyboard = xbmc.Keyboard(default, title) |
keyboard = xbmc.Keyboard(default, title) |
420 |
keyboard.setHiddenInput(hidden) |
keyboard.setHiddenInput(hidden) |
421 |
keyboard.doModal() |
keyboard.doModal() |
422 |
|
|
423 |
if keyboard.isConfirmed(): |
if keyboard.isConfirmed(): |
424 |
result = keyboard.getText() |
result = keyboard.getText() |
425 |
|
|
426 |
return result |
return result |
427 |
|
|
428 |
|
|
429 |
def get_params(): |
def get_params(): |
430 |
param=[] |
return parse_parameter_string(sys.argv[2]) |
431 |
paramstring=sys.argv[2] |
|
432 |
if len(paramstring)>=2: |
|
433 |
params=sys.argv[2] |
def parse_parameter_string(paramstring): |
434 |
cleanedparams=params.replace('?','') |
param = [] |
435 |
if (params[len(params)-1]=='/'): |
if len(paramstring) >= 2: |
436 |
params=params[0:len(params)-2] |
params = paramstring |
437 |
pairsofparams=cleanedparams.split('&') |
cleanedparams = params.replace('?', '') |
438 |
param={} |
if (params[len(params) - 1] == '/'): |
439 |
for i in range(len(pairsofparams)): |
params = params[0:len(params) - 2] |
440 |
splitparams={} |
pairsofparams = cleanedparams.split('&') |
441 |
splitparams=pairsofparams[i].split('=') |
param = {} |
442 |
if (len(splitparams))==2: |
for i in range(len(pairsofparams)): |
443 |
param[splitparams[0]]=splitparams[1] |
splitparams = {} |
444 |
return param |
splitparams = pairsofparams[i].split('=') |
445 |
|
if (len(splitparams)) == 2: |
446 |
|
param[splitparams[0]] = splitparams[1] |
447 |
|
return param |
448 |
|
|
449 |
|
|
450 |
params = get_params() |
params = get_params() |
453 |
mode = None |
mode = None |
454 |
description = None |
description = None |
455 |
|
|
456 |
|
|
457 |
|
#print params |
458 |
|
|
459 |
try: |
try: |
460 |
url = urllib.unquote_plus(params["url"]) |
url = urllib.unquote_plus(params["url"]) |
461 |
except: |
except: |
462 |
pass |
pass |
463 |
try: |
try: |
464 |
name = urllib.unquote_plus(params["name"]) |
name = urllib.unquote_plus(params["name"]) |
465 |
except: |
except: |
466 |
pass |
pass |
467 |
try: |
try: |
468 |
mode = int(params["mode"]) |
mode = int(params["mode"]) |
469 |
except: |
except: |
470 |
pass |
pass |
471 |
try: |
try: |
472 |
description = urllib.unquote_plus(params["description"]) |
description = urllib.unquote_plus(params["description"]) |
473 |
except: |
except: |
474 |
pass |
pass |
475 |
|
|
476 |
|
|
477 |
|
|
478 |
|
|
479 |
try: |
try: |
480 |
open_url("http://todic.dk") |
open_url("http://todic.dk") |
481 |
except: |
except: |
482 |
showMessage("Fejl", "Kunne ikke forbinde til todic.dk") |
showMessage("Fejl", "Kunne ikke forbinde til todic.dk") |
483 |
exit() |
exit() |
484 |
|
|
485 |
|
|
486 |
if url == 'refresh': |
if url == 'refresh': |
487 |
#xbmc.output("[tvserver] Container.Refresh") #20130418 xbmc.output virker ikke med XBMC12 |
# xbmc.output("[tvserver] Container.Refresh") #20130418 xbmc.output virker |
488 |
xbmc.executebuiltin("Container.Refresh") |
# ikke med XBMC12 |
489 |
|
xbmc.executebuiltin("Container.Refresh") |
490 |
|
|
491 |
|
|
492 |
elif mode == None: |
elif mode == None: |
493 |
#build main menu |
# build main menu |
494 |
rootMenu() |
rootMenu() |
495 |
|
|
496 |
elif mode == 1: |
elif mode == 1: |
497 |
#build list of movie starting letters |
# build list of movie starting letters |
498 |
buildList(url, name) |
buildList(url, name) |
499 |
|
|
500 |
elif mode == 10: |
elif mode == 10: |
501 |
search() |
search() |
502 |
|
|
503 |
elif mode == 11: |
elif mode == 11: |
504 |
searchSeries() |
searchSeries() |
|
|
|
|
|
|
|
elif mode == 50: |
|
|
play_video(url, name, description) |
|
|
|
|
|
|
|
505 |
|
|
506 |
|
|
507 |
|
elif mode == 50: |
508 |
|
play_video(url, name, description) |