/[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 1676 by torben, Mon Jan 2 20:51:02 2012 UTC revision 2596 by torben, Tue Jun 30 13:39:04 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.15
7  '''  '''
8    
9  import sys  import sys
# Line 13  import xbmcaddon Line 16  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    #import pprint
22    
23    from xml.dom.minidom import parseString
24    
25  __addon__ = xbmcaddon.Addon(id='plugin.video.todic')  __addon__ = xbmcaddon.Addon(id='plugin.video.todic')
26  __key__ = __addon__.getSetting('xbmckey').lower()  __key__ = __addon__.getSetting('xbmckey').lower()
27  __backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__  __backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__
28  fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'fanart.jpg')  fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg')
29    datapath = xbmc.translatePath('special://profile/addon_data/plugin.video.todic/')
30    
31    ADDON_PATH = __addon__.getAddonInfo('path')
32    SkinMasterPath = os.path.join(ADDON_PATH, 'skins' ) + '/'
33    MySkinPath = (os.path.join(SkinMasterPath, '720p')) + '/'
34    MySkin = 'main.xml'
35    
36    
37    class TodicMovieDialog(xbmcgui.WindowXMLDialog):
38            def __new__(cls):
39                    return super(TodicMovieDialog, cls).__new__(cls, "main.xml", ADDON_PATH)
40    
41            def __init__(self):
42                    super(TodicMovieDialog, self).__init__()
43    
44            def onClick( self, controlId ):
45                    print "OnClick: " + str(controlId)
46            
47                    if (controlId == 50):
48                            self.close()
49                            play_real_video(self.url, self.name)
50    
51                    if ( controlId == 98 ):
52                            self.close()
53    
54    
55            def onInit(self):
56    
57                    print "ONINIT"
58                    self.getControl( 1 ).setLabel( self.name);
59                    self.getControl( 2 ).setLabel( self.moviegroups )
60                    self.getControl( 3 ).setLabel( self.description )
61                    self.getControl( 10 ).setLabel( self.playlength )
62                    self.getControl( 11 ).setLabel( self.codecdetails )
63    
64            
65    
66                    orig_img_width = self.getControl(40).getWidth()
67                    self.starwidth = ( float(self.imdbrating) / 10.0) * orig_img_width;
68                    self.getControl(40).setWidth( int(self.starwidth) )
69    
70            def setUrl( self, url):
71                    print "SETURL:" + url
72                    self.url = url
73                    self.fetchClipDetails()
74    
75    
76            def fetchClipDetails(self):
77                    param1 = parse_parameter_string( self.url )
78    
79                    self.clipkey = param1[ "clipkey" ]
80                    print "CLIPKEY:" + self.clipkey
81                    detailurl = __backend__ + "&action=clipdetails&clipkey=" + self.clipkey
82            
83                    xml = open_url(detailurl)
84    
85                    doc = parseString(xml)
86                    self.imdbrating = getText( doc.getElementsByTagName("imdbrating") )
87                    self.moviegroups = getText( doc.getElementsByTagName("moviegroups") )
88                    self.playlength = getText( doc.getElementsByTagName("playlength") )
89                    self.codecdetails = getText( doc.getElementsByTagName("codecdetails") )
90    
91    
92    
93    
94    
95            def setName( self, name ):
96                    self.name = name
97    
98            def setDescription( self, description ):
99                    self.description = description
100    
101    
102  class TodicPlayer(xbmc.Player):  class TodicPlayer(xbmc.Player):
# Line 51  class TodicPlayer(xbmc.Player): Line 129  class TodicPlayer(xbmc.Player):
129                          xbmc.sleep(5000)                          xbmc.sleep(5000)
130                                                    
131    
132    def getText2(nodelist):
133            rc = []
134            for node in nodelist:
135                    if node.nodeType == node.TEXT_NODE:
136                            rc.append(node.data)
137                    else:
138                            rc.append( getText(node.childNodes) )
139            return ''.join(rc)
140    
141    def getText(nodelist):
142            if nodelist.length == 0:
143                    return ''
144            else:
145                    if nodelist[0].childNodes.length == 0:
146                            return ''
147                    else:
148                            return nodelist[0].childNodes[0].nodeValue
149    
150    def SaveFile(path, data):
151            file = open(path,'w')
152            file.write(data)
153            file.close()
154    
155    
156  def open_url(url):  def open_url(url):
# Line 62  def open_url(url): Line 162  def open_url(url):
162    
163  def rootMenu():  def rootMenu():
164    
165            msg = open_url(__backend__ + "&action=messages")
166            msg = msg.strip()
167    
168            if msg != "":
169                    dialog = xbmcgui.Dialog()              
170                    dialog.ok('XBMC Todic', msg)
171    
172          buildList(__backend__, "", False) # call default list          buildList(__backend__, "", False) # call default list
173    
174          # Adde xtra items to root menu          # Adde xtra items to root menu
# Line 71  def rootMenu(): Line 178  def rootMenu():
178          u = sys.argv[0] + "?mode=10&name="          u = sys.argv[0] + "?mode=10&name="
179          ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True)          ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True)
180    
181            #add search series
182            listitem = xbmcgui.ListItem(label = "Søg Serier ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png')
183            listitem.setProperty('Fanart_Image', fanartImage)
184    
185            u = sys.argv[0] + "?mode=11&name="
186            ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True)
187    
188          xbmcplugin.endOfDirectory(int(sys.argv[1]))          xbmcplugin.endOfDirectory(int(sys.argv[1]))
189    
190    
191  def buildList(url,title, endlist=True):  def buildList(url,title, endlist=True):
192          print '[TODIC]:'+str(url)                  print '[TODIC]:'+str(url)
193    
194          link = open_url(url)          link = open_url(url)
195          ty=re.compile('<meta type=\'(.+?)\'').findall(link)          doc = parseString(link)
196          print '[TODIC]'+str(ty[0])          ty = doc.getElementsByTagName("meta")[0].getAttribute("type")
197            print '[TODIC]'+str(ty)
198    
199          if ty[0] == 'clipList':          if ty == 'clipList':
200                  mode = '50'                  mode = '50'
201                  folder = False                  folder = False
202          else:          else:
203                  mode = '1'                  mode = '1'
204                  folder = True                  folder = True
205    
206          m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover><description>(.*)</description>').findall(link)  
207          l=len(m)          entries = doc.getElementsByTagName("entry")
208          for name,url,thumb,description in m:                                  l=len(entries)
209            description = ''
210            for entry in entries:
211                    name =  getText( entry.getElementsByTagName("title") )
212                    url =  getText( entry.getElementsByTagName("url") )
213                    thumb = getText( entry.getElementsByTagName("cover") )
214                    description = getText( entry.getElementsByTagName("description") )
215                    playcount = getText( entry.getElementsByTagName("playcount") )
216    
217                    if playcount == '':
218                            playcount = '0'
219                    playcount = int(playcount)
220    
221    
222    ##              print "name:" + name
223    #               print "url:" + url
224    #               print "thumb:" + thumb
225    #               print "description:" + description
226    
227    
228                  listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb)                  listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb)
229                  listitem.setProperty('Fanart_Image', fanartImage)                  listitem.setProperty('Fanart_Image', fanartImage)
230                  if mode == '50':                  if mode == '50':
231                          infoLabels = {}                          infoLabels = {}
232                          infoLabels['title'] = name                          infoLabels['title'] = name
233                          infoLabels['plot'] = description                                  infoLabels['plot'] = description
234                            infoLabels['playcount'] = playcount
235                          listitem.setInfo('video', infoLabels)                          listitem.setInfo('video', infoLabels)
236    
237                  u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url)                  name = name.encode('UTF-8')
238                    description = description.encode('UTF-8')
239    
240    
241                    u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description)
242                  ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l)                  ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l)
243    
244          if (endlist == True):            if (endlist == True):  
# Line 108  def buildList(url,title, endlist=True): Line 247  def buildList(url,title, endlist=True):
247    
248    
249    
250  def play_video(url, name):  def play_video(url, name,description):
251          link = open_url(url)          if (description == None or description == ""):
252          match=re.compile('<url>(.+?)</url>').findall(link)                  play_real_video(url,name)
253          url = match[0]          else:
254          print '[TODIC]:'+str(url)                  d = TodicMovieDialog()
255                    d.setUrl( url)
256                    d.setName( name )
257                    d.setDescription( description )
258    
259                    d.doModal()
260    
261    
262    def play_real_video(url, name):
263            xml = open_url(url)
264            print 'TODIC url: ' + str(url)
265            print 'TODIC xml: '+ xml
266    
267            doc = parseString(xml)
268            url = getText( doc.getElementsByTagName("url") )
269    
270            subtitleurl = getText( doc.getElementsByTagName("subtitles") )
271            subtitlesfile = os.path.join(datapath,'temp.srt')
272    
273            #if old srt file exists delete it first
274            if os.path.isfile(subtitlesfile):
275                    os.unlink(subtitlesfile)
276    
277            print '[TODIC] subs: '+str(subtitleurl)
278            if len(subtitleurl) > 0:
279                    subtitles = open_url(subtitleurl)
280                    SaveFile(subtitlesfile, subtitles)
281                    print 'TODIC downloaded subtitles'
282    
283    
284    
285          image = xbmc.getInfoImage( 'ListItem.Thumb' )          image = xbmc.getInfoImage( 'ListItem.Thumb' )
286          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')  
287          listitem.setInfo( type = "Video", infoLabels={ "Title": name } )          listitem.setInfo( type = "Video", infoLabels={ "Title": name } )
 #       xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(str(url), listitem)  
288    
289          player = TodicPlayer(xbmc.PLAYER_CORE_AUTO)          player = TodicPlayer(xbmc.PLAYER_CORE_AUTO)
290          player.play(str(url), listitem)          player.play(str(url), listitem)
291          player.callbackLoop()  
292            #kan ikke loade subtitles hvis foerend playeren koerer
293            count = 0
294            while not xbmc.Player().isPlaying():
295                    xbmc.sleep(500)
296                    count += 1
297                    if count > 10:
298                            break
299    
300    
301            if xbmc.Player().isPlaying():
302                    if os.path.isfile(subtitlesfile):
303                            player.setSubtitles(subtitlesfile)
304                            print 'TODIC started subtitles'
305                    else:
306                            player.disableSubtitles()
307    
308    #       player.callbackLoop()
309    
310    
311    
# Line 136  def search(): Line 320  def search():
320    
321                  buildList(url, "søgning")                  buildList(url, "søgning")
322    
323    def searchSeries():
324            search = getUserInput("Todic Serie Søgning")
325    
326            if (search != None and search != ""):
327                    url = __backend__ + "&action=searchseries&search=" + urllib.quote_plus(search)
328    
329                    #print "[TODIC] Search start: " + search
330                    #print "[TODIC] Search url: " + url
331    
332                    buildList(url, "serie søgning")
333    
334                    
335    
336    
# Line 166  def getUserInput(title = "Input", defaul Line 361  def getUserInput(title = "Input", defaul
361    
362    
363  def get_params():  def get_params():
364            return parse_parameter_string( sys.argv[2] )
365    
366    def parse_parameter_string( paramstring ):
367          param=[]          param=[]
         paramstring=sys.argv[2]  
368          if len(paramstring)>=2:          if len(paramstring)>=2:
369                  params=sys.argv[2]                  params = paramstring
370                  cleanedparams=params.replace('?','')                  cleanedparams=params.replace('?','')
371                  if (params[len(params)-1]=='/'):                  if (params[len(params)-1]=='/'):
372                          params=params[0:len(params)-2]                          params=params[0:len(params)-2]
# Line 182  def get_params(): Line 379  def get_params():
379                                  param[splitparams[0]]=splitparams[1]                                                                      param[splitparams[0]]=splitparams[1]                                    
380          return param          return param
381    
 params = get_params()  
 url = None  
 name = None  
 mode = None  
382    
383  params = get_params()  params = get_params()
384  url = None  url = None
385  name = None  name = None
386  mode = None  mode = None
387    description = None
388    
389  try:  try:
390          url = urllib.unquote_plus(params["url"])          url = urllib.unquote_plus(params["url"])
# Line 204  try: Line 398  try:
398          mode = int(params["mode"])          mode = int(params["mode"])
399  except:  except:
400          pass          pass
401    try:
402            description = urllib.unquote_plus(params["description"])
403    except:
404            pass
405    
406    try:
407            open_url("http://todic.dk")
408    except:
409            showMessage("Fejl", "Kunne ikke forbinde til todic.dk")
410            exit()
411                            
412    
413  if mode == None:  if url == 'refresh':
414            #xbmc.output("[tvserver] Container.Refresh") #20130418 xbmc.output virker ikke med XBMC12
415            xbmc.executebuiltin("Container.Refresh")
416            
417    
418    elif mode == None:
419          #build main menu          #build main menu
420          rootMenu()          rootMenu()
421                
# Line 216  elif mode == 1: Line 425  elif mode == 1:
425    
426  elif mode == 10:  elif mode == 10:
427          search()          search()
428    
429    elif mode == 11:
430            searchSeries()
431                    
432    
433  elif mode == 50:  elif mode == 50:
434          play_video(url, name)          play_video(url, name, description)
435    
436    
437    
 # xbmcplugin.endOfDirectory(int(sys.argv[1]))  
438    

Legend:
Removed from v.1676  
changed lines
  Added in v.2596

  ViewVC Help
Powered by ViewVC 1.1.20