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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1631 - (hide annotations) (download) (as text)
Sun Nov 27 12:37:43 2011 UTC (12 years, 6 months ago) by torben
File MIME type: text/x-python
File size: 5496 byte(s)
added search option
1 torben 1629 '''
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 torben 1630 l = len(m)
31 torben 1629 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 torben 1630 ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True, totalItems = l)
35 torben 1631
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 torben 1629 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 torben 1630 l=len(m)
50 torben 1629 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 torben 1630 ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l)
61 torben 1629 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 torben 1630 l = len(m)
68 torben 1629 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 torben 1630 ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = False, totalItems = l)
72 torben 1629 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 torben 1631 def search():
89     search = getUserInput("Todic Søgning")
90 torben 1629
91 torben 1631 url = __backend__ + "&action=search&search=" + urllib.quote_plus(search)
92    
93     print "[TODIC] Search start: " + search
94     print "[TODIC] Search url: " + url
95    
96     buildSubList(url, "søgning")
97    
98    
99    
100    
101    
102     #=================================== Tool Box =======================================
103     # shows a more userfriendly notification
104     def showMessage(heading, message):
105     duration = 15*1000
106     xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) )
107    
108    
109     # raise a keyboard for user input
110     def getUserInput(title = "Input", default="", hidden=False):
111     result = None
112    
113     # Fix for when this functions is called with default=None
114     if not default:
115     default = ""
116    
117     keyboard = xbmc.Keyboard(default, title)
118     keyboard.setHiddenInput(hidden)
119     keyboard.doModal()
120    
121     if keyboard.isConfirmed():
122     result = keyboard.getText()
123    
124     return result
125    
126    
127 torben 1629 def get_params():
128     param=[]
129     paramstring=sys.argv[2]
130     if len(paramstring)>=2:
131     params=sys.argv[2]
132     cleanedparams=params.replace('?','')
133     if (params[len(params)-1]=='/'):
134     params=params[0:len(params)-2]
135     pairsofparams=cleanedparams.split('&')
136     param={}
137     for i in range(len(pairsofparams)):
138     splitparams={}
139     splitparams=pairsofparams[i].split('=')
140     if (len(splitparams))==2:
141     param[splitparams[0]]=splitparams[1]
142     return param
143    
144     params = get_params()
145     url = None
146     name = None
147     mode = None
148    
149     params = get_params()
150     url = None
151     name = None
152     mode = None
153    
154     try:
155     url = urllib.unquote_plus(params["url"])
156     except:
157     pass
158     try:
159     name = urllib.unquote_plus(params["name"])
160     except:
161     pass
162     try:
163     mode = int(params["mode"])
164     except:
165     pass
166    
167    
168     if mode == None:
169     #build main menu
170     rootMenu()
171    
172     elif mode == 1:
173     #build list of movie starting letters
174     buildList(url, name)
175    
176     elif mode == 2:
177     #build list of series
178     buildSubList(url, name)
179    
180 torben 1631 elif mode == 10:
181     search()
182    
183    
184 torben 1629 elif mode == 50:
185     play_video(url, name)
186    
187    
188    
189     xbmcplugin.endOfDirectory(int(sys.argv[1]))

  ViewVC Help
Powered by ViewVC 1.1.20