From 6a3bcb1d0f01f5131629837272b345b636507f42 Mon Sep 17 00:00:00 2001 From: yomguy Date: Wed, 17 Feb 2010 15:27:17 +0000 Subject: [PATCH] cleanup cores, fix max_level id --- analyze/max_level.py | 5 ++- decode/core.py | 96 -------------------------------------------- encode/core.py | 94 ------------------------------------------- 3 files changed, 3 insertions(+), 192 deletions(-) diff --git a/analyze/max_level.py b/analyze/max_level.py index c40ae4d..af6c4a0 100644 --- a/analyze/max_level.py +++ b/analyze/max_level.py @@ -30,9 +30,10 @@ class MaxLevelAnalyzer(AudioProcessor): @staticmethod def id(): - return "maxlevel" + return "max_level" - def name(self): + @staticmethod + def name(): return "Maximum peak level" def unit(self): diff --git a/decode/core.py b/decode/core.py index 99d3900..d82d6b9 100644 --- a/decode/core.py +++ b/decode/core.py @@ -78,99 +78,3 @@ class DecoderCore(Processor): -# External functions - -def get_type(value): - """ Return a String with the type of value """ - types = {bool : 'bool', int : 'int', str : 'str'} - # 'bool' type must be placed *before* 'int' type, otherwise booleans are - # detected as integers - for type in types.keys(): - if isinstance(value, type) : - return types[type] - raise TypeError(str(value) + ' has an unsupported type') - -def get_cast(value, type) : - """ Return value, casted into type """ - if type == 'bool' : - if value == 'True' : - return True - return False - elif type == 'int' : - return int(value) - elif type == 'str' : - return str(value) - raise TypeError(type + ' is an unsupported type') - -def get_file_mime_type(path): - """ Return the mime type of a file """ - try: - file_out1, file_out2 = os.popen4('file -i "'+path+'"') - for line in file_out2.readlines(): - line_split = line.split(': ') - mime = line_split[len(line_split)-1] - return mime[:len(mime)-1] - except: - raise IOError('DecoderError: path does not exist.') - -def get_file_type_desc(path): - """ Return the type of a file given by the 'file' command """ - try: - file_out1, file_out2 = os.popen4('file "'+path+'"') - for line in file_out2.readlines(): - description = line.split(': ') - description = description[1].split(', ') - return description - except: - raise IOError('DecoderError: path does not exist.') - -def iswav(path): - """ Tell if path is a WAV """ - try: - mime = get_file_mime_type(path) - return mime == 'audio/x-wav' - except: - raise IOError('DecoderError: path does not exist.') - -def iswav16(path): - """ Tell if path is a 16 bit WAV """ - try: - file_type_desc = get_file_type_desc(path) - return iswav(path) and '16 bit' in file_type_desc - except: - raise IOError('DecoderError: path does not exist.') - -def get_file_name(path): - """ Return the file name targeted in the path """ - return os.path.split(path)[1] - -def split_file_name(file): - """ Return main file name and its extension """ - try: - return os.path.splitext(file) - except: - raise IOError('DecoderError: path does not exist.') - -def clean_word(word) : - """ Return the word without excessive blank spaces, underscores and - characters causing problem to decodeers""" - word = re.sub("^[^\w]+","",word) #trim the beginning - word = re.sub("[^\w]+$","",word) #trim the end - word = re.sub("_+","_",word) #squeeze continuous _ to one _ - word = re.sub("^[^\w]+","",word) #trim the beginning _ - #word = string.replace(word,' ','_') - #word = string.capitalize(word) - dict = '&[];"*:,' - for letter in dict: - word = string.replace(word,letter,'_') - return word - -def recover_par_key(path): - """ Recover a file with par2 key """ - os.system('par2 r "'+path+'"') - -def verify_par_key(path): - """ Verify a par2 key """ - os.system('par2 v "'+path+'.par2"') - - diff --git a/encode/core.py b/encode/core.py index fbcf35f..3dc6391 100644 --- a/encode/core.py +++ b/encode/core.py @@ -68,99 +68,5 @@ class EncoderCore(Processor): break yield __chunk -# External functions - -def get_type(value): - """ Return a String with the type of value """ - types = {bool : 'bool', int : 'int', str : 'str'} - # 'bool' type must be placed *before* 'int' type, otherwise booleans are - # detected as integers - for type in types.keys(): - if isinstance(value, type) : - return types[type] - raise TypeError(str(value) + ' has an unsupported type') - -def get_cast(value, type) : - """ Return value, casted into type """ - if type == 'bool' : - if value == 'True' : - return True - return False - elif type == 'int' : - return int(value) - elif type == 'str' : - return str(value) - raise TypeError(type + ' is an unsupported type') - -def get_file_mime_type(path): - """ Return the mime type of a file """ - try: - file_out1, file_out2 = os.popen4('file -i "'+path+'"') - for line in file_out2.readlines(): - line_split = line.split(': ') - mime = line_split[len(line_split)-1] - return mime[:len(mime)-1] - except: - raise IOError('EncoderError: path does not exist.') - -def get_file_type_desc(path): - """ Return the type of a file given by the 'file' command """ - try: - file_out1, file_out2 = os.popen4('file "'+path+'"') - for line in file_out2.readlines(): - description = line.split(': ') - description = description[1].split(', ') - return description - except: - raise IOError('EncoderError: path does not exist.') - -def iswav(path): - """ Tell if path is a WAV """ - try: - mime = get_file_mime_type(path) - return mime == 'audio/x-wav' - except: - raise IOError('EncoderError: path does not exist.') - -def iswav16(path): - """ Tell if path is a 16 bit WAV """ - try: - file_type_desc = get_file_type_desc(path) - return iswav(path) and '16 bit' in file_type_desc - except: - raise IOError('EncoderError: path does not exist.') - -def get_file_name(path): - """ Return the file name targeted in the path """ - return os.path.split(path)[1] - -def split_file_name(file): - """ Return main file name and its extension """ - try: - return os.path.splitext(file) - except: - raise IOError('EncoderError: path does not exist.') - -def clean_word(word) : - """ Return the word without excessive blank spaces, underscores and - characters causing problem to encodeers""" - word = re.sub("^[^\w]+","",word) #trim the beginning - word = re.sub("[^\w]+$","",word) #trim the end - word = re.sub("_+","_",word) #squeeze continuous _ to one _ - word = re.sub("^[^\w]+","",word) #trim the beginning _ - #word = string.replace(word,' ','_') - #word = string.capitalize(word) - dict = '&[];"*:,' - for letter in dict: - word = string.replace(word,letter,'_') - return word - -def recover_par_key(path): - """ Recover a file with par2 key """ - os.system('par2 r "'+path+'"') - -def verify_par_key(path): - """ Verify a par2 key """ - os.system('par2 v "'+path+'.par2"') -- 2.39.5