]> git.parisson.com Git - deefuzzer.git/commitdiff
* First generators...
authorGuillaume Pellerin <yomguy@parisson.com>
Fri, 7 Sep 2007 03:08:49 +0000 (03:08 +0000)
committerGuillaume Pellerin <yomguy@parisson.com>
Fri, 7 Sep 2007 03:08:49 +0000 (03:08 +0000)
d-fuzz.py
myfuzz.xml
tools.py

index 8dfac3e47acfe317db5b9758f5507ee64e9954fb..397395df96114512b9b3c25059ef6a2d2f4e7c55 100755 (executable)
--- a/d-fuzz.py
+++ b/d-fuzz.py
@@ -22,10 +22,12 @@ from mutagen.oggvorbis import OggVorbis
 class DFuzz:
     """A d-fuzz station"""
     
-    def __init__(self, conf_file):
-        self.conf_file = conf_file
+    def __init__(self):
+        
         self.work_dir = os.environ['HOME']+'.d-fuzz'
         self.conf = []
+        self.id = 0
+        self.buffer_size = 0xFFFF
         
         
     def prog_info(self):
@@ -49,9 +51,10 @@ class DFuzz:
         """
 
     def get_conf_dict(self):
-        conf = open(self.conf_file,'r')
-        conf_xml = conf.readlines()
+        confile = open(self.conf_file,'r')
+        conf_xml = confile.readlines()
         self.conf = xmltodict(conf_xml)
+        confile.close()
 
     def get_station_names(self):
         return self.conf['station']['name']
@@ -61,6 +64,10 @@ class DFuzz:
     def check_work_dir(self):
         if not os.isdir.exists(self.work_dir):
             os.mkdir(self.work_dir)
+    
+    def get_playlist_length(self):
+        pass
+        
 
     def get_playlist(self):
         file_list = []
@@ -68,108 +75,108 @@ class DFuzz:
             for file in files:
                 file_list.append(root + os.sep + file)
         return file_list
-                    
-
-
-    for i in range(1,nb_ch+1):
-        ch_name_i = radio_name+'_'+type+'_'+str(i)
-        ch_ice_name_i = radio_name+'_'+str(i)
-        ch_pre_i = work_dir+os.sep+ch_name_i
-        fi_xml = open(ch_pre_i+'.xml','w')
-        fi_xml.write('<ezstream>\n')
-       
-fi_xml.write('<url>http://'+server+':'+port+'/'+ch_ice_name_i+'.'+type+'</url>\
-n')
-        fi_xml.write('<format>'+string.upper(type)+'</format>\n')
-            fi_xml.write('<filetype>script</filetype>\n')
-            fi_xml.write('<filename>'+ch_pre_i+'.py</filename>\n')
-        for line in l_descr:
-            fi_xml.write(line)
-        fi_xml.write('</ezstream>')
-        fi_xml.close()
-        fi_py = open(ch_pre_i+'.py','w')
-        fi_py.write('#!/usr/bin/python\n\n')
-        fi_py.write('import sys, os, random\n\n')
-        fi_py.write('Playdir="'+audio_dir+os.sep+'"\n')
-        fi_py.write('IndexFile="'+ch_pre_i+'_index.txt"\n')
-       
-fi_py.write('RandomIndexListFile="'+ch_pre_i+'_random_index_list.txt"\n')
-       
-fi_py.write('PlaylistLengthOrigFile="'+ch_pre_i+'_playlist_length.txt"\n\n')
-        for line in l_tools:
-            fi_py.write(line)
-        fi_py.close()
-        os.chmod(work_dir+os.sep+ch_name_i+'.py',0755)
-
-    def stream(self, media_dir):
-        """Looped stream of the media_dir"""
-
-
-    for station in conf_dict['station']:
 
+    def get_next_media(self):
+        playlist = self.get_playlist()
+        lp = len(playlist)
+        if self.id > lp:
+            self.id = 0
+        else:
+            self.id = self.id + 1
+        yield playlist[self.id]
+    
+    
+
+    def core_process(self, command, buffer_size):
+        """Apply command and stream data through a generator. 
+        From Telemeta..."""
+        
+        __chunk = 0
+        #file_out = open(dest,'w')
+
+        try:
+            proc = subprocess.Popen(command,
+                    shell = True,
+                    bufsize = buffer_size,
+                    stdin = subprocess.PIPE,
+                    stdout = subprocess.PIPE,
+                    close_fds = True)
+        except:
+            raise ExportProcessError('Command failure:', command, proc)
+            
+
+        # Core processing
+        while True:
+            __chunk = proc.stdout.read(buffer_size)
+            status = proc.poll()
+            if status != None and status != 0:
+                raise ExportProcessError('Command failure:', command, proc)
+            if len(__chunk) == 0:
+                break
+            yield __chunk
+            #file_out.write(__chunk)
+
+        #file_out.close()
+
+    def stream(self, conf_file): 
+        self.conf_file = conf_file
+        self.get_conf_dict()
+#       for station in conf_dict['station']:
+        chi = 0
+        station = self.conf['station']
+        
         s = shout.Shout()
         print "Using libshout version %s" % shout.version()
-
-        s.host = self.server['host']
-        s.port = self.server['port']
+        
+        self.media_dir = station['media']['media_dir'][chi]
+        
+        s.host = station['server']['host'][chi]
+        s.port = station['server']['port'][chi]
         s.user = 'source'
-        s.password = self.conf['sourcepassword']
-        s.mount = self.mountpoint
-        s.format = self.conf['format']
+        s.password = station['server']['sourcepassword'][chi]
+        s.mount = station['server']['mountpoint'][chi]
+        s.format = station['media']['format'][chi]
         s.protocol = 'http'
         # | 'xaudiocast' | 'icy'
-        s.name = self.conf['name']
-        s.genre = self.conf['genre']
+        s.name = station['infos']['name']
+        s.genre = station['infos']['genre']
         # s.url = ''
         # s.public = 0 | 1
         # s.audio_info = { 'key': 'val', ... }
         #  (keys are shout.SHOUT_AI_BITRATE, shout.SHOUT_AI_SAMPLERATE,
         #   shout.SHOUT_AI_CHANNELS, shout.SHOUT_AI_QUALITY)
+        
+        
 
         s.open()
 
         total = 0
         st = time.time()
-        for fa in sys.argv[1:]:
-            print "opening file %s" % fa
-            f = open(fa)
-            s.set_metadata({'song': fa})
-
-            nbuf = f.read(4096)
-            while 1:
-                buf = nbuf
-                nbuf = f.read(4096)
-                total = total + len(buf)
-                if len(buf) == 0:
-                    break
-                s.send(buf)
-                s.sync()
-            f.close()
+        command = 'cat '
+        
+        for media in self.get_next_media():
+            print "opening file %s" % media
+            command = 'cat '+media_dir
+            stream = self.core_process(command, self.buffer_size)
+            #s.set_metadata({'song': fa})
             
+            for chunk in stream:
+                total = total + len(self.buffer_size)
+                s.send(chunk)
+                s.sync()
+                        
             et = time.time()
             br = total*0.008/(et-st)
             print "Sent %d bytes in %d seconds (%f kbps)" % (total, et-st, br)
 
         print s.close()
         
-        #os.system('d-fuzz_loop '+ch_pre_i+' &')
-        print ch_pre_i+' started !'
         
 
-
-class Stream:
-
-    def __init__(self):
-        self.buffer_size = 0xFFFF
-        
-    def process:
-        
-        if len(sys.argv) == 2:
-            station = DFuzz(sys.argv[1])
-        sys.exit('')
+if len(sys.argv) == 2:
+    station = DFuzz()
+    station.stream(sys.argv[1])
+else:
+    sys.exit('No way :(')
 
 
-        # Processing (streaming + cache writing)
-        stream = self.core_process(self.command,self.buffer_size,self.dest)
-        for chunk in stream:
-            yield chunk
index 5423f58167d0092c7a777b751a45f9c8aec4368c..f15936972a2eb35e48200de9d49a2b7fc7b99699 100644 (file)
@@ -24,7 +24,7 @@
         <public>1</public>
     </server>
     <media>
-        <media_dir>/home/momo/music/music3/mp3/Roger Troutman/</media_dir>
+        <media_dir>/mnt/data/Music/Air/</media_dir>
         <!-- mp3 or ogg -->
         <format>mp3</format>
         <bitrate>192</bitrate>
index cbe821b6d40ec678f54f7568441390be398aceb1..74d191a3ae0269e7aa4cc6d5f4e5ea8571cd7c5f 100755 (executable)
--- a/tools.py
+++ b/tools.py
@@ -16,58 +16,3 @@ def randrange(start, stop):
 
 
 
-
-#print nf
-
-fill=open(PlaylistLengthOrigFile,'rw')
-
-nforig=int(fill.readline())
-
-if not nf == nforig:
-       fil=open(RandomIndexListFile,'w')
-       ril=randrange(0,nf)
-       #print ril
-       k=1
-       for i in ril:
-               fil.write("%d\n" % (i))
-#      fil.close()
-
-fi=open(IndexFile,'rw')
-fil=open(RandomIndexListFile,'rw')
-
-#print nforig
-if nforig < nf:
-       nforig = nf
-
-f_index=int(fi.readline())
-
-#tmpil = fil.readlines()
-f_index_list = range(nforig)
-j = 0
-for i in fil.readlines():
-       f_index_list[j] = int(i)
-       j+=1
-       #print f_index_list[j]
-
-fi.close()
-fil.close()
-fill.close()
-
-if f_index == nf or f_index > nf:
-       f_index = 0
-
-#print f_index_list[f_index]
-#print f_index
-print Playdir + playlist[f_index_list[f_index]]
-
-f_index+=1
-
-fi = open(IndexFile,'w')
-fi.write("%d" % (f_index))
-fi.close()
-
-fill=open(PlaylistLengthOrigFile,'w')
-fill.write("%d" % (nf))
-fill.close()
-
-