1 |
torben |
1629 |
''' |
2 |
|
|
Todic plugin for XBMC |
3 |
|
|
Version 0.0.2 |
4 |
|
|
''' |
5 |
|
|
|
6 |
|
|
import sys |
7 |
|
|
import cgi as urlparse |
8 |
torben |
1648 |
import os |
9 |
torben |
1629 |
|
10 |
torben |
1648 |
|
11 |
torben |
1629 |
import xbmc |
12 |
|
|
import xbmcaddon |
13 |
|
|
import xbmcgui |
14 |
|
|
import xbmcplugin |
15 |
|
|
import urllib |
16 |
|
|
import urllib2, re |
17 |
|
|
|
18 |
|
|
__addon__ = xbmcaddon.Addon(id='plugin.video.todic') |
19 |
|
|
__key__ = __addon__.getSetting('xbmckey').lower() |
20 |
|
|
__backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__ |
21 |
torben |
1648 |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'fanart.jpg') |
22 |
torben |
1629 |
|
23 |
|
|
def open_url(url): |
24 |
|
|
req = urllib2.Request(url) |
25 |
|
|
content = urllib2.urlopen(req) |
26 |
|
|
data = content.read() |
27 |
|
|
content.close() |
28 |
|
|
return data |
29 |
|
|
|
30 |
|
|
def rootMenu(): |
31 |
|
|
link = open_url(__backend__) |
32 |
|
|
m=re.compile('<title>(.+?)</title><url>(.+?)</url>').findall(link) |
33 |
torben |
1630 |
l = len(m) |
34 |
torben |
1629 |
for name,url in m: |
35 |
|
|
listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
36 |
torben |
1648 |
listitem.setProperty('Fanart_Image', fanartImage) |
37 |
|
|
|
38 |
torben |
1629 |
u = sys.argv[0] + "?mode=1&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
39 |
torben |
1630 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True, totalItems = l) |
40 |
torben |
1631 |
|
41 |
torben |
1640 |
listitem = xbmcgui.ListItem(label = "Søg film ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
42 |
torben |
1648 |
listitem.setProperty('Fanart_Image', fanartImage) |
43 |
|
|
|
44 |
torben |
1631 |
u = sys.argv[0] + "?mode=10&name=" + urllib.quote_plus(name) |
45 |
|
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True, totalItems = l) |
46 |
|
|
|
47 |
torben |
1629 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
48 |
|
|
|
49 |
|
|
|
50 |
|
|
def buildList(url,title): |
51 |
|
|
print '[TODIC]:'+str(url) |
52 |
|
|
link = open_url(url) |
53 |
|
|
ty=re.compile('<meta type=\'(.+?)\'').findall(link) |
54 |
torben |
1646 |
print '[TODIC]'+str(ty[0]) |
55 |
|
|
|
56 |
|
|
if ty[0] == 'clipList': |
57 |
|
|
mode = '50' |
58 |
|
|
folder = False |
59 |
|
|
else: |
60 |
|
|
mode = '1' |
61 |
|
|
folder = True |
62 |
|
|
|
63 |
torben |
1647 |
m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover><description>(.*)</description>').findall(link) |
64 |
torben |
1630 |
l=len(m) |
65 |
torben |
1647 |
for name,url,thumb,description in m: |
66 |
|
|
infoLabels = {} |
67 |
|
|
infoLabels['title'] = name |
68 |
|
|
infoLabels['plot'] = description |
69 |
|
|
|
70 |
|
|
listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
71 |
|
|
listitem.setInfo('video', infoLabels) |
72 |
torben |
1648 |
listitem.setProperty('Fanart_Image', fanartImage) |
73 |
|
|
|
74 |
torben |
1629 |
u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
75 |
torben |
1630 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l) |
76 |
torben |
1629 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
def play_video(url, name): |
82 |
|
|
link = open_url(url) |
83 |
|
|
match=re.compile('<url>(.+?)</url>').findall(link) |
84 |
|
|
url = match[0] |
85 |
|
|
print '[TODIC]:'+str(url) |
86 |
|
|
image = xbmc.getInfoImage( 'ListItem.Thumb' ) |
87 |
|
|
listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image) |
88 |
|
|
# listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = 'DefaultVideo.png') |
89 |
|
|
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
90 |
|
|
xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(str(url), listitem) |
91 |
|
|
xbmc.sleep(200) |
92 |
|
|
|
93 |
torben |
1631 |
def search(): |
94 |
|
|
search = getUserInput("Todic Søgning") |
95 |
torben |
1629 |
|
96 |
torben |
1634 |
if (search != None and search != ""): |
97 |
|
|
url = __backend__ + "&action=search&search=" + urllib.quote_plus(search) |
98 |
torben |
1631 |
|
99 |
torben |
1634 |
#print "[TODIC] Search start: " + search |
100 |
|
|
#print "[TODIC] Search url: " + url |
101 |
torben |
1631 |
|
102 |
torben |
1646 |
buildList(url, "søgning") |
103 |
torben |
1631 |
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
#=================================== Tool Box ======================================= |
109 |
|
|
# shows a more userfriendly notification |
110 |
|
|
def showMessage(heading, message): |
111 |
|
|
duration = 15*1000 |
112 |
|
|
xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) ) |
113 |
|
|
|
114 |
|
|
|
115 |
|
|
# raise a keyboard for user input |
116 |
|
|
def getUserInput(title = "Input", default="", hidden=False): |
117 |
|
|
result = None |
118 |
|
|
|
119 |
|
|
# Fix for when this functions is called with default=None |
120 |
|
|
if not default: |
121 |
|
|
default = "" |
122 |
|
|
|
123 |
|
|
keyboard = xbmc.Keyboard(default, title) |
124 |
|
|
keyboard.setHiddenInput(hidden) |
125 |
|
|
keyboard.doModal() |
126 |
|
|
|
127 |
|
|
if keyboard.isConfirmed(): |
128 |
|
|
result = keyboard.getText() |
129 |
|
|
|
130 |
|
|
return result |
131 |
|
|
|
132 |
|
|
|
133 |
torben |
1629 |
def get_params(): |
134 |
|
|
param=[] |
135 |
|
|
paramstring=sys.argv[2] |
136 |
|
|
if len(paramstring)>=2: |
137 |
|
|
params=sys.argv[2] |
138 |
|
|
cleanedparams=params.replace('?','') |
139 |
|
|
if (params[len(params)-1]=='/'): |
140 |
|
|
params=params[0:len(params)-2] |
141 |
|
|
pairsofparams=cleanedparams.split('&') |
142 |
|
|
param={} |
143 |
|
|
for i in range(len(pairsofparams)): |
144 |
|
|
splitparams={} |
145 |
|
|
splitparams=pairsofparams[i].split('=') |
146 |
|
|
if (len(splitparams))==2: |
147 |
|
|
param[splitparams[0]]=splitparams[1] |
148 |
|
|
return param |
149 |
|
|
|
150 |
|
|
params = get_params() |
151 |
|
|
url = None |
152 |
|
|
name = None |
153 |
|
|
mode = None |
154 |
|
|
|
155 |
|
|
params = get_params() |
156 |
|
|
url = None |
157 |
|
|
name = None |
158 |
|
|
mode = None |
159 |
|
|
|
160 |
|
|
try: |
161 |
|
|
url = urllib.unquote_plus(params["url"]) |
162 |
|
|
except: |
163 |
|
|
pass |
164 |
|
|
try: |
165 |
|
|
name = urllib.unquote_plus(params["name"]) |
166 |
|
|
except: |
167 |
|
|
pass |
168 |
|
|
try: |
169 |
|
|
mode = int(params["mode"]) |
170 |
|
|
except: |
171 |
|
|
pass |
172 |
|
|
|
173 |
|
|
|
174 |
|
|
if mode == None: |
175 |
|
|
#build main menu |
176 |
|
|
rootMenu() |
177 |
|
|
|
178 |
|
|
elif mode == 1: |
179 |
|
|
#build list of movie starting letters |
180 |
|
|
buildList(url, name) |
181 |
|
|
|
182 |
torben |
1631 |
elif mode == 10: |
183 |
|
|
search() |
184 |
|
|
|
185 |
|
|
|
186 |
torben |
1629 |
elif mode == 50: |
187 |
|
|
play_video(url, name) |
188 |
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
torben |
1632 |
# xbmcplugin.endOfDirectory(int(sys.argv[1])) |