]> git.parisson.com Git - telemaster.git/commitdiff
fix wav streaming
authoryomguy <yomguy@353fd7da-fb10-4236-9bec-1a49139083f2>
Fri, 1 May 2009 08:52:41 +0000 (08:52 +0000)
committeryomguy <yomguy@353fd7da-fb10-4236-9bec-1a49139083f2>
Fri, 1 May 2009 08:52:41 +0000 (08:52 +0000)
git-svn-id: http://svn.parisson.org/svn/telemaster/trunk@5 353fd7da-fb10-4236-9bec-1a49139083f2

flac2mp3mix.py

index 37fa2cd4ba91269c520c92ee8ec8176040f2a7fa..69587f0ae15bb254bfacab0f22075f3be9a8e1f1 100644 (file)
@@ -4,32 +4,35 @@
 import os
 import sys
 import mutagen
+import subprocess
 
 class Flac2Mp3Mix:
 
     def __init__(self, argv):
-        self.root_dir = argv[0]
-        self.files, self.dirs, self.root = os.walk(self.root_dir)
+        self.root_dir = argv[1]
         self.buffer_size = 32768
         
     def flac_mix_player(self, media_list):
+        args = ''
         for media in media_list:
-            stream = self.core_process_stream(media)
-            for chunk in stream:
-                yield chunk
+            args += '"' + media + '" '
             
-    def core_process_stream(self, media):
-    """Read media and stream data through a generator.
-    Taken from Telemeta (see http://telemeta.org)"""
+        command = 'cat ' + args + ' | flac -d -c - '
+        print command
+        stream = self.core_process_stdout(command)
+        for chunk in stream:
+            yield chunk
 
-    command = 'flac -d -c "' + media + '"'
+    def core_process_stdout(self, command):
+        """Read media and stream data through a generator.
+        Taken from Telemeta (see http://telemeta.org)"""
 
-    proc = subprocess.Popen(command.encode('utf-8'),
-                shell = True,
-                bufsize = self.buffer_size,
-                stdin = subprocess.PIPE,
-                stdout = subprocess.PIPE,
-                close_fds = True)
+        proc = subprocess.Popen(command.encode('utf-8'),
+                    shell = True,
+                    bufsize = self.buffer_size,
+                    stdin = subprocess.PIPE,
+                    stdout = subprocess.PIPE,
+                    close_fds = True)
 
         # Core processing
         while True:
@@ -41,36 +44,47 @@ class Flac2Mp3Mix:
                 break
             yield __chunk
 
-    def 
+    def core_process_stdin(self, command, stream_in):
+        """Read media and stream data through a generator.
+        Taken from Telemeta (see http://telemeta.org)"""
 
-    
-def pyfapg():
-    host = 'audio.pre-barreau.com'
-    root_dir = '/home/pro-barreau/www/audio'
-    web_dir = '/'
-    types = ['mp3','ogg','flac']
+        proc = subprocess.Popen(command.encode('utf-8'),
+                    shell = True,
+                    bufsize = self.buffer_size,
+                    stdin = subprocess.PIPE,
+                    stdout = subprocess.PIPE,
+                    close_fds = True)
 
-    for root, dirs, files in os.walk(root_dir+web_dir):
-        #print root
-        for file in files:
-            file_split = file.split('.')
-            filename = file_split[len(file_split)-2]
-            #print filename
-            if not os.path.exists(root+os.sep+filename+'.m3u'):
-                fileext = file_split[len(file_split)-1]
-                if fileext in types :
-                    os.chdir(root_dir)
-                    prefix = 'http://'+host+'/'
-                    dest_dir = string.replace(root,'/home/pro-barreau/www/audio/','')
-                    file_new = string.replace(file,' ','_')
-                    filename_new = string.replace(filename,' ','_')
-                    if file_new != file:
-                        os.system('mv "'+dest_dir+os.sep+file+'" "'+dest_dir+os.sep+file_new+'"')
-                    os.system('fapg -f m3u -p '+prefix+' -o "'+root+os.sep+filename_new+'.m3u" "'+dest_dir+os.sep+file_new+'"')
+        # Core processing
+        for __chunk in stream_in:
+            proc.stdin.write(__chunk)
+            proc.stdin.flush()
+            status = proc.poll()
+            if status != None and status != 0:
+                raise DeeFuzzStreamError('Command failure:', command, proc)
+    
 
+    def get_media_lists(self):
+        full_media_list = []
+        for root, dirs, files in os.walk(self.root_dir):
+            media_list = []
+            if root:
+                for file in files:
+                    if file.split('.')[-1] == 'flac':
+                        media_list.append(root+os.sep+file)
+                full_media_list.append(media_list)
+        return full_media_list
 
-    
+    def main(self, file):
+        command = 'lame -b 256 - "' + file + '"'
+        media_lists = self.get_media_lists()
+        print media_lists
+        for media_list in media_lists:
+            raw_stream = self.flac_mix_player(media_list)
+            self.core_process_stdin(command, raw_stream)
+            
 
 if __name__ == '__main__':
-    t = Flac2Mp3Mix(sys.argv)
-    t.main()
+    f = Flac2Mp3Mix(sys.argv)
+    f.main('/tmp/test.mp3')
+