The branch, dharma has been updated
via 1f8ebaae10981321c744bcd94b5edc934661e9cf (commit)
from d9256152d9db6309a442c99bb62e0fdae877045d (commit)
- Log -----------------------------------------------------------------
http://xbmc.git.sourceforge.net/git/gitweb.cgi?p=xbmc/plugins;a=commit;h=1f8ebaae10981321c744bcd94b5edc934661e9cf
commit 1f8ebaae10981321c744bcd94b5edc934661e9cf
Author: spiff <[email protected]>
Date: Tue Feb 28 10:08:01 2012 +0100
[plugin.audio.sverigesradio] updated to version 0.0.4
diff --git a/plugin.audio.sverigesradio/addon.xml
b/plugin.audio.sverigesradio/addon.xml
index 2669c43..8cf1caf 100644
--- a/plugin.audio.sverigesradio/addon.xml
+++ b/plugin.audio.sverigesradio/addon.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.audio.sverigesradio"
name="Sveriges Radio"
- version="0.0.3"
- provider-name="Popeye">
+ version="0.0.4"
+ provider-name="Popeye, Daniel">
<requires>
<import addon="xbmc.python" version="1.0"/>
</requires>
diff --git a/plugin.audio.sverigesradio/default.py
b/plugin.audio.sverigesradio/default.py
index 589181f..f946166 100644
--- a/plugin.audio.sverigesradio/default.py
+++ b/plugin.audio.sverigesradio/default.py
@@ -1,17 +1,25 @@
+# coding: latin-1
import urllib2
import xbmcgui
import xbmcplugin
+import xbmcaddon
from xml.dom.minidom import parse, parseString
-MAIN_URL = "http://api.sr.se/api/channels/channels.aspx"
+CHANNEL_URL = "http://api.sr.se/api/channels/channels.aspx"
+PROGRAM_LIST_URL = "http://api.sr.se/api/program/programfeed.aspx"
+PROGRAM_DETAIL_URL = "http://api.sr.se/api/program/broadcastfeed.aspx?unitid="
+BASE_URL = "http://sr.se"
+
+__settings__ = xbmcaddon.Addon(id='plugin.audio.sverigesradio')
def list_channels():
- doc, state = load_xml(MAIN_URL)
+ doc, state = load_xml(CHANNEL_URL)
if doc and not state:
for channel in doc.getElementsByTagName("channel"):
title = channel.getAttribute("name").encode('utf_8')
+ originaltitle = title
logo = get_node_value(channel, "logo")
description = get_node_value(channel, "tagline")
if description:
@@ -28,35 +36,117 @@ def list_channels():
stream = url.childNodes[0].data
if type == "m4a" and quality == "high":
if logo:
- add_posts(title, stream, description, logo)
+ add_posts(title, stream, description, logo, album =
originaltitle, artist = 'Sveriges Radio')
else:
- add_posts(title, stream, description)
+ add_posts(title, stream, description, album =
originaltitle, artist = 'Sveriges Radio')
+ else:
+ if state == "site":
+ xbmc.executebuiltin('Notification("Sveriges Radio","Site down")')
+ else:
+ xbmc.executebuiltin('Notification("Sveriges Radio","Malformed
result")')
+ xbmcplugin.endOfDirectory(HANDLE)
+
+def list_programs(url):
+ doc, state = load_xml(PROGRAM_LIST_URL)
+ if doc and not state:
+ for program in doc.getElementsByTagName("item"):
+ title = get_node_value(program, "title").encode('utf_8')
+ description = get_node_value(program, "description")
+ if description:
+ description = description.encode('utf_8')
+ title = title + " - " + description
+ else:
+ description = ''
+ unitid = ""
+ unitid = get_node_value(program, "unitid").encode('utf_8')
+ add_posts(title, url + unitid + "/", isFolder=True)
+ else:
+ if state == "site":
+ xbmc.executebuiltin('Notification("Sveriges Radio","Site down")')
+ else:
+ xbmc.executebuiltin('Notification("Sveriges Radio","Malformed
result")')
+ xbmcplugin.endOfDirectory(HANDLE)
+
+def list_program(unitid):
+ doc, state = load_xml(PROGRAM_DETAIL_URL+unitid)
+ if doc and not state:
+ urlset = doc.getElementsByTagName("urlset")[0]
+ base = ""
+ for url in urlset.getElementsByTagName("url"):
+ type = url.getAttribute("type")
+ protocol = url.getAttribute("protocol")
+ quality = url.getAttribute("quality")
+ if type == "m4a" and protocol == "http" and quality == "high":
+ base = url.childNodes[0].data
+ if base == "":
+ base =
"http://sverigesradio.se/topsy/ljudfil/utan/statistik/[broadcastid].m4a"
+ xbmc.log("Couldn't find url template, go with known (" + base +
")")
+ for audio in doc.getElementsByTagName("item"):
+ for ondemand in audio.getElementsByTagName("ondemand"):
+ title =
ondemand.getAttribute("mainbroadcasttitle").encode('utf_8')
+ originaltitle = title
+ description =
ondemand.getAttribute("mainbroadcastdescription").encode('utf_8')
+ if description:
+ title = description
+ else:
+ description = ''
+ date =
ondemand.getAttribute("mainbroadcastdate").encode('utf_8')
+ if date:
+ title = title + " - " + date
+ else:
+ date = ''
+ thumb = ondemand.getAttribute("image").encode('utf_8')
+ if thumb:
+ thumb = BASE_URL + thumb
+ else:
+ thumb = ''
+ for broadcast in
ondemand.getElementsByTagName("broadcastfilename"):
+ broadcastid =
broadcast.getAttribute("broadcastid").encode('utf_8')
+ # broadcastname =
broadcast.childNodes[0].data.encode('utf_8')
+ url = base.replace("[broadcastid]", broadcastid)
+ add_posts(title, url, description, thumb, artist='Sveriges
Radio', album=originaltitle)
else:
if state == "site":
xbmc.executebuiltin('Notification("Sveriges Radio","Site down")')
else:
xbmc.executebuiltin('Notification("Sveriges Radio","Malformed
result")')
- xbmcplugin.endOfDirectory(int(sys.argv[1]))
+ xbmcplugin.endOfDirectory(HANDLE)
+
-def add_posts(title, url, description='', thumb=''):
+def add_posts(title, url, description='', thumb='', isPlayable='true',
isLive='true', isFolder=False, artist='',\
+ album=''):
+ title = title.replace("\n", " ")
listitem=xbmcgui.ListItem(title, iconImage=thumb)
- listitem.setInfo(type='music', infoLabels={ 'Title': title})
- listitem.setProperty('IsPlayable', 'true')
- listitem.setProperty('IsLive', 'true')
+ listitem.setInfo(type='music', infoLabels={'title': title, 'artist':
artist, 'album': album})
+ listitem.setProperty('IsPlayable', isPlayable)
+ listitem.setProperty('IsLive', isLive)
listitem.setPath(url)
- return xbmcplugin.addDirectoryItem(HANDLE, url, listitem)
+ return xbmcplugin.addDirectoryItem(HANDLE, url=url, listitem=listitem,
isFolder=isFolder)
+
+def add_main_menu():
+ listitem=xbmcgui.ListItem("Kanaler")
+ listitem.setInfo(type='music', infoLabels={ 'Title': "Kanaler"})
+ listitem.setPath('channels')
+ u = sys.argv[0] + "channels/"
+ xbmcplugin.addDirectoryItem(HANDLE, url=u, listitem=listitem,
isFolder=True)
+ listitem=xbmcgui.ListItem("Program A-Ã")
+ listitem.setInfo(type='music', infoLabels={ 'Title': "Program A-Ã"})
+ listitem.setPath('program')
+ u = sys.argv[0] + "programs/"
+ xbmcplugin.addDirectoryItem(HANDLE, url=u, listitem=listitem,
isFolder=True)
+ return xbmcplugin.endOfDirectory(HANDLE)
def get_node_value(parent, name, ns=""):
- if ns:
- if parent.getElementsByTagNameNS(ns, name) and \
- parent.getElementsByTagNameNS(ns,
name)[0].childNodes:
- return parent.getElementsByTagNameNS(ns,
name)[0].childNodes[0].data
- else:
- if parent.getElementsByTagName(name) and \
- parent.getElementsByTagName(name)[0].childNodes:
- return
parent.getElementsByTagName(name)[0].childNodes[0].data
- return None
+ if ns:
+ if parent.getElementsByTagNameNS(ns, name) and \
+ parent.getElementsByTagNameNS(ns, name)[0].childNodes:
+ return parent.getElementsByTagNameNS(ns,
name)[0].childNodes[0].data
+ else:
+ if parent.getElementsByTagName(name) and \
+ parent.getElementsByTagName(name)[0].childNodes:
+ return parent.getElementsByTagName(name)[0].childNodes[0].data
+ return None
def load_xml(url):
try:
@@ -76,6 +166,18 @@ def load_xml(url):
if (__name__ == "__main__" ):
+ MODE=sys.argv[0]
HANDLE=int(sys.argv[1])
- list_channels()
+ modes = MODE.split('/')
+ activemode = modes[len(modes) - 2]
+ parentmode = modes[len(modes) - 3]
+ if activemode == "programs" :
+ list_programs(MODE)
+ elif activemode == "channels" :
+ list_channels()
+ elif parentmode == "programs" :
+ list_program(activemode)
+ else :
+ add_main_menu()
+
-----------------------------------------------------------------------
Summary of changes:
plugin.audio.sverigesradio/addon.xml | 4 +-
plugin.audio.sverigesradio/default.py | 142 ++++++++++++++++++++++++++++-----
2 files changed, 124 insertions(+), 22 deletions(-)
hooks/post-receive
--
Plugins
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Xbmc-addons mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xbmc-addons