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.2 |
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 |
|
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') |
27 |
|
|
28 |
|
|
29 |
|
class TodicPlayer(xbmc.Player): |
30 |
|
def __init__(self, *args, **kwargs): |
31 |
|
#xbmc.Player.__init__(selv,*args,**kwargs) |
32 |
|
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER ) |
33 |
|
self.stopped = False |
34 |
|
self.started = False |
35 |
|
print "[TodicPlayer] init" |
36 |
|
|
37 |
|
# @catchall |
38 |
|
def onPlayBackStarted(self): |
39 |
|
self.started = True |
40 |
|
print "[TodicPlayer] : started" |
41 |
|
# super.onPlayBackStarted() |
42 |
|
|
43 |
|
def onPlayBackStopped(self): |
44 |
|
self.stopped = True |
45 |
|
print "[TodicPlayer] : stopped" |
46 |
|
|
47 |
|
def onPlayBackEnded(self): |
48 |
|
self.stopped = True |
49 |
|
print "[TodicPlayer] : ended" |
50 |
|
|
51 |
|
def callbackLoop(self): |
52 |
|
print "[Todic] startLoop" |
53 |
|
while (self.stopped == False): |
54 |
|
if (self.started == True ): |
55 |
|
print "[todic] " + str(self.getTime()) |
56 |
|
xbmc.sleep(5000) |
57 |
|
|
58 |
|
|
59 |
|
def getText2(nodelist): |
60 |
|
rc = [] |
61 |
|
for node in nodelist: |
62 |
|
if node.nodeType == node.TEXT_NODE: |
63 |
|
rc.append(node.data) |
64 |
|
else: |
65 |
|
rc.append( getText(node.childNodes) ) |
66 |
|
return ''.join(rc) |
67 |
|
|
68 |
|
def getText(nodelist): |
69 |
|
if nodelist.length == 0: |
70 |
|
return '' |
71 |
|
else: |
72 |
|
if nodelist[0].childNodes.length == 0: |
73 |
|
return '' |
74 |
|
else: |
75 |
|
return nodelist[0].childNodes[0].nodeValue |
76 |
|
|
77 |
|
|
78 |
def open_url(url): |
def open_url(url): |
79 |
req = urllib2.Request(url) |
req = urllib2.Request(url) |
83 |
return data |
return data |
84 |
|
|
85 |
def rootMenu(): |
def rootMenu(): |
86 |
link = open_url(__backend__) |
|
87 |
m=re.compile('<title>(.+?)</title><url>(.+?)</url>').findall(link) |
buildList(__backend__, "", False) # call default list |
88 |
for name,url in m: |
|
89 |
listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
# Adde xtra items to root menu |
90 |
u = sys.argv[0] + "?mode=1&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
listitem = xbmcgui.ListItem(label = "Søg film ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
91 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) |
listitem.setProperty('Fanart_Image', fanartImage) |
92 |
|
|
93 |
|
u = sys.argv[0] + "?mode=10&name=" |
94 |
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) |
95 |
|
|
96 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
97 |
|
|
98 |
|
|
99 |
def buildList(url,title): |
def buildList(url,title, endlist=True): |
100 |
print '[TODIC]:'+str(url) |
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) |
|
|
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) |
|
|
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
|
101 |
|
|
|
def buildSubList(url,title): |
|
|
print '[TODIC]:'+str(url) |
|
102 |
link = open_url(url) |
link = open_url(url) |
103 |
m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover>').findall(link) |
doc = parseString(link) |
104 |
for name,url,thumb in m: |
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
105 |
listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
print '[TODIC]'+str(ty) |
106 |
u = sys.argv[0] + "?mode=50&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
|
107 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = False) |
if ty == 'clipList': |
108 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
mode = '50' |
109 |
|
folder = False |
110 |
|
else: |
111 |
|
mode = '1' |
112 |
|
folder = True |
113 |
|
|
114 |
|
entries = doc.getElementsByTagName("entry") |
115 |
|
l=len(entries) |
116 |
|
description = '' |
117 |
|
for entry in entries: |
118 |
|
name = getText( entry.getElementsByTagName("title") ) |
119 |
|
url = getText( entry.getElementsByTagName("url") ) |
120 |
|
thumb = getText( entry.getElementsByTagName("cover") ) |
121 |
|
description = getText( entry.getElementsByTagName("description") ) |
122 |
|
|
123 |
|
name = name.encode('latin-1') |
124 |
|
description = description.encode('latin-1') |
125 |
|
|
126 |
|
## print "name:" + name |
127 |
|
# print "url:" + url |
128 |
|
# print "thumb:" + thumb |
129 |
|
# print "description:" + description |
130 |
|
|
131 |
|
|
132 |
|
listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
133 |
|
listitem.setProperty('Fanart_Image', fanartImage) |
134 |
|
if mode == '50': |
135 |
|
infoLabels = {} |
136 |
|
infoLabels['title'] = name |
137 |
|
infoLabels['plot'] = description |
138 |
|
listitem.setInfo('video', infoLabels) |
139 |
|
|
140 |
|
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(name) + "&url=" + urllib.quote(url) |
141 |
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l) |
142 |
|
|
143 |
|
if (endlist == True): |
144 |
|
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
def play_video(url, name): |
def play_video(url, name): |
150 |
link = open_url(url) |
xml = open_url(url) |
151 |
match=re.compile('<url>(.+?)</url>').findall(link) |
|
152 |
url = match[0] |
doc = parseString(xml) |
153 |
|
url = getText( doc.getElementsByTagName("url") ) |
154 |
|
|
155 |
print '[TODIC]:'+str(url) |
print '[TODIC]:'+str(url) |
156 |
image = xbmc.getInfoImage( 'ListItem.Thumb' ) |
image = xbmc.getInfoImage( 'ListItem.Thumb' ) |
157 |
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') |
|
158 |
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
159 |
xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(str(url), listitem) |
|
160 |
xbmc.sleep(200) |
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
161 |
|
player.play(str(url), listitem) |
162 |
|
# player.callbackLoop() |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
def search(): |
167 |
|
search = getUserInput("Todic Søgning") |
168 |
|
|
169 |
|
if (search != None and search != ""): |
170 |
|
url = __backend__ + "&action=search&search=" + urllib.quote_plus(search) |
171 |
|
|
172 |
|
#print "[TODIC] Search start: " + search |
173 |
|
#print "[TODIC] Search url: " + url |
174 |
|
|
175 |
|
buildList(url, "søgning") |
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
#=================================== Tool Box ======================================= |
182 |
|
# shows a more userfriendly notification |
183 |
|
def showMessage(heading, message): |
184 |
|
duration = 15*1000 |
185 |
|
xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) ) |
186 |
|
|
187 |
|
|
188 |
|
# raise a keyboard for user input |
189 |
|
def getUserInput(title = "Input", default="", hidden=False): |
190 |
|
result = None |
191 |
|
|
192 |
|
# Fix for when this functions is called with default=None |
193 |
|
if not default: |
194 |
|
default = "" |
195 |
|
|
196 |
|
keyboard = xbmc.Keyboard(default, title) |
197 |
|
keyboard.setHiddenInput(hidden) |
198 |
|
keyboard.doModal() |
199 |
|
|
200 |
|
if keyboard.isConfirmed(): |
201 |
|
result = keyboard.getText() |
202 |
|
|
203 |
|
return result |
204 |
|
|
205 |
|
|
206 |
def get_params(): |
def get_params(): |
252 |
#build list of movie starting letters |
#build list of movie starting letters |
253 |
buildList(url, name) |
buildList(url, name) |
254 |
|
|
255 |
elif mode == 2: |
elif mode == 10: |
256 |
#build list of series |
search() |
257 |
buildSubList(url, name) |
|
258 |
|
|
259 |
elif mode == 50: |
elif mode == 50: |
260 |
play_video(url, name) |
play_video(url, name) |
261 |
|
|
262 |
|
|
263 |
|
|
|
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
|
264 |
|
|