1 |
|
# This Python file uses the following encoding: utf-8 |
2 |
|
|
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 |
21 |
__addon__ = xbmcaddon.Addon(id='plugin.video.todic') |
__addon__ = xbmcaddon.Addon(id='plugin.video.todic') |
22 |
__key__ = __addon__.getSetting('xbmckey').lower() |
__key__ = __addon__.getSetting('xbmckey').lower() |
23 |
__backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__ |
__backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__ |
24 |
|
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'fanart.jpg') |
25 |
|
|
26 |
|
|
27 |
|
class TodicPlayer(xbmc.Player): |
28 |
|
def __init__(self, *args, **kwargs): |
29 |
|
#xbmc.Player.__init__(selv,*args,**kwargs) |
30 |
|
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER ) |
31 |
|
self.stopped = False |
32 |
|
self.started = False |
33 |
|
print "[TodicPlayer] init" |
34 |
|
|
35 |
|
# @catchall |
36 |
|
def onPlayBackStarted(self): |
37 |
|
self.started = True |
38 |
|
print "[TodicPlayer] : started" |
39 |
|
# super.onPlayBackStarted() |
40 |
|
|
41 |
|
def onPlayBackStopped(self): |
42 |
|
self.stopped = True |
43 |
|
print "[TodicPlayer] : stopped" |
44 |
|
|
45 |
|
def onPlayBackEnded(self): |
46 |
|
self.stopped = True |
47 |
|
print "[TodicPlayer] : ended" |
48 |
|
|
49 |
|
def callbackLoop(self): |
50 |
|
print "[Todic] startLoop" |
51 |
|
while (self.stopped == False): |
52 |
|
if (self.started == True ): |
53 |
|
print "[todic] " + str(self.getTime()) |
54 |
|
xbmc.sleep(5000) |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
def open_url(url): |
def open_url(url): |
60 |
req = urllib2.Request(url) |
req = urllib2.Request(url) |
64 |
return data |
return data |
65 |
|
|
66 |
def rootMenu(): |
def rootMenu(): |
67 |
link = open_url(__backend__) |
|
68 |
m=re.compile('<title>(.+?)</title><url>(.+?)</url>').findall(link) |
buildList(__backend__, "", False) # call default list |
69 |
l = len(m) |
|
70 |
for name,url in m: |
# Adde xtra items to root menu |
71 |
listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
listitem = xbmcgui.ListItem(label = "Søg film ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
72 |
u = sys.argv[0] + "?mode=1&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
listitem.setProperty('Fanart_Image', fanartImage) |
73 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True, totalItems = l) |
|
74 |
|
u = sys.argv[0] + "?mode=10&name=" |
75 |
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) |
76 |
|
|
77 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
78 |
|
|
79 |
|
|
80 |
def buildList(url,title): |
def buildList(url,title, endlist=True): |
81 |
print '[TODIC]:'+str(url) |
print '[TODIC]:'+str(url) |
82 |
link = open_url(url) |
link = open_url(url) |
83 |
ty=re.compile('<meta type=\'(.+?)\'').findall(link) |
ty=re.compile('<meta type=\'(.+?)\'').findall(link) |
84 |
print '[TOD]'+str(ty[0]) |
print '[TODIC]'+str(ty[0]) |
85 |
m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover>').findall(link) |
|
86 |
|
if ty[0] == 'clipList': |
87 |
|
mode = '50' |
88 |
|
folder = False |
89 |
|
else: |
90 |
|
mode = '1' |
91 |
|
folder = True |
92 |
|
|
93 |
|
m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover><description>(.*)</description>').findall(link) |
94 |
l=len(m) |
l=len(m) |
95 |
for name,url,thumb in m: |
for name,url,thumb,description in m: |
96 |
if ty[0] == 'clipList': |
|
97 |
mode = '50' |
listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
98 |
folder = False |
listitem.setProperty('Fanart_Image', fanartImage) |
99 |
else: |
if mode == '50': |
100 |
mode = '2' |
infoLabels = {} |
101 |
folder = True |
infoLabels['title'] = name |
102 |
|
infoLabels['plot'] = description |
103 |
listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
listitem.setInfo('video', infoLabels) |
104 |
|
|
105 |
u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
106 |
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) |
|
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
|
107 |
|
|
108 |
def buildSubList(url,title): |
if (endlist == True): |
109 |
print '[TODIC]:'+str(url) |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
110 |
link = open_url(url) |
|
|
m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover>').findall(link) |
|
|
l = len(m) |
|
|
for name,url,thumb in m: |
|
|
listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
|
|
u = sys.argv[0] + "?mode=50&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
|
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = False, totalItems = l) |
|
|
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
|
111 |
|
|
112 |
|
|
113 |
|
|
120 |
listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image) |
listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image) |
121 |
# listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = 'DefaultVideo.png') |
# listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = 'DefaultVideo.png') |
122 |
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
123 |
xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(str(url), listitem) |
# xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(str(url), listitem) |
124 |
xbmc.sleep(200) |
|
125 |
|
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
126 |
|
player.play(str(url), listitem) |
127 |
|
player.callbackLoop() |
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
def search(): |
132 |
|
search = getUserInput("Todic Søgning") |
133 |
|
|
134 |
|
if (search != None and search != ""): |
135 |
|
url = __backend__ + "&action=search&search=" + urllib.quote_plus(search) |
136 |
|
|
137 |
|
#print "[TODIC] Search start: " + search |
138 |
|
#print "[TODIC] Search url: " + url |
139 |
|
|
140 |
|
buildList(url, "søgning") |
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
#=================================== Tool Box ======================================= |
147 |
|
# shows a more userfriendly notification |
148 |
|
def showMessage(heading, message): |
149 |
|
duration = 15*1000 |
150 |
|
xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) ) |
151 |
|
|
152 |
|
|
153 |
|
# raise a keyboard for user input |
154 |
|
def getUserInput(title = "Input", default="", hidden=False): |
155 |
|
result = None |
156 |
|
|
157 |
|
# Fix for when this functions is called with default=None |
158 |
|
if not default: |
159 |
|
default = "" |
160 |
|
|
161 |
|
keyboard = xbmc.Keyboard(default, title) |
162 |
|
keyboard.setHiddenInput(hidden) |
163 |
|
keyboard.doModal() |
164 |
|
|
165 |
|
if keyboard.isConfirmed(): |
166 |
|
result = keyboard.getText() |
167 |
|
|
168 |
|
return result |
169 |
|
|
170 |
|
|
171 |
def get_params(): |
def get_params(): |
217 |
#build list of movie starting letters |
#build list of movie starting letters |
218 |
buildList(url, name) |
buildList(url, name) |
219 |
|
|
220 |
elif mode == 2: |
elif mode == 10: |
221 |
#build list of series |
search() |
222 |
buildSubList(url, name) |
|
223 |
|
|
224 |
elif mode == 50: |
elif mode == 50: |
225 |
play_video(url, name) |
play_video(url, name) |
226 |
|
|
227 |
|
|
228 |
|
|
229 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
# xbmcplugin.endOfDirectory(int(sys.argv[1])) |
230 |
|
|