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

  ViewVC Help
Powered by ViewVC 1.1.20