Skip to content

Instantly share code, notes, and snippets.

@queeup
Created January 16, 2012 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save queeup/92a1674bf852dfdb6a68 to your computer and use it in GitHub Desktop.
Save queeup/92a1674bf852dfdb6a68 to your computer and use it in GitHub Desktop.
example of playlist play on add-on
# -*- coding: utf-8 -*-
# Debug
Debug = False
# Imports
import re, urllib
import BeautifulSoup as BS
import xbmc, xbmcgui, xbmcplugin, xbmcaddon
__addon__ = xbmcaddon.Addon(id='plugin.video.el.diario')
__info__ = __addon__.getAddonInfo
__plugin__ = __info__('name')
__version__ = __info__('version')
__icon__ = __info__('icon')
__fanart__ = __info__('fanart')
__path__ = __info__('path')
__cachedir__ = __info__('profile')
__language__ = __addon__.getLocalizedString
__settings__ = __addon__.getSetting
MAIN_URL = 'http://www.antena3.com/videos/el-diario.html'
ROOT_URL = 'http://www.antena3.com'
class Main:
def __init__(self):
if ("action=play" in sys.argv[2]):
self.PLAY()
else:
self.LIST()
def LIST(self):
if Debug: self.LOG('\nLIST function')
url = BS.BeautifulSoup(urllib.urlopen(MAIN_URL).read(), parseOnlyThese=BS.SoupStrainer('ul', 'carrusel carruDetalle'))
soup = url.findAll('div')
for i in soup:
title = i.a['title']
link = ROOT_URL + i.a['href']
thumb = ROOT_URL + i.a.img['src']
if Debug: print title, link, thumb
listitem = xbmcgui.ListItem(title, iconImage="DefaultVideo.png", thumbnailImage=thumb)
listitem.setInfo(type="Video",
infoLabels={"Title" : title,
"Label" : title})
parameters = "%s?action=play&url=%s" % (sys.argv[ 0 ], urllib.quote_plus(link))
xbmcplugin.addDirectoryItems(int(sys.argv[1]), [(parameters, listitem, False)])
# TODO: Add more sorting methods
xbmcplugin.addSortMethod(handle=int(sys.argv[ 1 ]), sortMethod=xbmcplugin.SORT_METHOD_NONE)
# End of directory...
xbmcplugin.endOfDirectory(handle=int(sys.argv[ 1 ]), succeeded=True)
def PLAY(self):
if Debug: self.LOG('\nPLAY function')
# Get current list item details...
title = unicode(xbmc.getInfoLabel("ListItem.Title"), "utf-8")
thumbnail = xbmc.getInfoImage("ListItem.Thumb")
# Create Playlist video...
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
playlist.clear()
# only need to add label, icon and thumbnail, setInfo() and addSortMethod() takes care of label2
listitem = xbmcgui.ListItem(title, iconImage="DefaultVideo.png", thumbnailImage=thumbnail)
# set the key information
listitem.setInfo("Video", {"Title" : title,
"Label" : title})
# get unresolved url's for resolve it
url = urllib.urlopen(self.Arguments('url')).read()
link = ROOT_URL + re.findall("player_capitulo.xml='(.+?)';", url)[0]
xml = BS.BeautifulStoneSoup(urllib.urlopen(link).read())
root = xml.urlhttpvideo.string
for i in xml('multimedia'):
# resolved url's
videos = root + i.archivomultimedia.archivo.string
# add resolved url's to our playlist
playlist.add(videos)
# Play all videos...
xbmcPlayer = xbmc.Player()
xbmcPlayer.play(playlist)
def Arguments(self, arg):
Arguments = dict(part.split('=') for part in sys.argv[2][1:].split('&'))
return urllib.unquote_plus(Arguments[arg])
def LOG(self, description):
xbmc.log("[ADD-ON] '%s v%s': '%s'" % (__plugin__, __version__, description), xbmc.LOGNOTICE)
if __name__ == '__main__':
Main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment