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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1629 by torben, Sun Nov 27 11:01:27 2011 UTC revision 2594 by torben, Mon Jun 29 20:07:17 2015 UTC
# Line 1  Line 1 
1    
2    # This Python file uses the following encoding: utf-8
3    
4  '''  '''
5      Todic plugin for XBMC      Todic plugin for XBMC
6      Version 0.0.2      Version 0.0.14
7  '''  '''
8    
9  import sys  import sys
10  import cgi as urlparse  import cgi as urlparse
11    import os
12    
13    
14  import xbmc  import xbmc
15  import xbmcaddon  import xbmcaddon
16  import xbmcgui  import xbmcgui
17  import xbmcplugin  import xbmcplugin
18  import urllib  import urllib
19  import urllib2, re  import urllib2
20    
21    from xml.dom.minidom import parseString
22    
23  __addon__ = xbmcaddon.Addon(id='plugin.video.todic')  __addon__ = xbmcaddon.Addon(id='plugin.video.todic')
24  __key__ = __addon__.getSetting('xbmckey').lower()  __key__ = __addon__.getSetting('xbmckey').lower()
25  __backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__  __backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__
26    fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg')
27    datapath = xbmc.translatePath('special://profile/addon_data/plugin.video.todic/')
28    
29    ADDON_PATH = __addon__.getAddonInfo('path')
30    SkinMasterPath = os.path.join(ADDON_PATH, 'skins' ) + '/'
31    MySkinPath = (os.path.join(SkinMasterPath, '720p')) + '/'
32    MySkin = 'main.xml'
33    
34    
35    class TodicMovieDialog(xbmcgui.WindowXMLDialog):
36            def __new__(cls):
37                    return super(TodicMovieDialog, cls).__new__(cls, "main.xml", ADDON_PATH)
38    
39            def __init__(self):
40                    super(TodicMovieDialog, self).__init__()
41    
42            def onClick( self, controlId ):
43                    print "OnClick: " + str(controlId)
44            
45                    if (controlId == 50):
46                            self.close()
47                            play_real_video(self.url, self.name)
48    
49                    if ( controlId == 98 ):
50                            self.close()
51    
52    
53            def onInit(self):
54    
55                    print "ONINIT"
56                    self.getControl( 1 ).setLabel( self.name);
57                    self.getControl( 2 ).setLabel( self.description );
58    
59            def setUrl( self, url):
60                    self.url = url
61    
62            def setName( self, name ):
63                    self.name = name
64    
65            def setDescription( self, description ):
66                    self.description = description
67    
68    
69    class TodicPlayer(xbmc.Player):
70            def __init__(self, *args, **kwargs):
71                    #xbmc.Player.__init__(selv,*args,**kwargs)
72                    xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER )
73                    self.stopped = False
74                    self.started = False
75                    print "[TodicPlayer] init"
76    
77    #       @catchall      
78            def onPlayBackStarted(self):
79                    self.started = True
80                    print "[TodicPlayer] : started"
81    #               super.onPlayBackStarted()
82    
83            def onPlayBackStopped(self):
84                    self.stopped = True
85                    print "[TodicPlayer] : stopped"
86    
87            def onPlayBackEnded(self):
88                    self.stopped = True
89                    print "[TodicPlayer] : ended"
90    
91            def callbackLoop(self):
92                    print "[Todic] startLoop"
93                    while (self.stopped == False):
94                            if (self.started == True ):
95                                    print "[todic] " + str(self.getTime())
96                            xbmc.sleep(5000)
97                            
98    
99    def getText2(nodelist):
100            rc = []
101            for node in nodelist:
102                    if node.nodeType == node.TEXT_NODE:
103                            rc.append(node.data)
104                    else:
105                            rc.append( getText(node.childNodes) )
106            return ''.join(rc)
107    
108    def getText(nodelist):
109            if nodelist.length == 0:
110                    return ''
111            else:
112                    if nodelist[0].childNodes.length == 0:
113                            return ''
114                    else:
115                            return nodelist[0].childNodes[0].nodeValue
116    
117    def SaveFile(path, data):
118            file = open(path,'w')
119            file.write(data)
120            file.close()
121    
122    
123  def open_url(url):  def open_url(url):
124          req = urllib2.Request(url)          req = urllib2.Request(url)
# Line 25  def open_url(url): Line 128  def open_url(url):
128          return data          return data
129    
130  def rootMenu():  def rootMenu():
         link = open_url(__backend__)  
         m=re.compile('<title>(.+?)</title><url>(.+?)</url>').findall(link)  
         for name,url in m:  
                 listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png')  
                 u = sys.argv[0] + "?mode=1&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url)  
                 ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True)  
         xbmcplugin.endOfDirectory(int(sys.argv[1]))  
131    
132            msg = open_url(__backend__ + "&action=messages")
133            msg = msg.strip()
134    
135            if msg != "":
136                    dialog = xbmcgui.Dialog()              
137                    dialog.ok('XBMC Todic', msg)
138    
139            buildList(__backend__, "", False) # call default list
140    
141            # Adde xtra items to root menu
142            listitem = xbmcgui.ListItem(label = "Søg film ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png')
143            listitem.setProperty('Fanart_Image', fanartImage)
144    
145            u = sys.argv[0] + "?mode=10&name="
146            ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True)
147    
148            #add search series
149            listitem = xbmcgui.ListItem(label = "Søg Serier ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png')
150            listitem.setProperty('Fanart_Image', fanartImage)
151    
152            u = sys.argv[0] + "?mode=11&name="
153            ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True)
154    
 def buildList(url,title):  
         print '[TODIC]:'+str(url)          
         link = open_url(url)  
         ty=re.compile('<meta type=\'(.+?)\'').findall(link)  
         print '[TOD]'+str(ty[0])  
         m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover>').findall(link)  
         for name,url,thumb in m:  
                 if ty[0] == 'clipList':  
                         mode = '50'  
                         folder = False  
                 else:  
                         mode = '2'  
                         folder = True  
                           
                 listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = thumb)  
                 u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url)  
                 ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder)  
155          xbmcplugin.endOfDirectory(int(sys.argv[1]))          xbmcplugin.endOfDirectory(int(sys.argv[1]))
156    
157  def buildSubList(url,title):  
158    def buildList(url,title, endlist=True):
159          print '[TODIC]:'+str(url)          print '[TODIC]:'+str(url)
160    
161          link = open_url(url)          link = open_url(url)
162          m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover>').findall(link)          doc = parseString(link)
163          for name,url,thumb in m:          ty = doc.getElementsByTagName("meta")[0].getAttribute("type")
164                  listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = thumb)          print '[TODIC]'+str(ty)
165                  u = sys.argv[0] + "?mode=50&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url)  
166                  ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = False)          if ty == 'clipList':
167          xbmcplugin.endOfDirectory(int(sys.argv[1]))                  mode = '50'
168                    folder = False
169            else:
170                    mode = '1'
171                    folder = True
172    
173    
174            entries = doc.getElementsByTagName("entry")
175            l=len(entries)
176            description = ''
177            for entry in entries:
178                    name =  getText( entry.getElementsByTagName("title") )
179                    url =  getText( entry.getElementsByTagName("url") )
180                    thumb = getText( entry.getElementsByTagName("cover") )
181                    description = getText( entry.getElementsByTagName("description") )
182                    playcount = getText( entry.getElementsByTagName("playcount") )
183    
184                    if playcount == '':
185                            playcount = '0'
186                    playcount = int(playcount)
187    
188    
189    ##              print "name:" + name
190    #               print "url:" + url
191    #               print "thumb:" + thumb
192    #               print "description:" + description
193    
194    
195                    listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb)
196                    listitem.setProperty('Fanart_Image', fanartImage)
197                    if mode == '50':
198                            infoLabels = {}
199                            infoLabels['title'] = name
200                            infoLabels['plot'] = description
201                            infoLabels['playcount'] = playcount
202                            listitem.setInfo('video', infoLabels)
203    
204                    name = name.encode('UTF-8')
205                    description = description.encode('UTF-8')
206    
207    
208                    u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description)
209                    ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l)
210    
211            if (endlist == True):  
212                    xbmcplugin.endOfDirectory(int(sys.argv[1]))
213    
214    
215    
216    
217    def play_video(url, name,description):
218            if (description == None or description == ""):
219                    play_real_video(url,name)
220            else:
221                    d = TodicMovieDialog()
222                    d.setUrl( url)
223                    d.setName( name )
224                    d.setDescription( description )
225    
226                    d.doModal()
227    
228    
229    def play_real_video(url, name):
230            xml = open_url(url)
231            print 'TODIC url: ' + str(url)
232            print 'TODIC xml: '+ xml
233    
234            doc = parseString(xml)
235            url = getText( doc.getElementsByTagName("url") )
236    
237            subtitleurl = getText( doc.getElementsByTagName("subtitles") )
238            subtitlesfile = os.path.join(datapath,'temp.srt')
239    
240            #if old srt file exists delete it first
241            if os.path.isfile(subtitlesfile):
242                    os.unlink(subtitlesfile)
243    
244            print '[TODIC] subs: '+str(subtitleurl)
245            if len(subtitleurl) > 0:
246                    subtitles = open_url(subtitleurl)
247                    SaveFile(subtitlesfile, subtitles)
248                    print 'TODIC downloaded subtitles'
249    
250    
251    
 def play_video(url, name):  
         link = open_url(url)  
         match=re.compile('<url>(.+?)</url>').findall(link)  
         url = match[0]  
         print '[TODIC]:'+str(url)  
252          image = xbmc.getInfoImage( 'ListItem.Thumb' )          image = xbmc.getInfoImage( 'ListItem.Thumb' )
253          listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image)          listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image)
 #       listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = 'DefaultVideo.png')  
254          listitem.setInfo( type = "Video", infoLabels={ "Title": name } )          listitem.setInfo( type = "Video", infoLabels={ "Title": name } )
255          xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(str(url), listitem)  
256          xbmc.sleep(200)          player = TodicPlayer(xbmc.PLAYER_CORE_AUTO)
257            player.play(str(url), listitem)
258    
259            #kan ikke loade subtitles hvis foerend playeren koerer
260            count = 0
261            while not xbmc.Player().isPlaying():
262                    xbmc.sleep(500)
263                    count += 1
264                    if count > 10:
265                            break
266    
267    
268            if xbmc.Player().isPlaying():
269                    if os.path.isfile(subtitlesfile):
270                            player.setSubtitles(subtitlesfile)
271                            print 'TODIC started subtitles'
272                    else:
273                            player.disableSubtitles()
274    
275    #       player.callbackLoop()
276    
277    
278    
279    def search():
280            search = getUserInput("Todic Søgning")
281    
282            if (search != None and search != ""):
283                    url = __backend__ + "&action=search&search=" + urllib.quote_plus(search)
284    
285                    #print "[TODIC] Search start: " + search
286                    #print "[TODIC] Search url: " + url
287    
288                    buildList(url, "søgning")
289    
290    def searchSeries():
291            search = getUserInput("Todic Serie Søgning")
292    
293            if (search != None and search != ""):
294                    url = __backend__ + "&action=searchseries&search=" + urllib.quote_plus(search)
295    
296                    #print "[TODIC] Search start: " + search
297                    #print "[TODIC] Search url: " + url
298    
299                    buildList(url, "serie søgning")
300    
301            
302    
303    
304                    
305    #=================================== Tool Box =======================================
306    # shows a more userfriendly notification
307    def showMessage(heading, message):
308            duration = 15*1000
309            xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) )
310    
311    
312    # raise a keyboard for user input
313    def getUserInput(title = "Input", default="", hidden=False):
314            result = None
315    
316            # Fix for when this functions is called with default=None
317            if not default:
318                    default = ""
319                            
320            keyboard = xbmc.Keyboard(default, title)
321            keyboard.setHiddenInput(hidden)
322            keyboard.doModal()
323                    
324            if keyboard.isConfirmed():
325                    result = keyboard.getText()
326                    
327            return result
328    
329    
330  def get_params():  def get_params():
# Line 95  def get_params(): Line 344  def get_params():
344                                  param[splitparams[0]]=splitparams[1]                                                                      param[splitparams[0]]=splitparams[1]                                    
345          return param          return param
346    
 params = get_params()  
 url = None  
 name = None  
 mode = None  
347    
348  params = get_params()  params = get_params()
349  url = None  url = None
350  name = None  name = None
351  mode = None  mode = None
352    description = None
353    
354  try:  try:
355          url = urllib.unquote_plus(params["url"])          url = urllib.unquote_plus(params["url"])
# Line 117  try: Line 363  try:
363          mode = int(params["mode"])          mode = int(params["mode"])
364  except:  except:
365          pass          pass
366    try:
367            description = urllib.unquote_plus(params["description"])
368    except:
369            pass
370    
371    try:
372            open_url("http://todic.dk")
373    except:
374            showMessage("Fejl", "Kunne ikke forbinde til todic.dk")
375            exit()
376                            
377    
378    if url == 'refresh':
379            #xbmc.output("[tvserver] Container.Refresh") #20130418 xbmc.output virker ikke med XBMC12
380            xbmc.executebuiltin("Container.Refresh")
381            
382    
383  if mode == None:  elif mode == None:
384          #build main menu          #build main menu
385          rootMenu()          rootMenu()
386                
# Line 127  elif mode == 1: Line 388  elif mode == 1:
388          #build list of movie starting letters          #build list of movie starting letters
389          buildList(url, name)          buildList(url, name)
390    
391  elif mode == 2:  elif mode == 10:
392          #build list of series                  search()
393          buildSubList(url, name)  
394    elif mode == 11:
395            searchSeries()
396            
397    
398  elif mode == 50:  elif mode == 50:
399          play_video(url, name)          play_video(url, name, description)
400    
401    
402    
 xbmcplugin.endOfDirectory(int(sys.argv[1]))  
403    

Legend:
Removed from v.1629  
changed lines
  Added in v.2594

  ViewVC Help
Powered by ViewVC 1.1.20