Random ...
 
December 2017
S M T W T F S
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Tags ...
Links



python+zope++:: icecast2, ices and python: streamingly good combo
Posted at 16.Jul,2006 11:14  Comments 0 / Trackbacks 0 / Like this post!
Technorati tag(s):

Want to stream audio? This can be easily done with icecast2.

I had some problem initially, mostly because I didn't get how streaming with icecast2 works.

The gist of it is::

  • have the streaming server on - icecast2
  • stream the audio - with ices2/ices/etcc
  • prepare the dynamic playlist - python (or perl)

Get icecast2 tarball or binaries and install. In my case, it's just an apt-get install and away we go.

Customize the config file (icecast.xml); port to listen to, number of clients, yadda yadda..

Now get the streamer. There's ices2 and ices0. Since I want to stream mp3s, ices2 is out of the question. I downloaded ices-0.4, compiled and got an error. It seemed that the libshout header is in a different location.Fixed that and the compile went flawlessly.

We can use python to dynamically set playlist. If we want to entertain requests, we can set a queue and play the requests, if there's any.

Here's my simple python playlist:

 from string import *
 import sys, random, os

 # This is just a skeleton, something for you to start with.

 songnumber = -1

 # Function called to initialize your python environment.
 # Should return 1 if ok, and 0 if something went wrong.
 def ices_init ():
        print 'Executing initialize() function..'
        return 1

 # Function called to shutdown your python enviroment.
 # Return 1 if ok, 0 if something went wrong.
 def ices_shutdown ():
        print 'Executing shutdown() function...'
        return 1

 # Function called to get the next filename to stream.
 # Should return a string.
 def ices_get_next ():
        print 'Executing get_next() function...'
        #check for queued songs
        song = check4queued()
        if song:
            return song
        #randomly get from playlist
        else:
            return getFromPlaylist()

 def getFromPlaylist():
        f=open('playlist.txt').readlines()
        song = random.choice(f)
        return song.strip()

 def check4queued():
        l=os.listdir('q')
        if len(l) > 0:
            song = l[0].strip()
            s = open('q/'+song).read().strip()
            os.unlink('q/'+song)
            return s

 # This function, if defined, returns the string you'd like used
 # as metadata (ie for title streaming) for the current song. You may
 # return null to indicate that the file comment should be used.
 def ices_get_metadata ():
        #return 'Artist - Title (Label, Year)'
        return None

Now, I just need to tie the requests queue with a user interface; either web, mail, etc.

Oh, if you want to, have a listen at 1 (weekends) or at 2 (weekdays).

The stream may bnot even run though. So, good luck!


Bookmark and Share

Is this entry helpful? Comments/Donate/Click some google ads.  
Trackback is http://myzope.kedai.com.my/blogs/kedai/91/tbping 

Comments
Post a comment