]> git.parisson.com Git - deefuzzer.git/commitdiff
add yaml conf file parsing + xml2yaml converter
authorGuillaume Pellerin <yomguy@parisson.com>
Sun, 14 Jul 2013 08:24:05 +0000 (10:24 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Sun, 14 Jul 2013 08:24:05 +0000 (10:24 +0200)
deefuzzer/core.py
deefuzzer/station.py
deefuzzer/tools/player.py
example/telecaster_audio_monitor.yaml [new file with mode: 0644]
scripts/dev/xml2yaml.py [new file with mode: 0755]

index f9ff7e82c0004a2e083229074d295752a4b5d300..2eb55830e59c408515e67690378651524778588c 100755 (executable)
@@ -76,9 +76,15 @@ class DeeFuzzer(Thread):
 
     def get_conf_dict(self):
         confile = open(self.conf_file,'r')
-        conf_xml = confile.read()
+        filename, ext = os.path.splitext(self.conf_file)
+        data = confile.read()
         confile.close()
-        return xmltodict(conf_xml,'utf-8')
+
+        if 'xml' in ext:
+            return xmltodict(data,'utf-8')
+        elif 'yaml' in ext:
+            import yaml
+            return yaml.load(data)
 
     def set_m3u_playlist(self):
         m3u_dir = os.sep.join(self.m3u.split(os.sep)[:-1])
index 42b646f95cfa02d86c7fe329b99e4452178e8e93..a243be4097450e10b970bd013f16b262738d3052 100644 (file)
@@ -75,24 +75,26 @@ class Station(Thread):
         self.voices = self.station['media']['voices']
 
         # Server
-        self.short_name = self.station['infos']['short_name']
+        if 'mountpoint' in self.station['server'].keys():
+            self.mountpoint = self.station['server']['mountpoint']
+        elif 'short_name' in self.station['infos'].keys():
+            self.mountpoint = self.station['infos']['short_name']
+        else:
+            self.mountpoint = 'default'
+
+        self.short_name = self.mountpoint
 
         if 'type' in self.station['server']:
             self.type = self.station['server']['type'] #  'icecast' | 'stream-m'
 
-        if self.type == 'stream-m':
-            self.mount = '/publish/' + self.short_name
-        elif self.type == 'icecast':
-            self.mount = '/' + self.short_name
-        else:
-            self.mount = '/' + self.short_name
-
         if 'stream-m' in self.type:
             self.channel = HTTPStreamer()
-            self.channel.mount = self.mount
-        else:
+            self.channel.mount = '/publish/' + self.mountpoint
+        elif 'icecast' in self.type:
             self.channel = shout.Shout()
-            self.channel.mount = self.mount + '.' + self.media_format
+            self.channel.mount = '/' + self.mountpoint + '.' + self.media_format
+        else:
+            sys.exit('Not a compatible server type. Choose "stream-m" or "icecast".')
 
         self.channel.url = self.station['infos']['url']
         self.channel.name = self.station['infos']['name'] + ' : ' + self.channel.url
@@ -106,10 +108,10 @@ class Station(Thread):
         self.channel.public = int(self.station['server']['public'])
         self.channel.genre = self.station['infos']['genre']
         self.channel.description = self.station['infos']['description']
-        self.channel.audio_info = { 'bitrate': self.bitrate,
-                                    'samplerate': self.samplerate,
-                                    'quality': self.ogg_quality,
-                                    'channels': self.voices,}
+        self.channel.audio_info = { 'bitrate': str(self.bitrate),
+                                    'samplerate': str(self.samplerate),
+                                    'quality': str(self.ogg_quality),
+                                    'channels': str(self.voices),}
 
         self.server_url = 'http://' + self.channel.host + ':' + str(self.channel.port)
         self.channel_url = self.server_url + self.channel.mount
index d05151703f9545e1d765a459153667c9db7fcf1d..1be33c2ff360f796e9c8dcb5c9947bba5f153a06 100644 (file)
@@ -50,7 +50,7 @@ class Player:
             self.main_buffer_size = 0x100000
             self.relay_queue_size = 0x100000
             self.sub_buffer_size = 0x10000
-        
+
     def set_media(self, media):
         self.media = media
 
@@ -108,6 +108,7 @@ class Player:
 
 
 class FileReader:
+
     def __init__(self, fp):
         self.fp = open(fp, 'r')
 
@@ -116,6 +117,7 @@ class FileReader:
 
 
 class URLReader:
+
     def __init__(self, relay):
         self.relay = urllib.urlopen(relay)
         self.rec_mode = 0
diff --git a/example/telecaster_audio_monitor.yaml b/example/telecaster_audio_monitor.yaml
new file mode 100644 (file)
index 0000000..0e45d94
--- /dev/null
@@ -0,0 +1,25 @@
+deefuzzer:
+  log: /var/log/telecaster/telecaster_audio_monitor.log
+  m3u: /var/www/m3u/telecaster_audio_monitor.m3u
+  station:
+    control: {mode: 0, port: 1236}
+    infos: {description: TeleCaster MP3 monitor,
+            genre: Vocal,
+            name: telecaster_mp3_monitor,
+            url: 'http://parisson.com.com'}
+    jingles: {dir: /path/to/jingles, mode: 0, shuffle: 1}
+    media: {bitrate: 96,
+            dir: /home/telecaster/media/mp3,
+            format: mp3, ogg_quality: 4,
+            samplerate: 48000, shuffle: 0, voices: '2'}
+    record: {dir: /home/telecaster/trash/mp3, mode: 1}
+    relay: {author: Inconnu, mode: 1,
+            url: 'http://127.0.0.1:8000/telecaster_live.mp3'}
+    rss: {dir: /var/www/rss, enclosure: 0,
+          media_url: 'http://my.domain.com/rss/'}
+    server: {host: 127.0.0.1, mountpoint: telecaster_mp3_monitor,
+             port: 8000, public: 0,
+             sourcepassword: source2parisson, type: icecast}
+    twitter: {key: 76728330-OjKgbHtn4II86Ad7pNUGEzfNAkGTW5Wvw38qUmLE,
+              mode: 0, secret: 4egZs1dSM37XVY8zXa016Yueku2fleXF2bx8k25V4,
+              tags: bla bla}
diff --git a/scripts/dev/xml2yaml.py b/scripts/dev/xml2yaml.py
new file mode 100755 (executable)
index 0000000..bcc0174
--- /dev/null
@@ -0,0 +1,61 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2013 Guillaume Pellerin
+
+# <yomguy@parisson.com>
+
+# This software is a computer program whose purpose is to stream audio
+# and video data through icecast2 servers.
+
+# This software is governed by the CeCILL license under French law and
+# abiding by the rules of distribution of free software. You can use,
+# modify and/ or redistribute the software under the terms of the CeCILL
+# license as circulated by CEA, CNRS and INRIA at the following URL
+# "http://www.cecill.info".
+
+# As a counterpart to the access to the source code and  rights to copy,
+# modify and redistribute granted by the license, users are provided only
+# with a limited warranty and the software's author, the holder of the
+# economic rights, and the successive licensors have only limited
+# liability.
+
+# In this respect, the user's attention is drawn to the risks associated
+# with loading, using,  modifying and/or developing or reproducing the
+# software by the user in light of its specific status of free software,
+# that may mean that it is complicated to manipulate, and that also
+# therefore means that it is reserved for developers and  experienced
+# professionals having in-depth computer knowledge. Users are therefore
+# encouraged to load and test the software's suitability as regards their
+# requirements in conditions enabling the security of their systems and/or
+# data to be ensured and, more generally, to use and operate it in the
+# same conditions as regards security.
+
+# The fact that you are presently reading this means that you have had
+# knowledge of the CeCILL license and that you accept its terms.
+
+# Author: Guillaume Pellerin <yomguy@parisson.com>
+
+
+import sys
+from deefuzzer.tools.xmltodict import *
+
+
+class XML2Various(object):
+
+    def __init__(self, xml_str):
+        self.dict = xmltodict(xml_str, 'utf-8')
+
+    def to_yaml(self):
+        import yaml
+        return yaml.dump(self.dict)
+
+
+if __name__ == '__main__':
+    xml_file = open(sys.argv[-2], 'r')
+    yaml_file = open(sys.argv[-1], 'w')
+    yaml_file.write(XML2Various(xml_file.read()).to_yaml())
+    xml_file.close()
+    yaml_file.close()
+
+