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
32
33
34
35
36
37
38
39 import os
40 import shout
41 import Queue
42 import datetime
43 from threading import Thread
44 from deefuzzer.tools import *
45
47 """a DeeFuzzer diffuser"""
48
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
64 self.nb_stations = 1
65 else:
66 self.nb_stations = len(self.conf['deefuzzer']['station'])
67
68
69 self.logger.write_info('Starting DeeFuzzer')
70 self.logger.write_info('Using libshout version %s' % shout.version())
71
72
73 self.stations = []
74 self.logger.write_info('Number of stations : ' + str(self.nb_stations))
75
77 confile = open(self.conf_file,'r')
78 conf_xml = confile.read()
79 confile.close()
80 return xmltodict(conf_xml,'utf-8')
81
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
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
112 for i in range(0,self.nb_stations):
113 self.stations[i].start()
114
115
117 """a DeeFuzzer Producer master thread"""
118
120 Thread.__init__(self)
121 self.q = q
122
124 i=0
125 q = self.q
126 while True:
127 q.put(i,1)
128 i+=1
129