import os
import re
import string
+import subprocess
import mutagen
import telemeta.export
#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()
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):
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)
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+'" "'+ \
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,
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,
chunk = proc.stdout.read(self.buffer_size)
yield chunk
file_out.write(chunk)
-
+
# Processing
while chunk:
chunk = proc.stdout.read(self.buffer_size)
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'
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
'creator': 'Cellar',
'type': 'House',
'date': '2004',
- 'publisher': 'PArISs0n',
+ 'publisher': 'Parisson',
}
-options = {'verbose': '1'}
+options = {'verbose': '0'}
class ExportTest(Component):