/[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 1649 - (hide annotations) (download) (as text)
Sun Dec 4 15:06:39 2011 UTC (12 years, 6 months ago) by torben
File MIME type: text/x-python
File size: 4733 byte(s)
code cleanup: root menu is just a call to buildList with some extras
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 torben 1648
32 torben 1649 buildList(__backend__, "") # call default list
33 torben 1631
34 torben 1649 # Adde xtra items to root menu
35 torben 1640 listitem = xbmcgui.ListItem(label = "Søg film ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png')
36 torben 1648 listitem.setProperty('Fanart_Image', fanartImage)
37    
38 torben 1649 u = sys.argv[0] + "?mode=10&name="
39     ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True)
40 torben 1631
41 torben 1629 xbmcplugin.endOfDirectory(int(sys.argv[1]))
42    
43    
44     def buildList(url,title):
45     print '[TODIC]:'+str(url)
46     link = open_url(url)
47     ty=re.compile('<meta type=\'(.+?)\'').findall(link)
48 torben 1646 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 torben 1647 m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover><description>(.*)</description>').findall(link)
58 torben 1630 l=len(m)
59 torben 1647 for name,url,thumb,description in m:
60     infoLabels = {}
61     infoLabels['title'] = name
62     infoLabels['plot'] = description
63    
64     listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb)
65     listitem.setInfo('video', infoLabels)
66 torben 1648 listitem.setProperty('Fanart_Image', fanartImage)
67    
68 torben 1629 u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url)
69 torben 1630 ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l)
70 torben 1629 xbmcplugin.endOfDirectory(int(sys.argv[1]))
71    
72    
73    
74    
75     def play_video(url, name):
76     link = open_url(url)
77     match=re.compile('<url>(.+?)</url>').findall(link)
78     url = match[0]
79     print '[TODIC]:'+str(url)
80     image = xbmc.getInfoImage( 'ListItem.Thumb' )
81     listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image)
82     # listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = 'DefaultVideo.png')
83     listitem.setInfo( type = "Video", infoLabels={ "Title": name } )
84     xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(str(url), listitem)
85     xbmc.sleep(200)
86    
87 torben 1631 def search():
88     search = getUserInput("Todic Søgning")
89 torben 1629
90 torben 1634 if (search != None and search != ""):
91     url = __backend__ + "&action=search&search=" + urllib.quote_plus(search)
92 torben 1631
93 torben 1634 #print "[TODIC] Search start: " + search
94     #print "[TODIC] Search url: " + url
95 torben 1631
96 torben 1646 buildList(url, "søgning")
97 torben 1631
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 torben 1631 elif mode == 10:
177     search()
178    
179    
180 torben 1629 elif mode == 50:
181     play_video(url, name)
182    
183    
184    
185 torben 1632 # xbmcplugin.endOfDirectory(int(sys.argv[1]))

  ViewVC Help
Powered by ViewVC 1.1.20