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

  ViewVC Help
Powered by ViewVC 1.1.20