]> git.parisson.com Git - telemeta.git/commitdiff
Fix sox arguments (14.2.0), remove metadata writing in OGG and MP3 post-process,...
authoryomguy <>
Mon, 15 Dec 2008 09:51:33 +0000 (09:51 +0000)
committeryomguy <>
Mon, 15 Dec 2008 09:51:33 +0000 (09:51 +0000)
debian/control
telemeta/export/core.py
telemeta/export/flac.py
telemeta/export/mp3.py
telemeta/export/ogg.py
telemeta/export/wav.py

index 60191786048600ad90ad4ee1b54692a9142b6813..000831e8316f8a5960e8b335da5d9938bface07d 100644 (file)
@@ -8,7 +8,7 @@ Standards-Version: 3.8.0
 
 Package: telemeta
 Architecture: any
-Depends: ${python:Depends}, python-xml, python-mutagen, python-django (>= 1.0-1), python-imaging (>= 1.1.6), sox, vorbis-tools, flac, normalize-audio, python-mysqldb, mysql-server, octave2.9, python-tk, libgd2-xpm, libsndfile1 (>= 1.0.17), python-numpy, python-ctypes (>= 1.0.1), python-scikits-audiolab (>= 0.7)
+Depends: ${python:Depends}, python-xml, python-mutagen, python-django (>= 1.0-1), python-imaging (>= 1.1.6), sox (>= 14.2.0-1), vorbis-tools, flac, normalize-audio, python-mysqldb, mysql-server, octave2.9, python-tk, libgd2-xpm, libsndfile1 (>= 1.0.17), python-numpy, python-ctypes (>= 1.0.1), python-scikits-audiolab (>= 0.7)
 Recommends: lame, vamp-examples
 Suggests: ecasound, festival, par2
 Description: web frontend to backup, transcode and publish any audio content with metadata
index 4474529d897883b1995d4d2661e48085ba6bab8a..a3d5129cf88bd0af658e94ec1c150a98b3c42fe0 100644 (file)
@@ -12,6 +12,7 @@
 
 import os
 import re
+import md5
 import string
 import subprocess
 import mutagen
@@ -74,15 +75,11 @@ class ExporterCore(Component):
         except IOError:
             return 'Exporter error: Cannot get the wav length...'
 
-    def compare_md5_key(self):
-        """ Compare 2 files wih md5 method """
-        in1, in2 = os.popen4('md5sum -b "'+self.source+'"')
-        out1, out2 = os.popen4('md5sum -b "'+self.dest+'"')
-        for line in in2.readlines():
-            line1 = line.split('*')[0]
-        for line in out2.readlines():
-            line2 = line.split('*')[0]
-        return line1 == line2
+    def compare_md5_key(self, source, dest):
+        """ Compare source and dest files wih md5 method """
+        f_source = open(source).read()
+        f_dest = open(dest).read()
+        return md5.new(f_source).digest() == md5.new(f_dest).digest()
 
     def write_metadata_xml(self,path):
         doc = xml.dom.minidom.Document()
@@ -170,7 +167,7 @@ class ExporterCore(Component):
     def post_process(self, item_id, source, metadata, ext, 
                      cache_dir, options=None):
         """ Post processing : write tags, print infos, etc..."""
-        self.write_tags()
+        #self.write_tags()
         if not options is None:
             if 'verbose' in self.options and self.options['verbose'] != '0':
                 print self.dest
index efac4fd9301cded5b971103ed6f8d1b6f17ee656..c7ff2ea91f7f6e1e9f7135b76c6a7eacec823a7e 100644 (file)
@@ -17,6 +17,7 @@ import subprocess
 from telemeta.export.core import *
 from telemeta.export.api import IExporter
 from mutagen.flac import FLAC
+from tempfile import NamedTemporaryFile
 
 class FlacExporter(ExporterCore):
     """Defines methods to export to FLAC"""
@@ -33,7 +34,7 @@ class FlacExporter(ExporterCore):
         self.quality_default = '5'
         self.info = []
         self.buffer_size = 0xFFFF
-        
+
     def get_format(self):
         return 'FLAC'
     
@@ -76,8 +77,8 @@ class FlacExporter(ExporterCore):
         except IOError:
             return 'ExporterError [2]: decoder not compatible.'
 
-    def write_tags(self):
-        media = FLAC(self.dest)
+    def write_tags(self, file):
+        media = FLAC(file)
         for tag in self.metadata.keys():
             if tag == 'COMMENT':
                 media['DESCRIPTION'] = str(self.metadata[tag])
@@ -115,8 +116,10 @@ class FlacExporter(ExporterCore):
         self.args = self.get_args(options)
         self.ext = self.get_file_extension()
         self.args = ' '.join(self.args)
-        self.command = 'sox "%s" -q -w -r 44100 -t wav -c2 - | flac %s -c -' % (self.source, self.args)
-
+        self.command = 'sox "%s" -s -q -r 44100 -t wav -c2 - | flac %s -c -' % (self.source, self.args)
+        tmp_file_name = NamedTemporaryFile(suffix = '.' + self.ext).name
+        tmp_file = open(tmp_file_name, 'w')
+        
         # Pre-proccessing
         self.dest = self.pre_process(self.item_id,
                                          self.source,
@@ -128,13 +131,25 @@ class FlacExporter(ExporterCore):
         # Processing (streaming + cache writing)
         stream = self.core_process(self.command, self.buffer_size, self.dest)
         for chunk in stream:
+            tmp_file.write(chunk)
+            
+        tmp_file.close()
+        self.write_tags(tmp_file)
+        tmp_file = open(tmp_file_name.name, 'r')
+
+        while True:
+            chunk = tmp_file.read(self.buffer_size)
+            if len(chunk) == 0:
+                break
             yield chunk
-    
+
+        tmp_file.close()
+
         # Post-proccessing
-        self.post_process(self.item_id,
-                         self.source,
-                         self.metadata,
-                         self.ext,
-                         self.cache_dir,
-                         self.options)
+        #self.post_process(self.item_id,
+                         #self.source,
+                         #self.metadata,
+                         #self.ext,
+                         #self.cache_dir,
+                         #self.options)
 
index 1f54672de23d00bc3762b3517c3b1229a0ec70d8..ce0f4ed8055d961a219238b568bc8e6e028afcf5 100644 (file)
@@ -78,7 +78,7 @@ class Mp3Exporter(ExporterCore):
 
     def decode(self):
         try:
-            os.system('sox "'+self.source+'" -w -r 44100 -t wav "' \
+            os.system('sox "'+self.source+'" -s -q -r 44100 -t wav "' \
                         +self.cache_dir+os.sep+self.item_id+'"')
             return self.cache_dir+os.sep+self.item_id+'.wav'
         except IOError:
@@ -129,7 +129,7 @@ class Mp3Exporter(ExporterCore):
         self.args = self.get_args(options)
         self.ext = self.get_file_extension()
         self.args = ' '.join(self.args)
-        self.command = 'sox "%s" -q -w -r 44100 -t wav -c2 - | lame %s -' % (self.source, self.args)
+        self.command = 'sox "%s" -s -q -r 44100 -t wav -c2 - | lame %s -' % (self.source, self.args)
         #self.command = 'lame %s "%s" -' % (self.args, self.source)
         
         # Pre-proccessing
@@ -146,10 +146,10 @@ class Mp3Exporter(ExporterCore):
             yield chunk
     
         # Post-proccessing
-        self.post_process(self.item_id,
-                         self.source,
-                         self.metadata,
-                         self.ext,
-                         self.cache_dir,
-                         self.options)
+        #self.post_process(self.item_id,
+                         #self.source,
+                         #self.metadata,
+                         #self.ext,
+                         #self.cache_dir,
+                         #self.options)
 
index 1189ab3032ce4d15be12fe41e2684c59920a75a8..2d0e332643d8afa2a7c95aa16fcc487fb447e46f 100644 (file)
@@ -109,7 +109,7 @@ class OggExporter(ExporterCore):
         self.args = self.get_args(options)
         self.ext = self.get_file_extension()
         self.args = ' '.join(self.args)
-        self.command = 'sox "%s" -q -w -r 44100 -t wav -c2 - | oggenc %s -' % (self.source, self.args)
+        self.command = 'sox "%s" -s -q -r 44100 -t wav -c2 - | oggenc %s -' % (self.source, self.args)
         
         # Pre-proccessing
         self.dest = self.pre_process(self.item_id,
@@ -125,10 +125,10 @@ class OggExporter(ExporterCore):
             yield chunk
     
         # Post-proccessing
-        self.post_process(self.item_id,
-                        self.source,
-                        self.metadata,
-                        self.ext,
-                        self.cache_dir,
-                        self.options)
+        #self.post_process(self.item_id,
+                        #self.source,
+                        #self.metadata,
+                        #self.ext,
+                        #self.cache_dir,
+                        #self.options)
 
index 576bb87a8f3924c70000c1dd052c5fec4bfcc914..86619f9dd9f691b9c449e6b25791b29903ed9fa4 100644 (file)
@@ -61,7 +61,7 @@ class WavExporter(ExporterCore):
         try:
             file_name, ext = get_file_name(self.source)
             dest = self.cache_dir+os.sep+file_name+'.wav'
-            os.system('sox "'+self.source+'" -w -r 44100 -t wav -c2 "'+ \
+            os.system('sox "'+self.source+'" -s -r 44100 -t wav -c2 "'+ \
                       dest+'.wav"')
             self.source = dest
             return dest
@@ -131,7 +131,7 @@ class WavExporter(ExporterCore):
 
         # Create the par2 key
         #if 'par2' in self.metadata and self.metadata['par2']:
-        self.create_par_key()
+        #self.create_par_key()
 
         # Pre-proccessing
         self.post_process(self.item_id,