/[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 1650 - (hide annotations) (download) (as text)
Sun Dec 4 16:31:58 2011 UTC (12 years, 5 months ago) by torben
File MIME type: text/x-python
File size: 4756 byte(s)
only add media infomation to clips
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    
61     listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb)
62 torben 1648 listitem.setProperty('Fanart_Image', fanartImage)
63 torben 1650 if mode == '50':
64     infoLabels = {}
65     infoLabels['title'] = name
66     infoLabels['plot'] = description
67     listitem.setInfo('video', infoLabels)
68 torben 1648
69 torben 1629 u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url)
70 torben 1630 ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l)
71 torben 1629 xbmcplugin.endOfDirectory(int(sys.argv[1]))
72    
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 1634 if (search != None and search != ""):
92     url = __backend__ + "&action=search&search=" + urllib.quote_plus(search)
93 torben 1631
94 torben 1634 #print "[TODIC] Search start: " + search
95     #print "[TODIC] Search url: " + url
96 torben 1631
97 torben 1646 buildList(url, "søgning")
98 torben 1631
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 torben 1629 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 torben 1631 elif mode == 10:
178     search()
179    
180    
181 torben 1629 elif mode == 50:
182     play_video(url, name)
183    
184    
185    
186 torben 1632 # xbmcplugin.endOfDirectory(int(sys.argv[1]))

  ViewVC Help
Powered by ViewVC 1.1.20