import shout
import Queue
import datetime
+import mimetypes
from threading import Thread
from deefuzzer.station import *
from deefuzzer.tools import *
+mimetypes.add_type('application/x-yaml','.yaml')
+
class DeeFuzzer(Thread):
"""a DeeFuzzer diffuser"""
Thread.__init__(self)
self.conf_file = conf_file
self.conf = self.get_conf_dict()
- if 'log' in self.conf['deefuzzer'].keys():
- self.logger = Logger(self.conf['deefuzzer']['log'])
- else:
- self.logger = Logger('.' + os.sep + 'deefuzzer.log')
- if 'm3u' in self.conf['deefuzzer'].keys():
- self.m3u = self.conf['deefuzzer']['m3u']
- else:
- self.m3u = '.' + os.sep + 'deefuzzer.m3u'
-
+
+ for key in self.conf['deefuzzer'].keys():
+ if key == 'log':
+ self.logger = Logger(self.conf['deefuzzer']['log'])
+ if key == 'm3u':
+ self.m3u = self.conf['deefuzzer']['m3u']
+ else:
+ setattr(self, key, self.conf['deefuzzer'][key])
+
if isinstance(self.conf['deefuzzer']['station'], dict):
# Fix wrong type data from xmltodict when one station (*)
self.nb_stations = 1
self.logger.write_info('Number of stations : ' + str(self.nb_stations))
def get_conf_dict(self):
+ mime_type = mimetypes.guess_type(self.conf_file)[0]
confile = open(self.conf_file,'r')
- filename, ext = os.path.splitext(self.conf_file)
data = confile.read()
confile.close()
- if 'xml' in ext:
+ if 'xml' in mime_type:
return xmltodict(data,'utf-8')
- elif 'yaml' in ext:
+ elif 'yaml' in mime_type:
import yaml
return yaml.load(data)
+ elif 'json' in mime_type:
+ import json
+ return json.loads(data)
def set_m3u_playlist(self):
m3u_dir = os.sep.join(self.m3u.split(os.sep)[:-1])
--- /dev/null
+{
+ "deefuzzer": {
+ "log": "mystation.log",
+ "m3u": "mystation.m3u",
+ "station": {
+ "control": {
+ "mode": 0,
+ "port": 16001
+ },
+ "infos": {
+ "description": "my_station",
+ "genre": "music",
+ "name": "my_station",
+ "url": "http://parisson.com"
+ },
+ "jingles": {
+ "dir": "/path/to/jingles",
+ "mode": 0,
+ "shuffle": 1
+ },
+ "media": {
+ "bitrate": 96,
+ "dir": "/path/to/mp3/",
+ "format": "mp3",
+ "m3u": "/path/to/m3u_file",
+ "ogg_quality": 4,
+ "samplerate": 48000,
+ "shuffle": 0,
+ "voices": "2"
+ },
+ "record": {
+ "dir": "/home/telecaster/archives/mp3",
+ "mode": 0
+ },
+ "relay": {
+ "author": "Inconnu",
+ "mode": 0,
+ "url": "http://127.0.0.1:8000/telecaster_live.mp3"
+ },
+ "rss": {
+ "dir": "/var/www/rss",
+ "enclosure": 0,
+ "media_url": "http://localhost/rss/"
+ },
+ "server": {
+ "host": "127.0.0.1",
+ "mountpoint": "monitor",
+ "port": 8000,
+ "public": 0,
+ "sourcepassword": "source2parisson",
+ "type": "icecast"
+ },
+ "twitter": {
+ "key": "76728330-OjKgbHtn4II86Ad7pNUGEzfNAkGTW5Wvw38qUmLE",
+ "mode": 0,
+ "secret": "4egZs1dSM37XVY8zXa016Yueku2fleXF2bx8k25V4",
+ "tags": "bla bla"
+ }
+ }
+ }
+}
\ No newline at end of file