self.dest = os.path.join(self.dest,target_file)
return self.dest
- def stream(self,command):
+ def core_process(self,command,buffer_size,dest):
"""Streams encoded audio data through a generator"""
+
+ __chunk = 0
+ file_out = open(dest,'w')
+
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
+ shell = True,
+ bufsize = buffer_size,
+ stdin = subprocess.PIPE,
+ stdout = subprocess.PIPE,
+ close_fds = True)
+
+ __chunk = proc.stdout.read(buffer_size)
+ yield __chunk
+ file_out.write(__chunk)
+
+ # Processing
+ while __chunk:
+ __chunk = proc.stdout.read(buffer_size)
+ yield __chunk
+ file_out.write(__chunk)
+
+ #file_in.close()
+ file_out.close()
def post_process(self, item_id, source, metadata, ext,
cache_dir, options=None):
media[tag] = str(self.metadata[tag])
media.save()
- def process(self, item_id, source, metadata, options=None):
- self.item_id = item_id
- self.source = source
- self.metadata = metadata
- self.options = {}
+ def get_args(self,options=None):
+ """Get process options and return arguments for the encoder"""
args = ''
-
if not options is None:
self.options = options
-
- if 'verbose' in self.options and self.options['verbose'] != '0':
- args = args
- else:
+ if not ('verbose' in self.options and self.options['verbose'] != '0'):
args = args + ' -s '
-
+
if 'flac_quality' in self.options:
args = args+' -f -'+self.options['flac_quality']
else:
args = args+' -f -'+self.quality_default
else:
args = args+' -s -f -'+self.quality_default
-
+ return args
+
+ def process(self, item_id, source, metadata, options=None):
+ self.item_id = item_id
+ self.source = source
+ self.metadata = metadata
+ #self.options = {}
+ self.args = self.get_args(options)
+ self.ext = self.get_file_extension()
+ self.command = 'sox "'+self.source+'" -q -w -r 44100 -t wav -c2 - '+ \
+ '| flac '+self.args+' -c -'
+
+ # Pre-proccessing
try:
- # Pre-proccessing (core)
- self.ext = self.get_file_extension()
self.dest = self.pre_process(self.item_id,
self.source,
self.metadata,
self.ext,
self.cache_dir,
self.options)
-
- # Initializing
- chunk = 0
- file_out = open(self.dest,'w')
-
- proc = subprocess.Popen( \
- '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_in.close()
- file_out.close()
+ except:
+ yield 'ExporterError [3]: pre_process'
- # Encoding
- #os.system('flac '+args+' -o "'+self.dest+'" "'+ \
- # self.source+'" > /dev/null')
+ # Processing (streaming + cache writing)
+ try:
+ stream = self.core_process(self.command,self.buffer_size,self.dest)
+ for chunk in stream:
+ yield chunk
+ except:
+ yield 'ExporterError: core_process'
- # Post-proccessing (self)
- self.write_tags()
+ # Post-proccessing
+ try:
+ self.write_tags()
self.post_process(self.item_id,
self.source,
self.metadata,
self.ext,
self.cache_dir,
self.options)
+ except:
+ yield 'ExporterError: post_process'
- # Output
- #return self.dest
-
- except IOError:
- yield 'ExporterError [3]: source file does not exist.'
+ # Encoding
+ #os.system('flac '+args+' -o "'+self.dest+'" "'+ \
+ # self.source+'" > /dev/null')
id3.add(frame)
id3.save()
- def process(self, item_id, source, metadata, options=None):
- self.item_id = item_id
- self.source = source
- self.metadata = metadata
- self.options = {}
+ def get_args(self,options=None):
+ """Get process options and return arguments for the encoder"""
args = ''
-
if not options is None:
self.options = options
args = args + ' -c -o '
else:
args = args + ' -S -c -o '
-
- if os.path.exists(self.source) and not iswav16(self.source):
- self.source = self.decode()
+
+ return args
+
+ def process(self, item_id, source, metadata, options=None):
+ self.item_id = item_id
+ self.source = source
+ self.metadata = metadata
+ #self.options = {}
+ self.args = self.get_args(options)
+ self.ext = self.get_file_extension()
+ self.command = 'sox "'+self.source+'" -q -w -r 44100 -t wav -c2 - '+ \
+ '| lame '+self.args+' --tc "default" - -'
+ # Pre-proccessing
try:
- # Pre-proccessing (core)
- self.ext = self.get_file_extension()
self.dest = self.pre_process(self.item_id,
- self.source,
- self.metadata,
- self.ext,
- self.cache_dir,
- self.options)
-
- # Initializing
- chunk = 0
- file_out = open(self.dest,'w')
-
- proc = subprocess.Popen( \
- 'sox "'+self.source+'" -q -w -r 44100 -t wav -c2 - '+
- '| lame '+args+' --tc "default" - -',
- 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)
+ self.source,
+ self.metadata,
+ self.ext,
+ self.cache_dir,
+ self.options)
+ except:
+ yield 'ExporterError [3]: pre_process'
+
+ # Processing (streaming + cache writing)
+ try:
+ stream = self.core_process(self.command,self.buffer_size,self.dest)
+ for chunk in stream:
yield chunk
- file_out.write(chunk)
-
- file_out.close()
-
- # Encoding
- # os.system('lame '+args+' --tc "default" "'+self.source+
- # '" "'+self.dest+'"')
-
- # Post-proccessing (self)
- self.write_tags()
+ except:
+ yield 'ExporterError: core_process'
+
+ # Post-proccessing
+ try:
+ self.write_tags()
self.post_process(self.item_id,
self.source,
self.metadata,
self.ext,
self.cache_dir,
self.options)
-
- # Output
- # return self.dest
-
- except IOError:
- yield 'ExporterError [3]: source file does not exist.'
-
+ except:
+ yield 'ExporterError: post_process'
+
+ # Encoding
+ # os.system('lame '+args+' --tc "default" "'+self.source+
+ # '" "'+self.dest+'"')
+
media[tag] = str(self.metadata[tag])
media.save()
-
- def process(self, item_id, source, metadata, options=None):
- self.item_id = item_id
- self.source = source
- self.metadata = metadata
- self.options = {}
+ def get_args(self,options=None):
+ """Get process options and return arguments for the encoder"""
args = ''
-
if not options is None:
self.options = options
args = args + '-q '+self.options['ogg_quality']
else:
args = args + '-b '+self.bitrate_default
-
else:
args = ' -Q -b '+self.bitrate_default
+ return args
- #if os.path.exists(self.source) and not iswav16(self.source):
- # self.source = self.decode()
-
- # Pre-processing
+
+ def process(self, item_id, source, metadata, options=None):
+ self.item_id = item_id
+ self.source = source
+ self.metadata = metadata
+ #self.options = {}
+ self.args = self.get_args(options)
self.ext = self.get_file_extension()
- self.dest = self.pre_process(self.item_id,
- self.source,
- self.metadata,
- self.ext,
- self.cache_dir,
- self.options)
-
+ self.command = 'sox "'+self.source+'" -q -w -r 44100 -t wav -c2 - '+ \
+ '| oggenc '+self.args+' -'
+
+ # Pre-proccessing
try:
- # Initializing
- chunk = 0
- file_out = open(self.dest,'w')
-
- proc = subprocess.Popen( \
- 'sox "'+self.source+'" -q -w -r 44100 -t wav -c2 - '+
- '| oggenc '+args+' -',
- 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)
+ self.dest = self.pre_process(self.item_id,
+ self.source,
+ self.metadata,
+ self.ext,
+ self.cache_dir,
+ self.options)
+ except:
+ yield 'ExporterError [3]: pre_process'
+
+ # Processing (streaming + cache writing)
+ try:
+ stream = self.core_process(self.command,self.buffer_size,self.dest)
+ for chunk in stream:
yield chunk
- file_out.write(chunk)
-
- #file_in.close()
- file_out.close()
-
- # Post-proccessing
- #os.system('sox "'+self.source+'" -w -r 44100 -t wav -c2 - \
- # | oggenc '+args+' -o "'+self.dest+'" -')
-
- self.write_tags()
+ except:
+ yield 'ExporterError: core_process'
+
+ # Post-proccessing
+ try:
+ self.write_tags()
self.post_process(self.item_id,
- self.source,
- self.metadata,
- self.ext,
- self.cache_dir,
- self.options)
-
- except IOError:
- yield 'ExporterError [3]: source file does not exist.'
+ self.source,
+ self.metadata,
+ self.ext,
+ self.cache_dir,
+ self.options)
+ except:
+ yield 'ExporterError: post_process'
+
+
+
+ # Post-proccessing
+ #os.system('sox "'+self.source+'" -w -r 44100 -t wav -c2 - \
+ # | oggenc '+args+' -o "'+self.dest+'" -')
+
chunk = 0
file_in = open(self.source,'rb')
file_out = open(self.dest,'w')
-
+
chunk = file_in.read(self.buffer_size)
yield chunk
file_out.write(chunk)
file_in.close()
file_out.close()
-
- #if self.compare_md5_key():
- #os.system('cp -a "'+self.source+'" "'+ self.dest+'"')
- #print 'COPIED'
-
- # Pre-proccessing (self)
self.write_tags()
# Create the md5 key
self.cache_dir,
self.options)
- # Output
- #return self.dest
-
except IOError:
yield 'ExporterError [3]: source file does not exist.'
+
+
+ #if self.compare_md5_key():
+ #os.system('cp -a "'+self.source+'" "'+ self.dest+'"')
+ #print 'COPIED'
+
'date': '2004',
'publisher': 'Parisson',
}
-options = {'verbose': '0'}
+options = {'verbose': '1'}
class ExportTest(Component):
for chunk in stream:
pass
+ #print chunk
compmgr = ComponentManager()
test = ExportTest(compmgr)