]> git.parisson.com Git - deefuzzer.git/commitdiff
add M3U feeding
authorGuillaume Pellerin <yomguy@parisson.com>
Thu, 16 Apr 2009 15:22:31 +0000 (15:22 +0000)
committerGuillaume Pellerin <yomguy@parisson.com>
Thu, 16 Apr 2009 15:22:31 +0000 (15:22 +0000)
deefuzz.py
example/deefuzz_xml_gen.py
example/myfuzz.xml

index 943a75c1208ae080052943d28c49797274843344..3c7841fa1442ea8d655dbce124f9f9a2afc6a05f 100755 (executable)
@@ -108,13 +108,33 @@ class DeeFuzz(Thread):
         Thread.__init__(self)
         self.conf_file = conf_file
         self.conf = self.get_conf_dict()
-
+        if 'log' in self.conf['deefuzz'].keys():
+            self.logger = Logger(self.conf['deefuzz']['log'])
+        else:
+            self.logger = Logger('.' + os.sep + 'deefuzz.log')
+        if 'm3u' in self.conf['deefuzz'].keys():
+            self.m3u = self.conf['deefuzz']['m3u']
+        else:
+            self.m3u = '.' + os.sep + 'deefuzz.m3u'
+            
     def get_conf_dict(self):
         confile = open(self.conf_file,'r')
         conf_xml = confile.read()
         confile.close()
         return xmltodict(conf_xml,'utf-8')
 
+    def set_m3u_playlist(self):
+        m3u = open(self.m3u, 'w')
+        i = 1
+        m3u.write('#EXTM3U\n')
+        for s in self.stations:
+            info = '#EXTINF:%s,%s' % (str(i), s.channel.name + ' (' + s.short_name + ')\n')
+            url =  s.channel.protocol + '://' + s.channel.host + ':' + str(s.channel.port) + s.channel.mount + '\n'
+            m3u.write(info)
+            m3u.write(url)
+            i += 1
+        m3u.close()
+
     def run(self):
         if isinstance(self.conf['deefuzz']['station'], dict):
             # Fix wrong type data from xmltodict when one station (*)
@@ -131,10 +151,6 @@ class DeeFuzz(Thread):
         p.start()
 
         # Set the deefuzz logger
-        if 'log' in self.conf['deefuzz'].keys():
-            self.logger = Logger(self.conf['deefuzz']['log'])
-        else:
-            self.logger = Logger('.' + os.sep + 'deefuzz.log')
         self.logger.write('Starting DeeFuzz v' + version)
         self.logger.write('Using libshout version %s' % shout.version())
 
@@ -143,7 +159,7 @@ class DeeFuzz(Thread):
         self.logger.write('Buffer size per station = ' + str(self.buffer_size))
 
         # Init all Stations
-        s = []
+        self.stations = []
         self.logger.write('Number of stations : ' + str(nb_stations))
         for i in range(0,nb_stations):
             if isinstance(self.conf['deefuzz']['station'], dict):
@@ -151,11 +167,15 @@ class DeeFuzz(Thread):
             else:
                 station = self.conf['deefuzz']['station'][i]
             # Create a Station
-            s.append(Station(station, q, self.buffer_size, self.logger))
+            self.stations.append(Station(station, q, self.buffer_size, self.logger))
 
+        # Create M3U playlist
+        self.logger.write('Writing M3U file to : ' + self.m3u)
+        self.set_m3u_playlist()
+        
         # Start the Stations
         for i in range(0,nb_stations):
-            s[i].start()
+            self.stations[i].start()
 
 
 class Producer(Thread):
@@ -206,6 +226,7 @@ class Station(Thread):
         self.channel.url = self.station['infos']['url']
         self.rss_current_file = self.rss_dir + os.sep + self.short_name + '_current.xml'
         self.rss_playlist_file = self.rss_dir + os.sep + self.short_name + '_playlist.xml'
+        self.m3u_playlist_file = self.rss_dir + os.sep + self.short_name + '.m3u'
         self.media_url_dir = '/media/'
         # Server
         self.channel.protocol = 'http'     # | 'xaudiocast' | 'icy'
index 15e474b78675ee55be6b27f32e4bfbf6adc1bdc6..26beb21d5d16074ca305f6c41300b977f894882c 100755 (executable)
@@ -1,4 +1,5 @@
 #!/usr/bin/python
+# -*- coding: utf-8 -*-
 
 import sys
 from string import Template
@@ -13,6 +14,7 @@ t = Template(df.read())
 
 dt.write('<deefuzz>\n')
 dt.write('    <log>/tmp/deefuzz.log</log>\n')
+dt.write('    <m3u>/tmp/deefuzz.m3u</m3u>\n')
 
 for i in range(0,int(nb_station)):
     xml = t.substitute(number='_'+str(i+1))
index 258ea7c3d1712c17a89379a6da962b21f89adc99..51fb68261ad8c2e2564e4116b470a1845441bc42 100644 (file)
@@ -1,5 +1,6 @@
 <deefuzz>
     <log>/tmp/deefuzz.log</log>
+    <m3u>/tmp/deefuzz.m3u</m3u>
     <station>
         <infos>
             <short_name>My_Station_1</short_name>