def get_station_names(self):
return self.conf['station']['name']
- def start(self):
+ def play(self):
if isinstance(self.conf['deefuzz']['station'], dict):
# Fix wrong type data from xmltodict when one station (*)
nb_stations = 1
else:
nb_stations = len(self.conf['deefuzz']['station'])
print 'Number of stations : ' + str(nb_stations)
-
+
# Create a Queue
q = Queue.Queue(0)
p = Producer(q)
p.start()
+ # Define the buffer_size
+ buffer_size = 65536/nb_stations
+
s = []
for i in range(0,nb_stations):
if isinstance(self.conf['deefuzz']['station'], dict):
station = self.conf['deefuzz']['station'][i]
name = station['infos']['name']
# Create a Station
- s.append(Station(station, q))
+ s.append(Station(station, q, buffer_size))
for i in range(0,nb_stations):
# Start the Stations
- s[i].start()
- time.sleep(0.1)
- pass
+ s[i].start()
class Producer(Thread):
def run(self):
q = self.q
i=0
- while 1 :
+ while 1:
#print "Producer produced one queue step: "+str(i)
self.q.put(i,1)
i+=1
class Station(Thread):
"""a DeeFuzz Station shouting slave thread"""
- def __init__(self, station, q):
+ def __init__(self, station, q, buffer_size):
Thread.__init__(self)
- self.q = q
self.station = station
- self.buffer_size = 16384
+ self.q = q
+ self.buffer_size = buffer_size
self.channel = shout.Shout()
self.id = 999999
self.counter = 0
}
self.channel.open()
self.playlist = self.get_playlist()
+ #print self.playlist
self.lp = len(self.playlist)
self.rand_list = range(0,self.lp-1)
print 'Opening ' + self.short_name + ' - ' + self.channel.name + \
' (' + str(self.lp) + ' tracks)...'
#print "Using libshout version %s" % shout.version()
- time.sleep(0.1)
+ time.sleep(0.5)
def update_rss(self, file_name):
self.media_url_dir = '/media/'
+ media_size = os.path.getsize(self.media_dir + os.sep + file_name)
+ media_link = self.channel.url + self.media_url_dir + file_name
rss = PyRSS2Gen.RSS2(
title = self.channel.name,
link = self.channel.url,
items = [
PyRSS2Gen.RSSItem(
title = file_name,
- link = self.channel.url + self.media_url_dir + file_name,
+ link = media_link
description = file_name,
- guid = PyRSS2Gen.Guid(self.channel.url + self.media_url_dir + file_name),
+ enclosure = PyRSS2Gen.Enclosure(media_link, str(media_size), 'audio/mpeg'),
+ guid = PyRSS2Gen.Guid(media_link),
pubDate = datetime.datetime(2003, 9, 6, 21, 31)),
])
file_list = []
for root, dirs, files in os.walk(self.media_dir):
for file in files:
- if '.'+self.channel.format in file and not '/.' in file:
+ s = file.split('.')
+ ext = s[len(s)-1]
+ if ext.lower() == self.channel.format and not '/.' in file:
file_list.append(root + os.sep + file)
return file_list
index = self.rand_list[self.id]
return playlist, playlist[index]
+ def log_queue(self, it):
+ print 'Station ' + self.short_name + ' eated one queue step: '+str(it)
def core_process(self, media, buffer_size):
"""Read media and stream data through a generator.
__chunk = 0
while True:
+ it = q.get(1)
if self.lp == 0:
break
if self.mode_shuffle == 1:
self.playlist, media = self.get_next_media_rand(self.playlist)
else:
self.playlist, media = self.get_next_media_lin(self.playlist)
-
self.counter += 1
+ q.task_done()
+ #self.log_queue(it)
+
if os.path.exists(media) and not '/.' in media:
- file_name = string.replace(media, self.media_dir + os.sep, '')
+ it = q.get(1)
+ file_name = string.replace(media, self.media_dir, '')
self.channel.set_metadata({'song': file_name})
- stream = self.core_process(media, self.buffer_size)
- print 'Deefuzzing this file on %s : id = %s, name = %s' % (self.short_name, self.id, file_name)
self.update_rss(file_name)
-
+ print 'Deefuzzing this file on %s : id = %s, name = %s' % (self.short_name, self.id, file_name)
+ stream = self.core_process(media, self.buffer_size)
+ q.task_done()
+ #self.log_queue(it)
+
for __chunk in stream:
it = q.get(1)
self.channel.send(__chunk)
self.channel.sync()
- # Get the queue
q.task_done()
- #print "Station eated one queue step: "+str(it)
+ #self.log_queue(it)
self.channel.close()
def main():
if len(sys.argv) == 2:
print "Deefuzz v"+version
- deefuzz_main = DeeFuzz(sys.argv[1])
- deefuzz_main.start()
+ d = DeeFuzz(sys.argv[1])
+ d.play()
else:
text = prog_info()
sys.exit(text)
<public>1</public>
</server>
<media>
- <dir>/home/momo/music/mp3/groovemaster_drums/</dir>
+ <dir>/home/momo/music/music2/mp3/Billy Cobham</dir>
<format>mp3</format>
<bitrate>192</bitrate>
<ogg_quality>7</ogg_quality>
<shuffle>1</shuffle>
</media>
</station>
- <station>
+ <station>
<infos>
<short_name>My_Station_2</short_name>
<name>My best funky station</name>
<public>1</public>
</server>
<media>
- <dir>/home/momo/music/mp3/groovemaster_drums/</dir>
+ <dir>/home/momo/music/music2/mp3/Billy Cobham</dir>
<format>mp3</format>
<bitrate>192</bitrate>
<ogg_quality>7</ogg_quality>
<shuffle>1</shuffle>
</media>
</station>
- <station>
+ <station>
<infos>
<short_name>My_Station_3</short_name>
<name>My best funky station</name>
<public>1</public>
</server>
<media>
- <dir>/home/momo/music/mp3/groovemaster_drums/</dir>
+ <dir>/home/momo/music/music2/mp3/Billy Cobham</dir>
<format>mp3</format>
<bitrate>192</bitrate>
<ogg_quality>7</ogg_quality>
<shuffle>1</shuffle>
</media>
</station>
- <station>
+ <station>
<infos>
<short_name>My_Station_4</short_name>
<name>My best funky station</name>
<public>1</public>
</server>
<media>
- <dir>/home/momo/music/mp3/groovemaster_drums/</dir>
+ <dir>/home/momo/music/music2/mp3/Billy Cobham</dir>
<format>mp3</format>
<bitrate>192</bitrate>
<ogg_quality>7</ogg_quality>
<shuffle>1</shuffle>
</media>
</station>
- <station>
+ <station>
<infos>
<short_name>My_Station_5</short_name>
<name>My best funky station</name>
<public>1</public>
</server>
<media>
- <dir>/home/momo/music/mp3/groovemaster_drums/</dir>
+ <dir>/home/momo/music/music2/mp3/Billy Cobham</dir>
<format>mp3</format>
<bitrate>192</bitrate>
<ogg_quality>7</ogg_quality>
<shuffle>1</shuffle>
</media>
</station>
- <station>
+ <station>
<infos>
<short_name>My_Station_6</short_name>
<name>My best funky station</name>
<public>1</public>
</server>
<media>
- <dir>/home/momo/music/mp3/groovemaster_drums/</dir>
+ <dir>/home/momo/music/music2/mp3/Billy Cobham</dir>
<format>mp3</format>
<bitrate>192</bitrate>
<ogg_quality>7</ogg_quality>
<shuffle>1</shuffle>
</media>
</station>
- <station>
+ <station>
<infos>
<short_name>My_Station_7</short_name>
<name>My best funky station</name>
<public>1</public>
</server>
<media>
- <dir>/home/momo/music/mp3/groovemaster_drums/</dir>
+ <dir>/home/momo/music/music2/mp3/Billy Cobham</dir>
<format>mp3</format>
<bitrate>192</bitrate>
<ogg_quality>7</ogg_quality>
<shuffle>1</shuffle>
</media>
</station>
- <station>
+ <station>
<infos>
<short_name>My_Station_8</short_name>
<name>My best funky station</name>
<public>1</public>
</server>
<media>
- <dir>/home/momo/music/mp3/groovemaster_drums/</dir>
+ <dir>/home/momo/music/music2/mp3/Billy Cobham</dir>
<format>mp3</format>
<bitrate>192</bitrate>
<ogg_quality>7</ogg_quality>