Re: need API doc to develop a radio client
Assen Totin <[email protected]>
| Newsgroups | gmane.comp.audio.icecast.devel |
|---|---|
| Message-ID | <CAMrYpX4DGi5aDOUvOVqjBZ1iHfSgnybXGYF-1qf3h7ozugsx8A@mail.gmail.com> |
Hi, Can you please share a sample code which fetches the station list from the > Icecast server and can play a station. > I am attaching a very basic, bare-bone example in Python which: - fetches the XML file - converts it into a DOM object - loops over it, extracting for each station it's server name, URL, bitrate and genre. To play a URL, just feed it to the underlying player. There are many other interesting things you can do from here on, like build a local cache, make a search by genre - and even avoid some caveats like broken UTF or HTML escaped characters in names and URLs etc. For a full-featured example, you can check out this project: svn:// svn.online.bg/plugin.audio.icecast/TRUNK - this is an Icecast plugin for XBMC media centre. It is Python and uses XBMC as a player. It stores the station list locally (either plain text file or SQLite) and auto-updates it at certain intervals; has a search; a favourites list; a recently listened list etc. It also deals with HTML escaped characters in names and URLs. More detaled description is here: http://bilbo.online.bg/~assen/icecast-addon/ Following the concept you can write the same virtually in any language (Python was chosen because I wanted to write an XBMC add-on and XBMC add-ons are only written in Python). If you prefer Java, I have the same player made for Android, check out the code here: svn://svn.online.bg/android-icecast-player (an Eclipse project) and see a description here: http://bilbo.online.bg/~assen/icecast-android . It does not differ much, but uses Android's built-in player. It only uses SQLite (no plain-text storage). The biggest non-Icecast feature here is the circle menu, which was custom built for the project. WWell, Assen _______________________________________________ Icecast-dev mailing list [email protected] http://lists.xiph.org/mailman/listinfo/icecast-dev
example.py
(application/octet-stream, 1.4 KB)
from xml.dom import minidom
import urllib2
BASE_URL = 'http://dir.xiph.org/yp.xml'
CHUNK_SIZE = 65536
str_list = []
xml = ''
response = urllib2.urlopen(BASE_URL);
while 1:
chunk = response.read(CHUNK_SIZE)
if not chunk: break
str_list.append(chunk)
response.close()
xml = ''.join(str_list)
dom = minidom.parseString(xml)
entries = dom.getElementsByTagName("entry")
for entry in entries:
server_name_objects = entry.getElementsByTagName("server_name")
for server_name_object in server_name_objects:
server_name = getText(server_name_object.childNodes)
genre_objects = entry.getElementsByTagName("genre")
for genre_object in genre_objects:
genre_name = getText(genre_object.childNodes)
listen_url_objects = entry.getElementsByTagName("listen_url")
for listen_url_object in listen_url_objects:
listen_url = getText(listen_url_object.childNodes)
bitrate_objects = entry.getElementsByTagName("bitrate")
for bitrate_object in bitrate_objects:
bitrate = getText(bitrate_object.childNodes)
# At this ponit you have all the data for the station:
#
# server_name - the server's name
# genre_name - the genre (one or more keywords)
# listen_url - the URL of the stream
# bitrate - the bitrate of the stream
#
# You can now store these, or build hashes from them etc.
# To play the URL, just feed the listen_url to the player