]> git.parisson.com Git - telemeta.git/commitdiff
Partially fixes #19 by changing MediaCollection.copied_from properties.
authoryomguy <>
Sun, 13 May 2007 01:43:06 +0000 (01:43 +0000)
committeryomguy <>
Sun, 13 May 2007 01:43:06 +0000 (01:43 +0000)
telemeta/export/core.py
telemeta/export/flac.py
telemeta/export/mp3.py
telemeta/export/ogg.py
telemeta/models.py
telemeta/views/web.py
tests/export_test.py

index 23e0b46cdbb033cea2a18fef8e552ae0f27b1379..fd9c1bdbff3f7698a0cada8323162463ff9c2aa1 100644 (file)
@@ -13,6 +13,7 @@
 import os
 import re
 import string
+import subprocess
 import mutagen
 
 import telemeta.export
@@ -113,13 +114,16 @@ class ExporterCore(Component):
         #self.title = self.metadata['Title']
 
         # Decode the source if needed
-        if os.path.exists(self.source) and not iswav16(self.source):
+        #if os.path.exists(self.source) and not iswav16(self.source):
             # TO FIX !
-            self.source = self.export.decode()
+        #    self.source = self.export.decode()
 
         # Normalize if demanded
-        if 'normalize' in self.metadata and self.metadata['normalize']:
-            self.normalize()
+        if not options is None:
+            self.options = options
+            if 'normalize' in self.options and \
+                self.options['normalize'] == True:
+                self.normalize()
 
         # Define the cache directory
         self.ext = self.get_file_extension()
@@ -145,6 +149,17 @@ class ExporterCore(Component):
         self.dest = os.path.join(self.dest,target_file)
         return self.dest
 
+    def stream(self,command):
+        """Streams encoded audio data through a generator"""
+        proc = subprocess.Popen(command,
+                shell=True,
+                bufsize=self.buffer_size,
+                stdin=subprocess.PIPE,
+                stdout=subprocess.PIPE,
+                close_fds=True)
+                
+        chunk = proc.stdout.read(self.buffer_size)
+        return chunk
 
     def post_process(self, item_id, source, metadata, ext, 
                      cache_dir, options=None):
index 56334e5a092c5abe0697bef78ad39ae68ac5e07c..212b61e441d9009bc37f7e31c63bb0db1fcd68ba 100644 (file)
@@ -101,11 +101,11 @@ class FlacExporter(ExporterCore):
                 args = args + ' -s '
                 
             if 'flac_quality' in self.options:
-                args = args+' -f -V -'+self.options['flac_quality']
+                args = args+' -f -'+self.options['flac_quality']
             else:
-                args = args+' -f -V -'+self.quality_default
+                args = args+' -f -'+self.quality_default
         else:
-            args = args+' -s -f -V -'+self.quality_default
+            args = args+' -s -f -'+self.quality_default
     
         try:
             # Pre-proccessing (core)
@@ -116,32 +116,32 @@ class FlacExporter(ExporterCore):
                                          self.ext,
                                          self.cache_dir,
                                          self.options)
-
+                                         
             # Initializing
             chunk = 0
             file_out = open(self.dest,'w')
             
             proc = subprocess.Popen( \
-                    'sox "'+self.source+'" -w -r 44100 -t wav -c2 - '+
+                    'sox "'+self.source+'" -q -w -r 44100 -t wav -c2 - '+
                     '| flac '+args+' -c -',
                     shell=True,
                     bufsize=self.buffer_size,
                     stdin=subprocess.PIPE,
                     stdout=subprocess.PIPE,
                     close_fds=True)
-                
+
             chunk = proc.stdout.read(self.buffer_size)
             yield chunk
             file_out.write(chunk)
-           
+
             # Processing
             while chunk:
                 chunk = proc.stdout.read(self.buffer_size)
                 yield chunk
                 file_out.write(chunk)           
-           
-            file_out.close()
             
+            #file_in.close()
+            file_out.close()
 
             # Encoding
             #os.system('flac '+args+' -o "'+self.dest+'" "'+ \
index 42beade664328489cce2dfae71116480d1e71e0f..42155f387decb48a4111fcc9caf0aeb1b876aa8f 100644 (file)
@@ -132,7 +132,7 @@ class Mp3Exporter(ExporterCore):
             file_out = open(self.dest,'w')
             
             proc = subprocess.Popen( \
-                    'sox "'+self.source+'" -w -r 44100 -t wav -c2 - '+
+                    'sox "'+self.source+'" -q -w -r 44100 -t wav -c2 - '+
                     '| lame '+args+' --tc "default" - -',
                     shell=True,
                     bufsize=self.buffer_size,
index 509e9d28547df4f9aea93793ed0cdc24045b4add..e4c402209463679f5adb7ec2fe88fe335bb9e466 100644 (file)
@@ -118,7 +118,7 @@ class OggExporter(ExporterCore):
             file_out = open(self.dest,'w')
             
             proc = subprocess.Popen( \
-                    'sox "'+self.source+'" -w -r 44100 -t wav -c2 - '+
+                    'sox "'+self.source+'" -q -w -r 44100 -t wav -c2 - '+
                     '| oggenc '+args+' -',
                     shell=True,
                     bufsize=self.buffer_size,
@@ -129,7 +129,7 @@ class OggExporter(ExporterCore):
             chunk = proc.stdout.read(self.buffer_size)
             yield chunk
             file_out.write(chunk)
-           
+
             # Processing
             while chunk:
                 chunk = proc.stdout.read(self.buffer_size)
index e15348a554c4ff87bbff70f6dabd0f2fcab56c80..eb1b2c58e4e15a558c1f08b1e3135e5d52b42c2e 100644 (file)
@@ -62,7 +62,7 @@ class MediaCollection(models.Model, MediaCore):
     publishing_status = models.CharField(maxlength=250, blank=True)
     is_original = models.CharField(maxlength=250)
     is_full_copy = models.CharField(maxlength=250)
-    copied_from = models.ForeignKey('self', null=True)
+    copied_from = models.ForeignKey('self', blank=True)
     #copied_from[0].dc_element = 'relation'
     creator = models.CharField(maxlength=250)
     creator.dc_element = 'creator'
index 2018506b34b2f1b83dd0b472c747625670cc6d90..19acdf63a47d881bafb27b0c608357a2a9356d0d 100644 (file)
@@ -105,9 +105,10 @@ class WebView(Component):
         metadata['Artist'] = metadata['creator']
         metadata['Title'] = metadata['title']
 
-        outfile = exporter.process(item.id, infile, metadata, [])
+        stream = exporter.process(item.id, infile, metadata, [])
 
-        response = HttpResponse(self.__file_stream(outfile), mimetype = mime_type)
+        #response = HttpResponse(self.__file_stream(outfile),mimetype=mime_type)
+        response = HttpResponse(stream, mimetype = mime_type)
         response['Content-Disposition'] = 'attachment; filename="download.' + \
                     exporter.get_file_extension() + '"'
         return response
index 68ca84456817e18c7970ae5a9715d2636639204f..d6063d62dd736d046a8c9f2fddfec27f5da92851 100644 (file)
@@ -25,9 +25,9 @@ metadata = {'identifier': 'Test',  #collection
          'creator': 'Cellar',
          'type': 'House',
          'date': '2004',
-         'publisher': 'PArISs0n',
+         'publisher': 'Parisson',
          }
-options = {'verbose': '1'}
+options = {'verbose': '0'}
 
 class ExportTest(Component):