Package deefuzzer :: Package deefuzzer :: Module core
[hide private]
[frames] | no frames]

Source Code for Module deefuzzer.deefuzzer.core

  1  #!/usr/bin/python 
  2  # -*- coding: utf-8 -*- 
  3  # 
  4  # Copyright (C) 2006-2011 Guillaume Pellerin 
  5   
  6  # <yomguy@parisson.com> 
  7   
  8  # This software is a computer program whose purpose is to stream audio 
  9  # and video data through icecast2 servers. 
 10   
 11  # This software is governed by the CeCILL license under French law and 
 12  # abiding by the rules of distribution of free software. You can use, 
 13  # modify and/ or redistribute the software under the terms of the CeCILL 
 14  # license as circulated by CEA, CNRS and INRIA at the following URL 
 15  # "http://www.cecill.info". 
 16   
 17  # As a counterpart to the access to the source code and  rights to copy, 
 18  # modify and redistribute granted by the license, users are provided only 
 19  # with a limited warranty and the software's author, the holder of the 
 20  # economic rights, and the successive licensors have only limited 
 21  # liability. 
 22   
 23  # In this respect, the user's attention is drawn to the risks associated 
 24  # with loading, using,  modifying and/or developing or reproducing the 
 25  # software by the user in light of its specific status of free software, 
 26  # that may mean that it is complicated to manipulate, and that also 
 27  # therefore means that it is reserved for developers and  experienced 
 28  # professionals having in-depth computer knowledge. Users are therefore 
 29  # encouraged to load and test the software's suitability as regards their 
 30  # requirements in conditions enabling the security of their systems and/or 
 31  # data to be ensured and, more generally, to use and operate it in the 
 32  # same conditions as regards security. 
 33   
 34  # The fact that you are presently reading this means that you have had 
 35  # knowledge of the CeCILL license and that you accept its terms. 
 36   
 37  # Author: Guillaume Pellerin <yomguy@parisson.com> 
 38   
 39  import os 
 40  import shout 
 41  import Queue 
 42  import datetime 
 43  from threading import Thread 
 44  from deefuzzer.tools import * 
 45   
46 -class DeeFuzzer(Thread):
47 """a DeeFuzzer diffuser""" 48
49 - def __init__(self, conf_file):
50 Thread.__init__(self) 51 self.conf_file = conf_file 52 self.conf = self.get_conf_dict() 53 if 'log' in self.conf['deefuzzer'].keys(): 54 self.logger = Logger(self.conf['deefuzzer']['log']) 55 else: 56 self.logger = Logger('.' + os.sep + 'deefuzzer.log') 57 if 'm3u' in self.conf['deefuzzer'].keys(): 58 self.m3u = self.conf['deefuzzer']['m3u'] 59 else: 60 self.m3u = '.' + os.sep + 'deefuzzer.m3u' 61 62 if isinstance(self.conf['deefuzzer']['station'], dict): 63 # Fix wrong type data from xmltodict when one station (*) 64 self.nb_stations = 1 65 else: 66 self.nb_stations = len(self.conf['deefuzzer']['station']) 67 68 # Set the deefuzzer logger 69 self.logger.write_info('Starting DeeFuzzer') 70 self.logger.write_info('Using libshout version %s' % shout.version()) 71 72 # Init all Stations 73 self.stations = [] 74 self.logger.write_info('Number of stations : ' + str(self.nb_stations))
75
76 - def get_conf_dict(self):
77 confile = open(self.conf_file,'r') 78 conf_xml = confile.read() 79 confile.close() 80 return xmltodict(conf_xml,'utf-8')
81
82 - def set_m3u_playlist(self):
83 m3u_dir = os.sep.join(self.m3u.split(os.sep)[:-1]) 84 if not os.path.exists(m3u_dir): 85 os.makedirs(m3u_dir) 86 m3u = open(self.m3u, 'w') 87 m3u.write('#EXTM3U\n') 88 for s in self.stations: 89 info = '#EXTINF:%s,%s - %s\n' % ('-1',s.short_name, s.channel.name) 90 url = s.channel.protocol + '://' + s.channel.host + ':' + str(s.channel.port) + s.channel.mount + '\n' 91 m3u.write(info) 92 m3u.write(url) 93 m3u.close() 94 self.logger.write_info('Writing M3U file to : ' + self.m3u)
95 96
97 - def run(self):
98 q = Queue.Queue(1) 99 100 for i in range(0,self.nb_stations): 101 if isinstance(self.conf['deefuzzer']['station'], dict): 102 station = self.conf['deefuzzer']['station'] 103 else: 104 station = self.conf['deefuzzer']['station'][i] 105 self.stations.append(Station(station, q, self.logger, self.m3u)) 106 107 self.set_m3u_playlist() 108 p = Producer(q) 109 p.start() 110 111 # Start the Stations 112 for i in range(0,self.nb_stations): 113 self.stations[i].start()
114 115
116 -class Producer(Thread):
117 """a DeeFuzzer Producer master thread""" 118
119 - def __init__(self, q):
120 Thread.__init__(self) 121 self.q = q
122
123 - def run(self):
124 i=0 125 q = self.q 126 while True: 127 q.put(i,1) 128 i+=1
129