The branch, eden has been updated
via e0641e6020bb60161b7c6023dad3df2faf9ea2a8 (commit)
from 0ce7acea13f61a5d2128f4d7b48bfa59c6cc140e (commit)
- Log -----------------------------------------------------------------
http://xbmc.git.sourceforge.net/git/gitweb.cgi?p=xbmc/plugins;a=commit;h=e0641e6020bb60161b7c6023dad3df2faf9ea2a8
commit e0641e6020bb60161b7c6023dad3df2faf9ea2a8
Author: spiff <[email protected]>
Date: Tue Mar 13 09:23:19 2012 +0100
[plugin.audio.npr] updated to version 2.1.0
diff --git a/plugin.audio.npr/README b/plugin.audio.npr/README
index 78ad486..e9a43d0 100644
--- a/plugin.audio.npr/README
+++ b/plugin.audio.npr/README
@@ -15,19 +15,6 @@ generate a new csv file if necessary.
= Installation =
-== Using the Zip Archive ==
-
-1. Download the "npr.zip" file. Remember where you downloaded
- it too.
-
-2. Navigate to: Settings --> Add-ons --> Install from Zip File
-
-3. Using the file chooser, navigate to where you downloaded
- the file and select "npr.zip". If all goes well a pop-up
- will inform you that the addon is installed and ready.
-
-== Using code from the Git Archive ==
-
1. Install Git on your local machine. See http://git-scm.com/ for
git installers and tutorials on how to use Git.
@@ -60,4 +47,3 @@ generate a new csv file if necessary.
This repo is originally a fork of the code from
http://xbmcnpr.googlecode.com/svn/trunk
-
diff --git a/plugin.audio.npr/addon.xml b/plugin.audio.npr/addon.xml
index c2bceee..fdf29c0 100644
--- a/plugin.audio.npr/addon.xml
+++ b/plugin.audio.npr/addon.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.audio.npr"
name="NPR (National Public Radio)"
- version="2.0.1"
+ version="2.1.0"
provider-name="Stieg, Fisslefink">
<requires>
<import addon="xbmc.python" version="2.0"/>
@@ -13,6 +13,6 @@
<extension point="xbmc.addon.metadata">
<platform>all</platform>
<summary lang="en">NPR (National Public Radio)</summary>
- <description lang="en">All available NPR streams.</description>
+ <description lang="en">All available NPR streams and most
podcasts.</description>
</extension>
</addon>
diff --git a/plugin.audio.npr/changelog.txt b/plugin.audio.npr/changelog.txt
index 25848b0..da53608 100644
--- a/plugin.audio.npr/changelog.txt
+++ b/plugin.audio.npr/changelog.txt
@@ -4,3 +4,4 @@ CHANGELOG for XBMC NPR Plugin (xbmcnpr)
1.1.0: Cleaned up icon. Name change (NPR --> npr) to conform to XBMC add-on
specs. Added All Songs Considered 24 hour stream.
1.2.0: Added KQED stream. Cleaned up some of the parsing code in default.py.
2.0.0: Added support for NPR API. Added all available NPR stations that
stream. Broke layout down by /state/station/stream. Added support for station
logo fetching.
+2.1.0: Addes support for basic NPR podcast streaming. Should cover the
majority of pod casts. Also updated stations cache and removed support for
"Newscasts" as these do not seem to be working just yet.
diff --git a/plugin.audio.npr/default.py b/plugin.audio.npr/default.py
index e2d3eb5..2853a98 100644
--- a/plugin.audio.npr/default.py
+++ b/plugin.audio.npr/default.py
@@ -1,19 +1,21 @@
-# *
-# * This Program is free software; you can redistribute it and/or modify
-# * it under the terms of the GNU General Public License as published by
-# * the Free Software Foundation; either version 2, or (at your option)
-# * any later version.
-# *
-# * This Program is distributed in the hope that it will be useful,
-# * but WITHOUT ANY WARRANTY; without even the implied warranty of
-# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# * GNU General Public License for more details.
-# *
-# * You should have received a copy of the GNU General Public License
-# * along with this program; see the file COPYING. If not, write to
-# * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-# * http://www.gnu.org/copyleft/gpl.html
-# *
+#
+# Copyright 2012 (stieg)
+#
+# This Program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This Program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING. If not, write to
+# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+# http://www.gnu.org/copyleft/gpl.html
+#
import xbmc,xbmcaddon,xbmcplugin,xbmcgui
@@ -106,6 +108,15 @@ def read_in_station_data(path):
return data
+def url_xml_to_etree(url):
+ '''
+ Given an URL, fetch the data and return an ElementTree object.
+ '''
+ data = urllib.urlopen(url)
+ tree = ElementTree()
+ tree.parse(data)
+
+ return tree
def get_station_data(sid = 0):
''' Acquire station data for the provided station ID '''
@@ -116,27 +127,56 @@ def get_station_data(sid = 0):
}
params = urllib.urlencode(query)
- data = urllib.urlopen(url + "?" + params)
+ url += '?' + params
+ return url_xml_to_etree(url)
+
+def strip_unsupported_podcast_urls(streams):
+ '''
+ Podcasts use a different XML schema. In fact, NPR seems to have
+ done a bad job of herding the cats into use of a common podcast data
+ format. Hence I am only supporting podcast data from
+ http://www.npr.org/templates/rss/podcast.php.
+ '''
+ url = 'http://www.npr.org/templates/rss/podcast.php'
+ keys = streams.keys()
+ for k in keys:
+ if streams[k].find(url) == -1:
+ del streams[k]
+
+def get_podcast_streams(tree):
+ '''
+ Gets the avalible podcasts from data read from
+ http://www.npr.org/templates/rss/podcast.php.
+ '''
+ streams = {}
- tree = ElementTree()
- tree.parse(data)
+ elist = tree.findall('channel/item')
+ for e in elist:
+ title = e.find('title').text
+ stream = e.find('guid').text
+ streams[title] = stream
- return tree
+ return streams
-def get_station_streams(tree):
- ''' Extract all station streams from etree of NPR station data '''
+def get_station_streams(tree, type_id):
+ '''
+ Extract all streams from etree of NPR station data based on the given type_id
+ 9 - Podcasts
+ 10 - Live Streams
+ 15 - Newscasts (doesn't seem to be working).
+ '''
streams = {}
elist = tree.findall('station/url')
+ type_id = str(type_id)
for e in elist:
url_id = e.get('typeId')
- if url_id == '10':
+ if url_id == type_id:
title = e.get('title')
text = e.text
streams[title] = text
return streams
-
def get_station_info(tree):
''' Extract general station info from etree of NPR station data '''
data = {}
@@ -158,7 +198,6 @@ def get_station_info(tree):
return data
-
def url_query_to_dict(url):
''' Returns the URL query args parsed into a dictionary '''
param = {}
@@ -170,7 +209,6 @@ def url_query_to_dict(url):
return param
-
def get_states_with_stations(stations):
''' Returns a dict of all available states '''
states = {}
@@ -179,12 +217,11 @@ def get_states_with_stations(stations):
if state:
state_full = __STATES.get(state)
if not state_full:
- state_full = 'Unknown'
+ state_full = 'Unknown'
states[state_full] = state
return states
-
def get_stations_in_state(stations, state):
''' Returns a dictionary of stations in the given state '''
state_st = {}
@@ -195,48 +232,76 @@ def get_stations_in_state(stations, state):
city = v.get('city')
tag = v.get('tagline')
if city is None:
- city = 'Unknown'
+ city = 'Unknown'
if tag is None or tag == 'None':
- tag = ''
+ tag = ''
else:
- tag = ' - ' + tag
+ tag = ' - ' + tag
name = "%s - %s%s" % (city, v.get('name'), tag)
state_st[name] = int(sid)
return state_st
+def list_streams(streams, url_id, title_prefix='', is_folder=False):
+ '''
+ Lists all streams in streams with the url_id as the key for the
+ handle. If title_prefix is defined, then prefix the entry string
+ with the provided prefix. If the entries need to be treated as a
+ folder, then set is_folder to True.
+ '''
+ keys = streams.keys()
+ keys.sort()
+ for k in keys:
+ stream = streams[k]
+ u = sys.argv[0] + '?' + urllib.urlencode({url_id:stream})
+ name = title_prefix + k
+ liz = xbmcgui.ListItem(name)
+ xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]),
+ url = u, listitem = liz,
+ isFolder = is_folder)
def main():
- stations = read_in_station_data(os.path.join(__home__, 'npr_stations.csv'))
params = url_query_to_dict(sys.argv[2])
+ podcast = params.get('podcast')
state = params.get('state')
stream = params.get('stream')
sid = params.get('id')
if stream:
# Play it.
+ stream = urllib.url2pathname(stream)
print ("Playing stream %s" % stream)
xbmc.Player().play(stream)
+
+ elif podcast:
+ # Show the avaialble Podcasts
+ podcast = urllib.url2pathname(podcast)
+ print("Podcast %s selected" % podcast)
+ tree = url_xml_to_etree(podcast)
+ pc_streams = get_podcast_streams(tree)
+ list_streams(pc_streams, 'stream', '', False)
+ xbmcplugin.endOfDirectory(int(sys.argv[1]))
+
elif sid:
# Display all streams for the station
print("Station #%s selected" % sid)
sd = get_station_data(sid)
- streams = get_station_streams(sd)
- keys = streams.keys()
- keys.sort()
- for k in keys:
- stream = streams[k]
- u = sys.argv[0] + "?stream=" + stream
- name = "Live Stream - %s" % k
- liz = xbmcgui.ListItem(name)
- xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]),
- url = u, listitem = liz,
- isFolder = False)
+
+ # First show the live streams
+ streams = get_station_streams(sd, 10)
+ list_streams(streams, 'stream', 'Stream - ', False)
+
+ # Next show the Podcasts
+ podcasts = get_station_streams(sd, 9)
+ strip_unsupported_podcast_urls(podcasts)
+ list_streams(podcasts, 'podcast', 'Podcast - ', True)
+
xbmcplugin.endOfDirectory(int(sys.argv[1]))
elif state:
# Display all stations in the state
print("State of %s selected" % state)
+ stations = read_in_station_data(os.path.join(__home__, 'npr_stations.csv'))
state_st = get_stations_in_state(stations, state)
keys = state_st.keys()
keys.sort()
@@ -249,8 +314,10 @@ def main():
url = u, listitem = liz,
isFolder = True)
xbmcplugin.endOfDirectory(int(sys.argv[1]))
+
else:
print("No state selected.")
+ stations = read_in_station_data(os.path.join(__home__, 'npr_stations.csv'))
states = get_states_with_stations(stations)
keys = states.keys()
keys.sort()
diff --git a/plugin.audio.npr/stations.py b/plugin.audio.npr/stations.py
old mode 100644
new mode 100755
index 4bb4d35..9255a9b
--- a/plugin.audio.npr/stations.py
+++ b/plugin.audio.npr/stations.py
@@ -1,4 +1,22 @@
-# FOO
+#!/usr/bin/python
+#
+# Copyright 2012 (stieg)
+#
+# This Program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This Program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING. If not, write to
+# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+# http://www.gnu.org/copyleft/gpl.html
+#
import csv, urllib, sys, time
from xml.etree.ElementTree import ElementTree
-----------------------------------------------------------------------
Summary of changes:
plugin.audio.npr/README | 14 ---
plugin.audio.npr/addon.xml | 4 +-
plugin.audio.npr/changelog.txt | 1 +
plugin.audio.npr/default.py | 153 ++++++++++++++++++-------
plugin.audio.npr/npr.org-station-info-example | 12 ++
plugin.audio.npr/stations.py | 20 +++-
6 files changed, 144 insertions(+), 60 deletions(-)
create mode 100644 plugin.audio.npr/npr.org-station-info-example
mode change 100644 => 100755 plugin.audio.npr/stations.py
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