/[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 1677 - (hide annotations) (download) (as text)
Mon Jan 23 15:50:40 2012 UTC (12 years, 4 months ago) by torben
File MIME type: text/x-python
File size: 5681 byte(s)
this source file is utf-8 encoded
1 torben 1677 # This Python file uses the following encoding: utf-8
2    
3    
4 torben 1629 '''
5     Todic plugin for XBMC
6     Version 0.0.2
7     '''
8    
9     import sys
10     import cgi as urlparse
11 torben 1648 import os
12 torben 1629
13 torben 1648
14 torben 1629 import xbmc
15     import xbmcaddon
16     import xbmcgui
17     import xbmcplugin
18     import urllib
19     import urllib2, re
20    
21     __addon__ = xbmcaddon.Addon(id='plugin.video.todic')
22     __key__ = __addon__.getSetting('xbmckey').lower()
23     __backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__
24 torben 1648 fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'fanart.jpg')
25 torben 1629
26 torben 1676
27     class TodicPlayer(xbmc.Player):
28     def __init__(self, *args, **kwargs):
29     #xbmc.Player.__init__(selv,*args,**kwargs)
30     xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER )
31     self.stopped = False
32     self.started = False
33     print "[TodicPlayer] init"
34    
35     # @catchall
36     def onPlayBackStarted(self):
37     self.started = True
38     print "[TodicPlayer] : started"
39     # super.onPlayBackStarted()
40    
41     def onPlayBackStopped(self):
42     self.stopped = True
43     print "[TodicPlayer] : stopped"
44    
45     def onPlayBackEnded(self):
46     self.stopped = True
47     print "[TodicPlayer] : ended"
48    
49     def callbackLoop(self):
50     print "[Todic] startLoop"
51     while (self.stopped == False):
52     if (self.started == True ):
53     print "[todic] " + str(self.getTime())
54     xbmc.sleep(5000)
55    
56    
57    
58    
59 torben 1629 def open_url(url):
60     req = urllib2.Request(url)
61     content = urllib2.urlopen(req)
62     data = content.read()
63     content.close()
64     return data
65    
66     def rootMenu():
67 torben 1648
68 torben 1659 buildList(__backend__, "", False) # call default list
69 torben 1631
70 torben 1649 # Adde xtra items to root menu
71 torben 1640 listitem = xbmcgui.ListItem(label = "Søg film ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png')
72 torben 1648 listitem.setProperty('Fanart_Image', fanartImage)
73    
74 torben 1649 u = sys.argv[0] + "?mode=10&name="
75     ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True)
76 torben 1631
77 torben 1629 xbmcplugin.endOfDirectory(int(sys.argv[1]))
78    
79    
80 torben 1659 def buildList(url,title, endlist=True):
81 torben 1629 print '[TODIC]:'+str(url)
82     link = open_url(url)
83     ty=re.compile('<meta type=\'(.+?)\'').findall(link)
84 torben 1646 print '[TODIC]'+str(ty[0])
85    
86     if ty[0] == 'clipList':
87     mode = '50'
88     folder = False
89     else:
90     mode = '1'
91     folder = True
92    
93 torben 1647 m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover><description>(.*)</description>').findall(link)
94 torben 1630 l=len(m)
95 torben 1647 for name,url,thumb,description in m:
96    
97     listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb)
98 torben 1648 listitem.setProperty('Fanart_Image', fanartImage)
99 torben 1650 if mode == '50':
100     infoLabels = {}
101     infoLabels['title'] = name
102     infoLabels['plot'] = description
103     listitem.setInfo('video', infoLabels)
104 torben 1648
105 torben 1629 u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url)
106 torben 1630 ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l)
107 torben 1629
108 torben 1659 if (endlist == True):
109     xbmcplugin.endOfDirectory(int(sys.argv[1]))
110 torben 1629
111    
112    
113 torben 1659
114 torben 1629 def play_video(url, name):
115     link = open_url(url)
116     match=re.compile('<url>(.+?)</url>').findall(link)
117     url = match[0]
118     print '[TODIC]:'+str(url)
119     image = xbmc.getInfoImage( 'ListItem.Thumb' )
120     listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image)
121     # listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = 'DefaultVideo.png')
122     listitem.setInfo( type = "Video", infoLabels={ "Title": name } )
123 torben 1676 # xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(str(url), listitem)
124 torben 1629
125 torben 1676 player = TodicPlayer(xbmc.PLAYER_CORE_AUTO)
126     player.play(str(url), listitem)
127     player.callbackLoop()
128    
129    
130    
131 torben 1631 def search():
132     search = getUserInput("Todic Søgning")
133 torben 1629
134 torben 1634 if (search != None and search != ""):
135     url = __backend__ + "&action=search&search=" + urllib.quote_plus(search)
136 torben 1631
137 torben 1634 #print "[TODIC] Search start: " + search
138     #print "[TODIC] Search url: " + url
139 torben 1631
140 torben 1646 buildList(url, "søgning")
141 torben 1631
142    
143    
144    
145    
146     #=================================== Tool Box =======================================
147     # shows a more userfriendly notification
148     def showMessage(heading, message):
149     duration = 15*1000
150     xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) )
151    
152    
153     # raise a keyboard for user input
154     def getUserInput(title = "Input", default="", hidden=False):
155     result = None
156    
157     # Fix for when this functions is called with default=None
158     if not default:
159     default = ""
160    
161     keyboard = xbmc.Keyboard(default, title)
162     keyboard.setHiddenInput(hidden)
163     keyboard.doModal()
164    
165     if keyboard.isConfirmed():
166     result = keyboard.getText()
167    
168     return result
169    
170    
171 torben 1629 def get_params():
172     param=[]
173     paramstring=sys.argv[2]
174     if len(paramstring)>=2:
175     params=sys.argv[2]
176     cleanedparams=params.replace('?','')
177     if (params[len(params)-1]=='/'):
178     params=params[0:len(params)-2]
179     pairsofparams=cleanedparams.split('&')
180     param={}
181     for i in range(len(pairsofparams)):
182     splitparams={}
183     splitparams=pairsofparams[i].split('=')
184     if (len(splitparams))==2:
185     param[splitparams[0]]=splitparams[1]
186     return param
187    
188     params = get_params()
189     url = None
190     name = None
191     mode = None
192    
193     params = get_params()
194     url = None
195     name = None
196     mode = None
197    
198     try:
199     url = urllib.unquote_plus(params["url"])
200     except:
201     pass
202     try:
203     name = urllib.unquote_plus(params["name"])
204     except:
205     pass
206     try:
207     mode = int(params["mode"])
208     except:
209     pass
210    
211    
212     if mode == None:
213     #build main menu
214     rootMenu()
215    
216     elif mode == 1:
217     #build list of movie starting letters
218     buildList(url, name)
219    
220 torben 1631 elif mode == 10:
221     search()
222    
223    
224 torben 1629 elif mode == 50:
225     play_video(url, name)
226    
227    
228    
229 torben 1632 # xbmcplugin.endOfDirectory(int(sys.argv[1]))

  ViewVC Help
Powered by ViewVC 1.1.20