From 78b2610f5115469a7571c2fdd27525efa6ef5129 Mon Sep 17 00:00:00 2001 From: yomguy <> Date: Tue, 1 May 2007 02:09:54 +0000 Subject: [PATCH] Made options optional. Closes: #10 --- telemeta/export/core.py | 14 ++++++++------ telemeta/export/flac.py | 27 +++++++++++++++------------ telemeta/export/mp3.py | 30 ++++++++++++++++++------------ telemeta/export/ogg.py | 28 ++++++++++++++++------------ telemeta/export/wav.py | 6 +++--- tests/export_test.py | 4 +++- 6 files changed, 63 insertions(+), 46 deletions(-) diff --git a/telemeta/export/core.py b/telemeta/export/core.py index ef0ddadf..fffd0d9c 100644 --- a/telemeta/export/core.py +++ b/telemeta/export/core.py @@ -96,7 +96,8 @@ class ExporterCore(Component): xml.dom.ext.PrettyPrint(doc, xml_file) xml_file.close() - def pre_process(self, item_id, source, metadata, ext, cache_dir, options): + def pre_process(self, item_id, source, metadata, ext, + cache_dir, options=None): """ Pre processing of the core. Prepare the export path and return it""" self.item_id = str(item_id) @@ -104,7 +105,6 @@ class ExporterCore(Component): file_name = get_file_name(self.source) file_name_wo_ext, file_ext = split_file_name(file_name) self.cache_dir = cache_dir - self.options = options self.metadata = metadata #self.collection = self.metadata['Collection'] @@ -145,11 +145,13 @@ class ExporterCore(Component): return self.dest - def post_process(self, item_id, source, metadata, ext, cache_dir, options): + def post_process(self, item_id, source, metadata, ext, + cache_dir, options=None): """ Post processing of the Core. Print infos, etc...""" - if 'verbose' in self.options and self.options['verbose'] != '0': - print self.dest - print self.get_file_info() + if not options is None: + if 'verbose' in self.options and self.options['verbose'] != '0': + print self.dest + print self.get_file_info() # External functions diff --git a/telemeta/export/flac.py b/telemeta/export/flac.py index 5b163b50..def184ad 100644 --- a/telemeta/export/flac.py +++ b/telemeta/export/flac.py @@ -83,22 +83,25 @@ class FlacExporter(ExporterCore): media[tag] = str(self.metadata[tag]) media.save() - def process(self, item_id, source, metadata, options): + def process(self, item_id, source, metadata, options=None): self.item_id = item_id self.source = source self.metadata = metadata - self.options = options - - if 'flac_quality' in self.options and \ - self.options['flac_quality'] != '': - args = '-f -V -'+self.options['flac_quality'] - else: - args = '-f -V -'+self.quality_default - - if 'verbose' in self.options and self.options['verbose'] != '0': - args = args + args = '' + + if not options is None: + self.options = options + if 'verbose' in self.options and self.options['verbose'] != '0': + args = args + else: + args = args + ' -s ' + + if 'flac_quality' in self.options: + args = args+' -f -V -'+self.options['flac_quality'] + else: + args = args+' -f -V -'+self.quality_default else: - args = args+' -s ' + args = args+' -s -f -V -'+self.quality_default try: # Pre-proccessing (core) diff --git a/telemeta/export/mp3.py b/telemeta/export/mp3.py index ebcc82d6..de6171ec 100644 --- a/telemeta/export/mp3.py +++ b/telemeta/export/mp3.py @@ -88,23 +88,29 @@ class Mp3Exporter(ExporterCore): id3.add(frame) id3.save() - def process(self, item_id, source, metadata, options): + def process(self, item_id, source, metadata, options=None): self.item_id = item_id self.source = source self.metadata = metadata - self.options = options - - if 'mp3_bitrate' in self.options: - args = '-b '+self.options['mp3_bitrate'] - else: - args = '-b '+self.bitrate_default + args = '' + + if not options is None: + self.options = options - args = args + '-c -o ' - - if 'verbose' in self.options and self.options['verbose'] != '0': - args = args + if 'verbose' in self.options and self.options['verbose'] != '0': + args = args + else: + args= args + '-S ' + + if 'mp3_bitrate' in self.options: + args = args+'-b '+self.options['mp3_bitrate'] + else: + args = args+'-b '+self.bitrate_default + + #Copyrights, etc.. + args = args + ' -c -o ' else: - args = args + '-S ' + args = args + ' -S -c -o ' if os.path.exists(self.source) and not iswav16(self.source): self.source = self.decode() diff --git a/telemeta/export/ogg.py b/telemeta/export/ogg.py index 207e6639..5f5ea2ba 100644 --- a/telemeta/export/ogg.py +++ b/telemeta/export/ogg.py @@ -72,24 +72,28 @@ class OggExporter(ExporterCore): media[tag] = str(self.metadata[tag]) media.save() - def process(self, item_id, source, metadata, options): + def process(self, item_id, source, metadata, options=None): self.item_id = item_id self.source = source self.metadata = metadata - self.options = options + args = '' + + if not options is None: + self.options = options + if 'verbose' in self.options and self.options['verbose'] != '0': + args = args + else: + args = args + ' -Q ' + if 'ogg_bitrate' in self.options: + args = '-b '+self.options['ogg_bitrate'] + elif 'ogg_quality' in self.options: + args = '-q '+self.options['ogg_quality'] + else: + args = '-b '+self.bitrate_default - if 'ogg_bitrate' in self.options: - args = '-b '+self.options['ogg_bitrate'] - elif 'ogg_quality' in self.options: - args = '-q '+self.options['ogg_quality'] else: - args = '-b '+self.bitrate_default + args = '-Q -b '+self.bitrate_default - if 'verbose' in self.options and self.options['verbose'] != '0': - args = args - else: - args = args + ' -Q ' - if os.path.exists(self.source) and not iswav16(self.source): self.source = self.decode() diff --git a/telemeta/export/wav.py b/telemeta/export/wav.py index 5da55895..88e2b89a 100644 --- a/telemeta/export/wav.py +++ b/telemeta/export/wav.py @@ -97,12 +97,12 @@ class WavExporter(ExporterCore): except IOError: return 'Exporter error: Cannot create the par2 key...' - def process(self, item_id, source, metadata, options): + def process(self, item_id, source, metadata, options=None): self.item_id = item_id self.source = source self.metadata = metadata - self.options = options - + if not options is None: + self.options = options try: # Pre-proccessing (core) self.ext = self.get_file_extension() diff --git a/tests/export_test.py b/tests/export_test.py index 24b25719..b8cd33be 100644 --- a/tests/export_test.py +++ b/tests/export_test.py @@ -33,14 +33,16 @@ class ExportTest(Component): exporters = ExtensionPoint(IExporter) def run(self): + verbose = '1' for exporter in self.exporters: format = exporter.get_format() - if 'verbose' in options and options['verbose'] != '0': + if verbose != '0': print "\n+------------------------------------------" print '| Testing exporter format: ' + format print "+------------------------------------------" exporter.set_cache_dir(cache_dir) exporter.process(item_id,source,metadata,options) + #exporter.process(item_id,source,metadata) compmgr = ComponentManager() -- 2.39.5