/[projects]/misc/xbmc/plugin.video.todic/default.py
ViewVC logotype

Contents of /misc/xbmc/plugin.video.todic/default.py

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20