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.9 |
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 |
|
|
30 |
|
class TodicPlayer(xbmc.Player): |
31 |
|
def __init__(self, *args, **kwargs): |
32 |
|
#xbmc.Player.__init__(selv,*args,**kwargs) |
33 |
|
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER ) |
34 |
|
self.stopped = False |
35 |
|
self.started = False |
36 |
|
print "[TodicPlayer] init" |
37 |
|
|
38 |
|
# @catchall |
39 |
|
def onPlayBackStarted(self): |
40 |
|
self.started = True |
41 |
|
print "[TodicPlayer] : started" |
42 |
|
# super.onPlayBackStarted() |
43 |
|
|
44 |
|
def onPlayBackStopped(self): |
45 |
|
self.stopped = True |
46 |
|
print "[TodicPlayer] : stopped" |
47 |
|
|
48 |
|
def onPlayBackEnded(self): |
49 |
|
self.stopped = True |
50 |
|
print "[TodicPlayer] : ended" |
51 |
|
|
52 |
|
def callbackLoop(self): |
53 |
|
print "[Todic] startLoop" |
54 |
|
while (self.stopped == False): |
55 |
|
if (self.started == True ): |
56 |
|
print "[todic] " + str(self.getTime()) |
57 |
|
xbmc.sleep(5000) |
58 |
|
|
59 |
|
|
60 |
|
def getText2(nodelist): |
61 |
|
rc = [] |
62 |
|
for node in nodelist: |
63 |
|
if node.nodeType == node.TEXT_NODE: |
64 |
|
rc.append(node.data) |
65 |
|
else: |
66 |
|
rc.append( getText(node.childNodes) ) |
67 |
|
return ''.join(rc) |
68 |
|
|
69 |
|
def getText(nodelist): |
70 |
|
if nodelist.length == 0: |
71 |
|
return '' |
72 |
|
else: |
73 |
|
if nodelist[0].childNodes.length == 0: |
74 |
|
return '' |
75 |
|
else: |
76 |
|
return nodelist[0].childNodes[0].nodeValue |
77 |
|
|
78 |
|
def SaveFile(path, data): |
79 |
|
file = open(path,'w') |
80 |
|
file.write(data) |
81 |
|
file.close() |
82 |
|
|
83 |
|
|
84 |
def open_url(url): |
def open_url(url): |
85 |
req = urllib2.Request(url) |
req = urllib2.Request(url) |
90 |
|
|
91 |
def rootMenu(): |
def rootMenu(): |
92 |
|
|
93 |
buildList(__backend__, "") # call default list |
msg = open_url(__backend__ + "&action=messages") |
94 |
|
msg = msg.strip() |
95 |
|
|
96 |
|
if msg != "": |
97 |
|
dialog = xbmcgui.Dialog() |
98 |
|
dialog.ok('XBMC Todic', msg) |
99 |
|
|
100 |
|
buildList(__backend__, "", False) # call default list |
101 |
|
|
102 |
# Adde xtra items to root menu |
# Adde xtra items to root menu |
103 |
listitem = xbmcgui.ListItem(label = "Søg film ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
listitem = xbmcgui.ListItem(label = "Søg film ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
106 |
u = sys.argv[0] + "?mode=10&name=" |
u = sys.argv[0] + "?mode=10&name=" |
107 |
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) |
108 |
|
|
109 |
|
#add search series |
110 |
|
listitem = xbmcgui.ListItem(label = "Søg Serier ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
111 |
|
listitem.setProperty('Fanart_Image', fanartImage) |
112 |
|
|
113 |
|
u = sys.argv[0] + "?mode=11&name=" |
114 |
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) |
115 |
|
|
116 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
117 |
|
|
118 |
|
|
119 |
def buildList(url,title): |
def buildList(url,title, endlist=True): |
120 |
print '[TODIC]:'+str(url) |
print '[TODIC]:'+str(url) |
121 |
|
|
122 |
link = open_url(url) |
link = open_url(url) |
123 |
ty=re.compile('<meta type=\'(.+?)\'').findall(link) |
doc = parseString(link) |
124 |
print '[TODIC]'+str(ty[0]) |
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
125 |
|
print '[TODIC]'+str(ty) |
126 |
|
|
127 |
if ty[0] == 'clipList': |
if ty == 'clipList': |
128 |
mode = '50' |
mode = '50' |
129 |
folder = False |
folder = False |
130 |
else: |
else: |
131 |
mode = '1' |
mode = '1' |
132 |
folder = True |
folder = True |
133 |
|
|
134 |
m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover><description>(.*)</description>').findall(link) |
|
135 |
l=len(m) |
entries = doc.getElementsByTagName("entry") |
136 |
for name,url,thumb,description in m: |
l=len(entries) |
137 |
|
description = '' |
138 |
|
for entry in entries: |
139 |
|
name = getText( entry.getElementsByTagName("title") ) |
140 |
|
url = getText( entry.getElementsByTagName("url") ) |
141 |
|
thumb = getText( entry.getElementsByTagName("cover") ) |
142 |
|
description = getText( entry.getElementsByTagName("description") ) |
143 |
|
playcount = getText( entry.getElementsByTagName("playcount") ) |
144 |
|
|
145 |
|
if playcount == '': |
146 |
|
playcount = '0' |
147 |
|
playcount = int(playcount) |
148 |
|
|
149 |
|
|
150 |
|
## print "name:" + name |
151 |
|
# print "url:" + url |
152 |
|
# print "thumb:" + thumb |
153 |
|
# print "description:" + description |
154 |
|
|
155 |
|
|
156 |
listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
157 |
listitem.setProperty('Fanart_Image', fanartImage) |
listitem.setProperty('Fanart_Image', fanartImage) |
158 |
if mode == '50': |
if mode == '50': |
159 |
infoLabels = {} |
infoLabels = {} |
160 |
infoLabels['title'] = name |
infoLabels['title'] = name |
161 |
infoLabels['plot'] = description |
infoLabels['plot'] = description |
162 |
|
infoLabels['playcount'] = playcount |
163 |
listitem.setInfo('video', infoLabels) |
listitem.setInfo('video', infoLabels) |
164 |
|
|
165 |
u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
name = name.encode('UTF-8') |
166 |
|
description = description.encode('UTF-8') |
167 |
|
|
168 |
|
|
169 |
|
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(name) + "&url=" + urllib.quote(url) |
170 |
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) |
171 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
|
172 |
|
if (endlist == True): |
173 |
|
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
def play_video(url, name): |
def play_video(url, name): |
179 |
link = open_url(url) |
xml = open_url(url) |
180 |
match=re.compile('<url>(.+?)</url>').findall(link) |
print 'TODIC url: ' + str(url) |
181 |
url = match[0] |
print 'TODIC xml: '+ xml |
182 |
print '[TODIC]:'+str(url) |
|
183 |
|
doc = parseString(xml) |
184 |
|
url = getText( doc.getElementsByTagName("url") ) |
185 |
|
|
186 |
|
subtitleurl = getText( doc.getElementsByTagName("subtitles") ) |
187 |
|
subtitlesfile = os.path.join(datapath,'temp.srt') |
188 |
|
|
189 |
|
#if old srt file exists delete it first |
190 |
|
if os.path.isfile(subtitlesfile): |
191 |
|
os.unlink(subtitlesfile) |
192 |
|
|
193 |
|
print '[TODIC] subs: '+str(subtitleurl) |
194 |
|
if len(subtitleurl) > 0: |
195 |
|
subtitles = open_url(subtitleurl) |
196 |
|
SaveFile(subtitlesfile, subtitles) |
197 |
|
print 'TODIC downloaded subtitles' |
198 |
|
|
199 |
|
|
200 |
|
|
201 |
image = xbmc.getInfoImage( 'ListItem.Thumb' ) |
image = xbmc.getInfoImage( 'ListItem.Thumb' ) |
202 |
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') |
|
203 |
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
204 |
xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(str(url), listitem) |
|
205 |
xbmc.sleep(200) |
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
206 |
|
player.play(str(url), listitem) |
207 |
|
|
208 |
|
#kan ikke loade subtitles hvis foerend playeren koerer |
209 |
|
count = 0 |
210 |
|
while not xbmc.Player().isPlaying(): |
211 |
|
xbmc.sleep(500) |
212 |
|
count += 1 |
213 |
|
if count > 10: |
214 |
|
break |
215 |
|
|
216 |
|
|
217 |
|
if xbmc.Player().isPlaying(): |
218 |
|
if os.path.isfile(subtitlesfile): |
219 |
|
player.setSubtitles(subtitlesfile) |
220 |
|
print 'TODIC started subtitles' |
221 |
|
else: |
222 |
|
player.disableSubtitles() |
223 |
|
|
224 |
|
# player.callbackLoop() |
225 |
|
|
226 |
|
|
227 |
|
|
228 |
def search(): |
def search(): |
229 |
search = getUserInput("Todic Søgning") |
search = getUserInput("Todic Søgning") |
236 |
|
|
237 |
buildList(url, "søgning") |
buildList(url, "søgning") |
238 |
|
|
239 |
|
def searchSeries(): |
240 |
|
search = getUserInput("Todic Serie Søgning") |
241 |
|
|
242 |
|
if (search != None and search != ""): |
243 |
|
url = __backend__ + "&action=searchseries&search=" + urllib.quote_plus(search) |
244 |
|
|
245 |
|
#print "[TODIC] Search start: " + search |
246 |
|
#print "[TODIC] Search url: " + url |
247 |
|
|
248 |
|
buildList(url, "serie søgning") |
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
|
293 |
param[splitparams[0]]=splitparams[1] |
param[splitparams[0]]=splitparams[1] |
294 |
return param |
return param |
295 |
|
|
|
params = get_params() |
|
|
url = None |
|
|
name = None |
|
|
mode = None |
|
296 |
|
|
297 |
params = get_params() |
params = get_params() |
298 |
url = None |
url = None |
312 |
except: |
except: |
313 |
pass |
pass |
314 |
|
|
315 |
|
if url == 'refresh': |
316 |
|
#xbmc.output("[tvserver] Container.Refresh") #20130418 xbmc.output virker ikke med XBMC12 |
317 |
|
xbmc.executebuiltin("Container.Refresh") |
318 |
|
|
319 |
|
|
320 |
if mode == None: |
elif mode == None: |
321 |
#build main menu |
#build main menu |
322 |
rootMenu() |
rootMenu() |
323 |
|
|
327 |
|
|
328 |
elif mode == 10: |
elif mode == 10: |
329 |
search() |
search() |
330 |
|
|
331 |
|
elif mode == 11: |
332 |
|
searchSeries() |
333 |
|
|
334 |
|
|
335 |
elif mode == 50: |
elif mode == 50: |
337 |
|
|
338 |
|
|
339 |
|
|
|
# xbmcplugin.endOfDirectory(int(sys.argv[1])) |
|
340 |
|
|