--- misc/xbmc/plugin.video.todic/default.py 2012/05/06 16:21:11 1799 +++ misc/xbmc/plugin.video.todic/default.py 2013/01/18 11:36:20 1917 @@ -24,6 +24,7 @@ __key__ = __addon__.getSetting('xbmckey').lower() __backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__ fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'fanart.jpg') +datapath = xbmc.translatePath('special://profile/addon_data/plugin.video.todic/') class TodicPlayer(xbmc.Player): @@ -74,6 +75,11 @@ else: return nodelist[0].childNodes[0].nodeValue +def SaveFile(path, data): + file = open(path,'w') + file.write(data) + file.close() + def open_url(url): req = urllib2.Request(url) @@ -104,7 +110,7 @@ def buildList(url,title, endlist=True): - print '[TODIC]:'+str(url) + print '[TODIC]:'+str(url) link = open_url(url) doc = parseString(link) @@ -118,6 +124,7 @@ mode = '1' folder = True + entries = doc.getElementsByTagName("entry") l=len(entries) description = '' @@ -126,6 +133,11 @@ url = getText( entry.getElementsByTagName("url") ) thumb = getText( entry.getElementsByTagName("cover") ) description = getText( entry.getElementsByTagName("description") ) + playcount = getText( entry.getElementsByTagName("playcount") ) + + if playcount == '': + playcount = '0' + playcount = int(playcount) name = name.encode('latin-1') description = description.encode('latin-1') @@ -141,7 +153,8 @@ if mode == '50': infoLabels = {} infoLabels['title'] = name - infoLabels['plot'] = description + infoLabels['plot'] = description + infoLabels['playcount'] = playcount listitem.setInfo('video', infoLabels) u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(name) + "&url=" + urllib.quote(url) @@ -155,17 +168,50 @@ def play_video(url, name): xml = open_url(url) + print 'TODIC url: ' + str(url) + print 'TODIC xml: '+ xml doc = parseString(xml) url = getText( doc.getElementsByTagName("url") ) - print '[TODIC]:'+str(url) + subtitleurl = getText( doc.getElementsByTagName("subtitles") ) + subtitlesfile = os.path.join(datapath,'temp.srt') + + #if old srt file exists delete it first + if os.path.isfile(subtitlesfile): + os.unlink(subtitlesfile) + + print '[TODIC] subs: '+str(subtitleurl) + if len(subtitleurl) > 0: + subtitles = open_url(subtitleurl) + SaveFile(subtitlesfile, subtitles) + print 'TODIC downloaded subtitles' + + + image = xbmc.getInfoImage( 'ListItem.Thumb' ) listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image) listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) player.play(str(url), listitem) + + #kan ikke loade subtitles hvis foerend playeren koerer + count = 0 + while not xbmc.Player().isPlaying(): + xbmc.sleep(500) + count += 1 + if count > 10: + break + + + if xbmc.Player().isPlaying(): + if os.path.isfile(subtitlesfile): + player.setSubtitles(subtitlesfile) + print 'TODIC started subtitles' + else: + player.disableSubtitles() + # player.callbackLoop() @@ -246,8 +292,12 @@ except: pass +if url == 'refresh': + xbmc.output("[tvserver] Container.Refresh") + xbmc.executebuiltin("Container.Refresh") + -if mode == None: +elif mode == None: #build main menu rootMenu()