import Queue
import shout
import subprocess
-from shout import Shout
from tools import *
from threading import Thread
from mutagen.oggvorbis import OggVorbis
error)
class DeFuzz:
- """A DeFuzz station"""
+ """A DeFuzz diffuser"""
def __init__(self, conf_file):
self.conf_file = conf_file
else:
nb_stations = len(self.conf['defuzz']['station'])
print 'Number of stations : ' + str(nb_stations)
-
+
# Create a Queue
q = Queue.Queue(nb_stations)
+
+ # Create a Producer
p = Producer(q)
p.start()
+
s = []
-
for i in range(0,nb_stations):
if isinstance(self.conf['defuzz']['station'], dict):
station = self.conf['defuzz']['station']
else:
station = self.conf['defuzz']['station'][i]
- #print station
name = station['infos']['name']
+ # Create a Station
s.append(Station(station, q))
-
+
for i in range(0,nb_stations):
+ # Start the Stations
s[i].start()
time.sleep(0.1)
- #s[i].join()
pass
-
+
class Producer(Thread):
- """A DeFuzz Producer master thread"""
+ """a DeFuzz Producer master thread"""
def __init__(self, q):
Thread.__init__(self)
#print "Producer produced one queue step: "+str(i)
self.q.put(i,1)
i+=1
- #time.sleep(0.1)
class Station(Thread):
- """A DeFuzz Station shouting slave thread"""
+ """a DeFuzz Station shouting slave thread"""
def __init__(self, station, q):
Thread.__init__(self)
self.q = q
self.station = station
self.buffer_size = 16384
- #self.channel_id = channel_id
- self.channel = Shout()
+ self.channel = shout.Shout()
self.id = 999999
self.counter = 0
self.rand_list = []
self.channel.user = 'source'
self.channel.password = self.station['server']['sourcepassword']
self.channel.mount = '/' + self.short_name + '.' + self.channel.format
- #print self.channel.mount
self.channel.public = int(self.station['server']['public'])
# s.audio_info = { 'key': 'val', ... }
# (keys are shout.SHOUT_AI_BITRATE, shout.SHOUT_AI_SAMPLERATE,
def get_next_media_rand(self, playlist):
lp = len(playlist)
if self.id >= (lp - 1):
- #print 'Get random list...'
playlist = self.get_playlist()
lp_new = len(playlist)
if lp_new != lp or self.counter == 0:
self.rand_list = range(0,lp_new)
random.shuffle(self.rand_list)
- #print self.rand_list
self.id = 0
else:
self.id = self.id + 1
index = self.rand_list[self.id]
- #print str(self.id) +':'+ str(index)
return playlist, playlist[index]
def core_process(self, media, buffer_size):
if lp == 0:
break
if self.mode_shuffle == 1:
- #print 'Shuffle mode'
playlist, media = self.get_next_media_rand(playlist)
else:
playlist, media = self.get_next_media_lin(playlist)
+
self.counter += 1
-
if os.path.exists(media) and not '/.' in media:
file_name = string.replace(media, self.media_dir + os.sep, '')
self.channel.set_metadata({'song': file_name})
print 'Defuzzing this file on %s : id = %s, name = %s' % (self.short_name, self.id, file_name)
for __chunk in stream:
- # Get the queue
self.channel.send(__chunk)
self.channel.sync()
+ # Get the queue
it = q.get(1)
#print "Station eated one queue step: "+str(it)
-
self.channel.close()
--- /dev/null
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2006-2007 Guillaume Pellerin <yomguy@altern.org>
+#
+# 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 of the License, 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 Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+# ONLY FOR LINUX
+
+import os, sys
+
+if len(sys.argv) == 1:
+ install_dir = '/usr/share/defuzz/'
+elif len(sys.argv) > 2:
+ sys.exit('Give just one directory to install Telemeta, or none.')
+else:
+ install_dir = sys.argv[1]
+
+if not os.path.exists(install_dir):
+ os.mkdir(install_dir)
+
+os.system('cp -ra ./* '+install_dir+os.sep)
+os.system('rm -rf '+install_dir+os.sep+'debian')
+
+if os.path.exists('/usr/bin/defuzz'):
+ os.system('rm -r /usr/bin/defuzz')
+
+os.system('ln -s '+install_dir+os.sep+'defuzz.py '+'/usr/bin/fuzz')
+
+print """
+ Installation successfull !
+ Type 'defuzz' now...
+ """
+