]> git.parisson.com Git - telemeta.git/commitdiff
Replaced all tabs by spaces in export. Closes: #18
authoryomguy <>
Mon, 7 May 2007 20:46:52 +0000 (20:46 +0000)
committeryomguy <>
Mon, 7 May 2007 20:46:52 +0000 (20:46 +0000)
17 files changed:
install.py
old/audio_marking.py
old/audio_tools.py
old/collection.py
old/consts.py
old/default.py
old/default_options.py
old/default_tags.py
old/tag_tools.py
old/telemeta.py
telemeta/export/api.py
telemeta/export/core.py
telemeta/export/flac.py
telemeta/export/mp3.py
telemeta/export/ogg.py
telemeta/export/wav.py
tests/export_test.py

index 693954116c9334e7e85f732a9d641708dcbef878..e52561f32af90bf9f5c6aca6d1d53aa13089a502 100644 (file)
 import os, sys
 
 if len(sys.argv) == 1:
-       install_dir = '/usr/share/telemeta/'
+    install_dir = '/usr/share/telemeta/'
 elif len(sys.argv) > 2:
-       sys.exit('Give just one directory to install Telemeta, or none.')
+    sys.exit('Give just one directory to install Telemeta, or none.')
 else:
-       install_dir = sys.argv[1]
+    install_dir = sys.argv[1]
 
 if not os.path.exists(install_dir):
-       os.mkdir(install_dir)
+    os.mkdir(install_dir)
 
 os.system('cp -ra ./* '+install_dir+os.sep)
 os.system('rm -rf '+install_dir+os.sep+'debian')
 
 if os.path.exists('/usr/bin/telemeta'):
-       os.system('rm -r /usr/bin/telemeta')
+    os.system('rm -r /usr/bin/telemeta')
 
 os.system('ln -s '+install_dir+os.sep+'telemeta.py '+'/usr/bin/telemeta')
 
index b9ce93c8e7d90dc67bee4cb4533d1c5d6b7094b5..a24ba7f7027521251df17e83710b9c5a392afd6c 100644 (file)
@@ -22,42 +22,42 @@ import tag_tools
 from audio_tools import *
 
 def make_auto_mark(dir_in,file_in):
-       media_in = dir_in+file_in
-       artist_no_ = string.replace(tag_tools.get_tag_value('ARTIST'),'_',' ')
-       title_no_ = string.replace(tag_tools.get_tag_value('TITLE'),'_',' ')
-       description_no_ = string.replace(tag_tools.get_tag_value('COMMENT'),'_',' ')
-       os.system('echo "This is: '+title_no_+'. By '+artist_no_+'. It is '+description_no_+'" | text2wave -f 44100 -o "'+media_in+'_mark.tmp"')
-       #os.system('normalize-audio "'+media_in+'_mark.tmp"')
-       os.system('sox "'+media_in+'_mark.tmp" -t wav -c2 "'+media_in+'_mark.wav" vol 10.0 dB compand 50,20 -80,-80,-25,-35,-15,-27,-5,-19,0,-15 15')
-       os.system('rm '+dir_in+'*.tmp')
+    media_in = dir_in+file_in
+    artist_no_ = string.replace(tag_tools.get_tag_value('ARTIST'),'_',' ')
+    title_no_ = string.replace(tag_tools.get_tag_value('TITLE'),'_',' ')
+    description_no_ = string.replace(tag_tools.get_tag_value('COMMENT'),'_',' ')
+    os.system('echo "This is: '+title_no_+'. By '+artist_no_+'. It is '+description_no_+'" | text2wave -f 44100 -o "'+media_in+'_mark.tmp"')
+    #os.system('normalize-audio "'+media_in+'_mark.tmp"')
+    os.system('sox "'+media_in+'_mark.tmp" -t wav -c2 "'+media_in+'_mark.wav" vol 10.0 dB compand 50,20 -80,-80,-25,-35,-15,-27,-5,-19,0,-15 15')
+    os.system('rm '+dir_in+'*.tmp')
 
 def mark_audio(dir_in,file_in,audio_marking_file,audio_marking_timeline):
-       media_in = dir_in+file_in
-       file_length_sec = audio_length_sec(media_in)
-       audio_mark_length_sec = audio_length_sec(audio_marking_file)
-       ecasound_phrase = ''
-       audio_gain = str(100+100*len(audio_marking_timeline))
+    media_in = dir_in+file_in
+    file_length_sec = audio_length_sec(media_in)
+    audio_mark_length_sec = audio_length_sec(audio_marking_file)
+    ecasound_phrase = ''
+    audio_gain = str(100+100*len(audio_marking_timeline))
 
-       for timeline in audio_marking_timeline:
-               audio_marking_ecasound_filename = file_in+'_'+timeline+'.ewf'
-               audio_marking_ecasound_path = dir_in+file_in+'_'+timeline+'.ewf'
-               audio_marking_ecasound_file=open(audio_marking_ecasound_path,'w')
-               audio_marking_ecasound_file.write('-- '+audio_marking_ecasound_filename+' --\n')
-               audio_marking_ecasound_file.write('source = '+audio_marking_file+'\n')
-               if timeline == 'b':
-                       mark_offset = '0'
-                       ecasound_phrase = '-a:2 -i:"'+audio_marking_ecasound_path+'" -ea:'+audio_gain+' '
-               if timeline == 'm':
-                       mark_offset = str(file_length_sec/2)
-                       ecasound_phrase = ecasound_phrase+'-a:3 -i:"'+audio_marking_ecasound_path+'" -ea:'+audio_gain+' '
-               if timeline == 'e':
-                       mark_offset = str(file_length_sec-audio_mark_length_sec)
-                       ecasound_phrase = ecasound_phrase+'-a:4 -i:"'+audio_marking_ecasound_path+'" -ea:'+audio_gain+' '
-               audio_marking_ecasound_file.write('offset = '+mark_offset+'.0\n')
-               audio_marking_ecasound_file.write('start-position = 0.0\n')
-               audio_marking_ecasound_file.write('length = '+str(audio_mark_length_sec)+'.0\n')
-               audio_marking_ecasound_file.write('looping = false\n')
-               audio_marking_ecasound_file.write('--cut--\n')
-               audio_marking_ecasound_file.close()
-       os.system('ecasound -a:1 -i:"'+media_in+'" -ea:'+audio_gain+' '+ecasound_phrase+' -a:all -o "'+dir_in+'marked_'+file_in+'"')
+    for timeline in audio_marking_timeline:
+        audio_marking_ecasound_filename = file_in+'_'+timeline+'.ewf'
+        audio_marking_ecasound_path = dir_in+file_in+'_'+timeline+'.ewf'
+        audio_marking_ecasound_file=open(audio_marking_ecasound_path,'w')
+        audio_marking_ecasound_file.write('-- '+audio_marking_ecasound_filename+' --\n')
+        audio_marking_ecasound_file.write('source = '+audio_marking_file+'\n')
+        if timeline == 'b':
+            mark_offset = '0'
+            ecasound_phrase = '-a:2 -i:"'+audio_marking_ecasound_path+'" -ea:'+audio_gain+' '
+        if timeline == 'm':
+            mark_offset = str(file_length_sec/2)
+            ecasound_phrase = ecasound_phrase+'-a:3 -i:"'+audio_marking_ecasound_path+'" -ea:'+audio_gain+' '
+        if timeline == 'e':
+            mark_offset = str(file_length_sec-audio_mark_length_sec)
+            ecasound_phrase = ecasound_phrase+'-a:4 -i:"'+audio_marking_ecasound_path+'" -ea:'+audio_gain+' '
+        audio_marking_ecasound_file.write('offset = '+mark_offset+'.0\n')
+        audio_marking_ecasound_file.write('start-position = 0.0\n')
+        audio_marking_ecasound_file.write('length = '+str(audio_mark_length_sec)+'.0\n')
+        audio_marking_ecasound_file.write('looping = false\n')
+        audio_marking_ecasound_file.write('--cut--\n')
+        audio_marking_ecasound_file.close()
+    os.system('ecasound -a:1 -i:"'+media_in+'" -ea:'+audio_gain+' '+ecasound_phrase+' -a:all -o "'+dir_in+'marked_'+file_in+'"')
 
index 0c2ea7a26e2607aa09c08313fc1799fee7941fad..ffbaee854dd3b5ba34b36352cb5ede11fc427cdb 100644 (file)
@@ -22,159 +22,159 @@ import tag_tools
 from audio_tools import *
 
 def encode(enc_type,dir_in,file_in,dir_out,file_out):
-       media_in = dir_in+file_in
-       media_out = dir_out+file_out
+    media_in = dir_in+file_in
+    media_out = dir_out+file_out
 
-       if enc_type == 'flac' :
-               quality = tag_tools.get_opt_value(enc_type+'_quality')
-               os.system('flac -f -V -q '+quality+' -o "'+media_out+'" "'+media_in+'"')
+    if enc_type == 'flac' :
+        quality = tag_tools.get_opt_value(enc_type+'_quality')
+        os.system('flac -f -V -q '+quality+' -o "'+media_out+'" "'+media_in+'"')
 
-       if enc_type == 'ogg':
-               bitrate = tag_tools.get_opt_value(enc_type+'_bitrate')
-               os.system('oggenc -b '+bitrate+' -o "'+media_out+'" "'+media_in+'"')
+    if enc_type == 'ogg':
+        bitrate = tag_tools.get_opt_value(enc_type+'_bitrate')
+        os.system('oggenc -b '+bitrate+' -o "'+media_out+'" "'+media_in+'"')
 
-       if enc_type == 'mp3':
-               bitrate = tag_tools.get_opt_value(enc_type+'_bitrate')
-               tag='temp'
-               os.system('lame -b '+tag+' --ta "'+tag+'" --tt "'+tag+'" --tl "'+tag+'" --ty '+tag+' --tg "Other" --tc "'+tag+'" "'+media_in+'" "'+media_out+'"')
+    if enc_type == 'mp3':
+        bitrate = tag_tools.get_opt_value(enc_type+'_bitrate')
+        tag='temp'
+        os.system('lame -b '+tag+' --ta "'+tag+'" --tt "'+tag+'" --tl "'+tag+'" --ty '+tag+' --tg "Other" --tc "'+tag+'" "'+media_in+'" "'+media_out+'"')
 
-       if enc_type == 'wav':
-               if iswav16(media_in):
-                       os.system('cp -a "'+media_in+'" "'+media_out+'"')
-               else:
-                       os.system('sox "'+media_in+'" -w -r 44100 -t wav -c2 "'+media_out+'"')
+    if enc_type == 'wav':
+        if iswav16(media_in):
+            os.system('cp -a "'+media_in+'" "'+media_out+'"')
+        else:
+            os.system('sox "'+media_in+'" -w -r 44100 -t wav -c2 "'+media_out+'"')
 
-#      if enc_type == 'ogg' and ismp3(media_in):
+#   if enc_type == 'ogg' and ismp3(media_in):
 #                os.system('mp32ogg --verbose "'+file_in+'" "'+file_out+'"')
 
 def decode(media_in,file_ext):
-       if ismp3(media_in) or file_ext == 'mp3':
-               os.system('mpg123 -q -s "'+media_in+'" -w "'+media_in+'.wav"')
-       if isogg(media_in) or file_ext == 'ogg':
-               os.system('oggdec -o "'+media_in+'.wav" "'+media_in+'"')
-       if isflac(media_in) or file_ext == 'flac':
-               os.system('flac -d "'+media_in+'"')
-       if iswav(media_in) or file_ext == 'wav':
-               os.system('sox "'+media_in+'" -w -r 44100 -t wav -c2 "'+media_in+'.wav"')
-       if isaiff(media_in) or file_ext == 'aiff':
-               os.system('sox "'+media_in+'" -w -r 44100 -t aiff -c2 "'+media_in+'.wav"')
+    if ismp3(media_in) or file_ext == 'mp3':
+        os.system('mpg123 -q -s "'+media_in+'" -w "'+media_in+'.wav"')
+    if isogg(media_in) or file_ext == 'ogg':
+        os.system('oggdec -o "'+media_in+'.wav" "'+media_in+'"')
+    if isflac(media_in) or file_ext == 'flac':
+        os.system('flac -d "'+media_in+'"')
+    if iswav(media_in) or file_ext == 'wav':
+        os.system('sox "'+media_in+'" -w -r 44100 -t wav -c2 "'+media_in+'.wav"')
+    if isaiff(media_in) or file_ext == 'aiff':
+        os.system('sox "'+media_in+'" -w -r 44100 -t aiff -c2 "'+media_in+'.wav"')
 
 def normalize(media_in):
-       os.system('normalize-audio "'+media_in+'"')
+    os.system('normalize-audio "'+media_in+'"')
 
 def create_md5_key(dir_in,file_in):
-       media_in = dir_in+file_in
-       os.system('md5sum -b "'+media_in+'" "'+media_in+'.md5"')
+    media_in = dir_in+file_in
+    os.system('md5sum -b "'+media_in+'" "'+media_in+'.md5"')
 
 def check_md5_key(dir_in,file_in):
-       media_in = dir_in+file_in
-       md5_log = os.popen4('md5sum -c "'+media_in+'" "'+media_in+'.md5"')
-       if 'OK' in md5_log.split(':'):
-               return True
-       else:
-               return False
+    media_in = dir_in+file_in
+    md5_log = os.popen4('md5sum -c "'+media_in+'" "'+media_in+'.md5"')
+    if 'OK' in md5_log.split(':'):
+        return True
+    else:
+        return False
 
 def compare_md5_key(file_in,file_out):
-       media_in = file_in
-       media_out = file_out
-       if not os.path.exists(media_in):
-               return False
-       else:
-               print 'Checking md5sums...'
-               file_in_in, file_in_out = os.popen4('md5sum -b "'+media_in+'"')
-               file_out_in, file_out_out = os.popen4('md5sum -b "'+media_out+'"')
-               for line in file_in_out.readlines():
-                       line = line.split('*')
-                       line = line[0]
-                       #print line
-                       for file_out_out_line in file_out_out.readlines():
-                               file_out_out_line= file_out_out_line.split('*')
-                               file_out_out_line= file_out_out_line[0]
-                               #print file_out_out_line        
-                               if line == file_out_out_line:
-                                       print 'Files are equal...\n'
-                                       return True
-                                       exit
-                               else:
-                                       print 'Files are different...\n'
-                                       return False
-                                       exit
-               
+    media_in = file_in
+    media_out = file_out
+    if not os.path.exists(media_in):
+        return False
+    else:
+        print 'Checking md5sums...'
+        file_in_in, file_in_out = os.popen4('md5sum -b "'+media_in+'"')
+        file_out_in, file_out_out = os.popen4('md5sum -b "'+media_out+'"')
+        for line in file_in_out.readlines():
+            line = line.split('*')
+            line = line[0]
+            #print line
+            for file_out_out_line in file_out_out.readlines():
+                file_out_out_line= file_out_out_line.split('*')
+                file_out_out_line= file_out_out_line[0]
+                #print file_out_out_line    
+                if line == file_out_out_line:
+                    print 'Files are equal...\n'
+                    return True
+                    exit
+                else:
+                    print 'Files are different...\n'
+                    return False
+                    exit
+        
 def create_par_key(dir_in,file_in):
-       media_in = dir_in+file_in
-       os.system('par2 c -n1 "'+media_in+'"')
+    media_in = dir_in+file_in
+    os.system('par2 c -n1 "'+media_in+'"')
 
 def recover_par_key(dir_in):
-       for file in os.listdir(dir_in):
-               media_in = dir_in+file
-               if iswav(media_in):
-                       os.system('par2 r "'+media_in+'"')
+    for file in os.listdir(dir_in):
+        media_in = dir_in+file
+        if iswav(media_in):
+            os.system('par2 r "'+media_in+'"')
 
 def verify_par_key(media_in):
-       os.system('par2 v "'+media_in+'.par2"')
+    os.system('par2 v "'+media_in+'.par2"')
 
 def clean_directory(dir_in,type_list):
-       for enc_type in type_list:
-               if os.path.exists(dir_in+enc_type):
-                       print 'Removing '+dir_in+enc_type
-                       os.system('rm -rf "'+dir_in+enc_type+'"')
+    for enc_type in type_list:
+        if os.path.exists(dir_in+enc_type):
+            print 'Removing '+dir_in+enc_type
+            os.system('rm -rf "'+dir_in+enc_type+'"')
 
 def audio_length_sec(file) :
-       file_in, file_out = os.popen4('wavinfo "'+file+'" | grep wavDataSize')
-       for line in file_out.readlines():
-               line_split = line.split(':')
-               value = int(int(line_split[1])/(4*44100))
-               return value
+    file_in, file_out = os.popen4('wavinfo "'+file+'" | grep wavDataSize')
+    for line in file_out.readlines():
+        line_split = line.split(':')
+        value = int(int(line_split[1])/(4*44100))
+        return value
 
 def ext_is_audio(file):
-       file_name_woext, file_ext = tag_tools.filename_split(file)
-       return file_ext == "mp3" or file_ext == "ogg" or file_ext == "flac" or file_ext == "wav" or file_ext == "aif" or file_ext == "aiff" or file_ext == "WAV" or file_ext == "AIFF" or file_ext == "AIF" or file_ext == "MP3" or file_ext == "OGG" or file_ext == "FLAC"
+    file_name_woext, file_ext = tag_tools.filename_split(file)
+    return file_ext == "mp3" or file_ext == "ogg" or file_ext == "flac" or file_ext == "wav" or file_ext == "aif" or file_ext == "aiff" or file_ext == "WAV" or file_ext == "AIFF" or file_ext == "AIF" or file_ext == "MP3" or file_ext == "OGG" or file_ext == "FLAC"
 
 def isaudio(file) :
-       file_in, file_out = os.popen4('file "'+file+'"')
-       for line in file_out.readlines():
-               line_split = line.split(' ')
-               return (iswav16(file) or iswav(file) or ismp3(file) or isogg(file) or isflac(file) or isaiff(file) or isaiff16(file))
+    file_in, file_out = os.popen4('file "'+file+'"')
+    for line in file_out.readlines():
+        line_split = line.split(' ')
+        return (iswav16(file) or iswav(file) or ismp3(file) or isogg(file) or isflac(file) or isaiff(file) or isaiff16(file))
 
 def iswav(file) :
-       file_in, file_out = os.popen4('file "'+file+'"')
-       for line in file_out.readlines():
-               line_split = line.split(' ')
-               return ('WAVE' in line_split)
+    file_in, file_out = os.popen4('file "'+file+'"')
+    for line in file_out.readlines():
+        line_split = line.split(' ')
+        return ('WAVE' in line_split)
 
 def iswav16(file) :
-       file_in, file_out = os.popen4('file "'+file+'"')
-       for line in file_out.readlines():
-               line_split = line.split(' ')
-               return ('WAVE' in line_split) and ('16' in line_split)
+    file_in, file_out = os.popen4('file "'+file+'"')
+    for line in file_out.readlines():
+        line_split = line.split(' ')
+        return ('WAVE' in line_split) and ('16' in line_split)
 
 def isaiff(file) :
-       file_in, file_out = os.popen4('file "'+file+'"')
-       for line in file_out.readlines():
-               line_split = line.split(' ')
-               return ('AIFF' in line_split)
+    file_in, file_out = os.popen4('file "'+file+'"')
+    for line in file_out.readlines():
+        line_split = line.split(' ')
+        return ('AIFF' in line_split)
 
 def isaiff16(file) :
-       file_in, file_out = os.popen4('file "'+file+'"')
-       for line in file_out.readlines():
-               line_split = line.split(' ')
-               return ('AIFF' in line_split) and ('16' in line_split)
+    file_in, file_out = os.popen4('file "'+file+'"')
+    for line in file_out.readlines():
+        line_split = line.split(' ')
+        return ('AIFF' in line_split) and ('16' in line_split)
 
 def ismp3(file) :
-       file_in, file_out = os.popen4('file "'+file+'"')
-       for line in file_out.readlines():
-               line_split_space = line.split(' ')
-               line_split_comma = line.split(',')
-               return (('MPEG' in line_split_space and ' layer III' in line_split_comma) or 'MP3' in line_split_space)
+    file_in, file_out = os.popen4('file "'+file+'"')
+    for line in file_out.readlines():
+        line_split_space = line.split(' ')
+        line_split_comma = line.split(',')
+        return (('MPEG' in line_split_space and ' layer III' in line_split_comma) or 'MP3' in line_split_space)
 
 def isogg(file) :
-       file_in, file_out = os.popen4('file "'+file+'"')
-       for line in file_out.readlines():
-               line_split = line.split(',')
-               return (' Vorbis audio' in line_split)
+    file_in, file_out = os.popen4('file "'+file+'"')
+    for line in file_out.readlines():
+        line_split = line.split(',')
+        return (' Vorbis audio' in line_split)
 
 def isflac(file) :
-       file_in, file_out = os.popen4('file "'+file+'"')
-       for line in file_out.readlines():
-               line_split = line.split(' ')
-               return ('FLAC' in line_split)
+    file_in, file_out = os.popen4('file "'+file+'"')
+    for line in file_out.readlines():
+        line_split = line.split(' ')
+        return ('FLAC' in line_split)
index 671de22fc10c936ff45de43c908b564e0d2b32e4..042a4cf9e50baa77ed6cb579ab973e9e2b502a91 100644 (file)
@@ -21,16 +21,16 @@ import os, string
 
 class Collection :
 
-       def __init__(self) :
-               self.collection_name = 'telemeta_default'
-               self.collection_dir = '/home/'+os.environ["USER"]+'/telemeta/'
-               self.user_dir = '/home/'+os.environ["USER"]+'/.telemeta/'
-               self.user_tag_xml = '/home/'+os.environ["USER"]+'/.telemeta/default_tags.xml'
-               self.user_collection_xml = '/home/'+os.environ["USER"]+'/.telemeta/default_collection.xml'
-               self.tag_table = 'ARTIST,TITLE,ALBUM,DATE,GENRE,SOURCE,ENCODER,COMMENT'
-               self.type_list = 'mp3,ogg,flac,wav,aiff'
-               self.net_backup_host = 'domain.com'
-               self.net_backup_dir = '/home/'+os.environ["USER"]+'/telemeta/'
+    def __init__(self) :
+        self.collection_name = 'telemeta_default'
+        self.collection_dir = '/home/'+os.environ["USER"]+'/telemeta/'
+        self.user_dir = '/home/'+os.environ["USER"]+'/.telemeta/'
+        self.user_tag_xml = '/home/'+os.environ["USER"]+'/.telemeta/default_tags.xml'
+        self.user_collection_xml = '/home/'+os.environ["USER"]+'/.telemeta/default_collection.xml'
+        self.tag_table = 'ARTIST,TITLE,ALBUM,DATE,GENRE,SOURCE,ENCODER,COMMENT'
+        self.type_list = 'mp3,ogg,flac,wav,aiff'
+        self.net_backup_host = 'domain.com'
+        self.net_backup_dir = '/home/'+os.environ["USER"]+'/telemeta/'
 
 #option_table=['enc_types','flac_bitrate','ogg_bitrate','mp3_bitrate','audio_marking','auto_audio_marking','audio_marking_file','audio_marking_timeline']
 
index 250daed70f8d9bfbff35c4744e472543968e50ee..dc204f734becaad7bf9027a6fe43a64fecc0d6a2 100644 (file)
@@ -21,16 +21,16 @@ import os, string
 
 class Collection :
 
-       def __init__(self) :
-               self.collection_name = 'telemeta_default'
-               self.collection_dir = '/home/'+os.environ["USER"]+'/telemeta_default/'
-               self.user_dir = '/home/'+os.environ["USER"]+'/.telemeta/'
-               self.default_tag_xml = '/home/'+os.environ["USER"]+'/.telemeta/default_tags.xml'
-               self.default_collection_xml = '/home/'+os.environ["USER"]+'/.telemeta/default_collection.xml'
-               self.tag_table = 'ARTIST,TITLE,ALBUM,DATE,GENRE,SOURCE,ENCODER,COMMENT'
-               self.type_list = 'mp3,ogg,flac,wav,aiff'
-               self.net_backup_host = 'domain.com'
-               self.net_backup_dir = '/home/'+os.environ["USER"]+'/telemeta/'
+    def __init__(self) :
+        self.collection_name = 'telemeta_default'
+        self.collection_dir = '/home/'+os.environ["USER"]+'/telemeta_default/'
+        self.user_dir = '/home/'+os.environ["USER"]+'/.telemeta/'
+        self.default_tag_xml = '/home/'+os.environ["USER"]+'/.telemeta/default_tags.xml'
+        self.default_collection_xml = '/home/'+os.environ["USER"]+'/.telemeta/default_collection.xml'
+        self.tag_table = 'ARTIST,TITLE,ALBUM,DATE,GENRE,SOURCE,ENCODER,COMMENT'
+        self.type_list = 'mp3,ogg,flac,wav,aiff'
+        self.net_backup_host = 'domain.com'
+        self.net_backup_dir = '/home/'+os.environ["USER"]+'/telemeta/'
 
 #option_table=['enc_types','flac_bitrate','ogg_bitrate','mp3_bitrate','audio_marking','auto_audio_marking','audio_marking_file','audio_marking_timeline']
 
index f8ec9297bc2d8e4acf470a53860b54dab2e8c7bb..1db0e06074a781268e329ea13258b6afdaacc1ef 100644 (file)
@@ -14,47 +14,47 @@ import os
 
 class Tags :
 
-       def __init__(self) :
-               self.COLLECTION = 'Unknown'
-               self.ARTIST = 'Unknown'
-               self.TITLE = 'Unknown'
-               self.ALBUM = 'Unknown'
-               self.GENRE = 'Other'
-               self.DATE = '1900'
-               self.SOURCE = 'Here'
-               self.ENCODER = 'me@domain.com'
-               self.COMMENT = 'No comment'
-               self.ORIGINAL_MEDIA = '1/4" tape'
+    def __init__(self) :
+        self.COLLECTION = 'Unknown'
+        self.ARTIST = 'Unknown'
+        self.TITLE = 'Unknown'
+        self.ALBUM = 'Unknown'
+        self.GENRE = 'Other'
+        self.DATE = '1900'
+        self.SOURCE = 'Here'
+        self.ENCODER = 'me@domain.com'
+        self.COMMENT = 'No comment'
+        self.ORIGINAL_MEDIA = '1/4" tape'
 
 
 class Options :
 
-       def __init__(self) :
-               self.collection = 'Unknown'
-               self.enc_types = 'flac, ogg, mp3'
-               self.ogg_bitrate ='192'
-               self.mp3_bitrate = '192'
-               self.flac_quality = '5'
-               self.audio_marking = False
-               self.auto_audio_marking = True
-               self.audio_marking_file = '/path/to/file'
-               self.audio_marking_timeline = 'b, m, e'
-               self.par_key = True
-               self.normalize = False
+    def __init__(self) :
+        self.collection = 'Unknown'
+        self.enc_types = 'flac, ogg, mp3'
+        self.ogg_bitrate ='192'
+        self.mp3_bitrate = '192'
+        self.flac_quality = '5'
+        self.audio_marking = False
+        self.auto_audio_marking = True
+        self.audio_marking_file = '/path/to/file'
+        self.audio_marking_timeline = 'b, m, e'
+        self.par_key = True
+        self.normalize = False
 
 
 class Collection :
 
-       def __init__(self) :
-               self.collection_name = 'telemeta_default'
-               self.collection_dir = '/home/'+os.environ["USER"]+'/telemeta_default/'
-               self.user_dir = '/home/'+os.environ["USER"]+'/.telemeta/'
-               self.default_tag_xml = '/home/'+os.environ["USER"]+ \
-                                                          '/.telemeta/default_tags.xml'
-               self.default_collection_xml = '/home/'+os.environ["USER"]+ \
-                                                                         '/.telemeta/default_collection.xml'
-               self.tag_table = 'ARTIST,TITLE,ALBUM,DATE,GENRE,SOURCE,ENCODER,COMMENT'
-               self.type_list = 'mp3,ogg,flac,wav,aiff'
-               self.net_backup_host = 'domain.com'
-               self.net_backup_dir = '/home/'+os.environ["USER"]+'/telemeta/'
+    def __init__(self) :
+        self.collection_name = 'telemeta_default'
+        self.collection_dir = '/home/'+os.environ["USER"]+'/telemeta_default/'
+        self.user_dir = '/home/'+os.environ["USER"]+'/.telemeta/'
+        self.default_tag_xml = '/home/'+os.environ["USER"]+ \
+                               '/.telemeta/default_tags.xml'
+        self.default_collection_xml = '/home/'+os.environ["USER"]+ \
+                                      '/.telemeta/default_collection.xml'
+        self.tag_table = 'ARTIST,TITLE,ALBUM,DATE,GENRE,SOURCE,ENCODER,COMMENT'
+        self.type_list = 'mp3,ogg,flac,wav,aiff'
+        self.net_backup_host = 'domain.com'
+        self.net_backup_dir = '/home/'+os.environ["USER"]+'/telemeta/'
 
index 065e97b7fdab771f50296525c006b1875bfd289d..f03f966571c40e9de20fee3ad90f60665dbe56f8 100644 (file)
 
 class Options :
 
-       def __init__(self) :
-               self.collection = 'Unknown'
-               self.enc_types = 'flac, ogg, mp3'
-               self.ogg_bitrate ='192'
-               self.mp3_bitrate = '192'
-               self.flac_quality = '5'
-               self.audio_marking = False
-               self.auto_audio_marking = True
-               self.audio_marking_file = '/path/to/file'
-               self.audio_marking_timeline = 'b, m, e'
-               self.par_key = True
-               self.normalize = False
+    def __init__(self) :
+        self.collection = 'Unknown'
+        self.enc_types = 'flac, ogg, mp3'
+        self.ogg_bitrate ='192'
+        self.mp3_bitrate = '192'
+        self.flac_quality = '5'
+        self.audio_marking = False
+        self.auto_audio_marking = True
+        self.audio_marking_file = '/path/to/file'
+        self.audio_marking_timeline = 'b, m, e'
+        self.par_key = True
+        self.normalize = False
index a03c6207658ecff14d87bff27149fe18d925fed4..8cec9410c745ec511678dc9199618cdb602fbf0d 100644 (file)
 
 class Tags :
 
-       def __init__(self) :
-               self.COLLECTION = 'Unknown'
-               self.ARTIST = 'Unknown'
-               self.TITLE = 'Unknown'
-               self.ALBUM = 'Unknown'
-               self.GENRE = 'Other'
-               self.DATE = '1900'
-               self.SOURCE = 'Here'
-               self.ENCODER = 'me@domain.com'
-               self.COMMENT = 'No comment'
-               self.ORIGINAL_MEDIA = '1/4" tape'
+    def __init__(self) :
+        self.COLLECTION = 'Unknown'
+        self.ARTIST = 'Unknown'
+        self.TITLE = 'Unknown'
+        self.ALBUM = 'Unknown'
+        self.GENRE = 'Other'
+        self.DATE = '1900'
+        self.SOURCE = 'Here'
+        self.ENCODER = 'me@domain.com'
+        self.COMMENT = 'No comment'
+        self.ORIGINAL_MEDIA = '1/4" tape'
 
index a64af2789045db76d8742e65c3b3938cfb90acf6..2b784aabadc0f9888f815603eaea795460a40fb0 100644 (file)
@@ -38,272 +38,272 @@ collection = consts.Collection()
 # ============
 
 def write_collection_consts(fic):
-       doc = xml.dom.minidom.Document()
-       root = doc.createElement('telemeta')
-       doc.appendChild(root)
-       for data in collection.__dict__.keys() :
-               value = collection.__dict__[data]
-               node = doc.createElement('data')
-               node.setAttribute('name', data)
-               node.setAttribute('value', str(value))
-               node.setAttribute('type', typeToolBox.getType(value))
-               root.appendChild(node)
-       file_object = open(fic, "w")
-       xml.dom.ext.PrettyPrint(doc, file_object)
-       file_object.close()
+    doc = xml.dom.minidom.Document()
+    root = doc.createElement('telemeta')
+    doc.appendChild(root)
+    for data in collection.__dict__.keys() :
+        value = collection.__dict__[data]
+        node = doc.createElement('data')
+        node.setAttribute('name', data)
+        node.setAttribute('value', str(value))
+        node.setAttribute('type', typeToolBox.getType(value))
+        root.appendChild(node)
+    file_object = open(fic, "w")
+    xml.dom.ext.PrettyPrint(doc, file_object)
+    file_object.close()
 
 def get_collection_consts(doc):
-       for data in doc.documentElement.getElementsByTagName('data') :
-               name = data.getAttribute('name')
-               value = typeToolBox.cast(data.getAttribute('value'), data.getAttribute('type'))
-               collection.__dict__[name] = value
+    for data in doc.documentElement.getElementsByTagName('data') :
+        name = data.getAttribute('name')
+        value = typeToolBox.cast(data.getAttribute('value'), data.getAttribute('type'))
+        collection.__dict__[name] = value
 
 def ask_write_collection(name):
-       global collection
-       for data in collection.__dict__.keys() :
-               if data == 'collection_name' :
-                       def_value = name
-                       type_def_value = typeToolBox.getType(def_value)
-                       value = raw_input(data+' ? ['+str(def_value)+']: ')
-               elif data == 'default_collection_xml' :
-                       collection_xml = '/home/'+os.environ["USER"]+'/.telemeta/'+name+'.xml'
-                       type_def_collection = typeToolBox.getType(collection_xml)
-                       collection_tmp = typeToolBox.cast(collection_xml,type_def_collection)
-                       collection.__dict__[data] = collection_tmp
-                       value = collection.__dict__[data]
-               elif data == 'collection_dir' :
-                       collection_dir = '/home/'+os.environ["USER"]+'/'+name
-                       type_def_collection_dir = typeToolBox.getType(collection_dir)
-                       collection_tmp = typeToolBox.cast(collection_dir,type_def_collection_dir)
-                       collection.__dict__[data] = collection_tmp
-                       def_value = collection.__dict__[data]
-                       value = raw_input(data+' ? ['+str(def_value)+']: ')
-               elif data == 'user_dir' :
-                       def_value = '/home/'+os.environ["USER"]+'/.telemeta/'
-                       type_def_value = typeToolBox.getType(def_value)
-                       value = def_value
-               elif data == 'default_tag_xml' :
-                       def_value = '/home/'+os.environ["USER"]+'/.telemeta/default_tags.xml'
-                       type_def_value = typeToolBox.getType(def_value)
-                       value = def_value
-               else :
-                       def_value = collection.__dict__[data]
-                       type_def_value = typeToolBox.getType(def_value)
-                       value = raw_input(data+' ? ['+str(def_value)+']: ')
-               if not value == '' :
-                       value = typeToolBox.cast(value,type_def_value)
-                       #value = string.replace(in_float,' ','')
-                       collection.__dict__[data] = value
+    global collection
+    for data in collection.__dict__.keys() :
+        if data == 'collection_name' :
+            def_value = name
+            type_def_value = typeToolBox.getType(def_value)
+            value = raw_input(data+' ? ['+str(def_value)+']: ')
+        elif data == 'default_collection_xml' :
+            collection_xml = '/home/'+os.environ["USER"]+'/.telemeta/'+name+'.xml'
+            type_def_collection = typeToolBox.getType(collection_xml)
+            collection_tmp = typeToolBox.cast(collection_xml,type_def_collection)
+            collection.__dict__[data] = collection_tmp
+            value = collection.__dict__[data]
+        elif data == 'collection_dir' :
+            collection_dir = '/home/'+os.environ["USER"]+'/'+name
+            type_def_collection_dir = typeToolBox.getType(collection_dir)
+            collection_tmp = typeToolBox.cast(collection_dir,type_def_collection_dir)
+            collection.__dict__[data] = collection_tmp
+            def_value = collection.__dict__[data]
+            value = raw_input(data+' ? ['+str(def_value)+']: ')
+        elif data == 'user_dir' :
+            def_value = '/home/'+os.environ["USER"]+'/.telemeta/'
+            type_def_value = typeToolBox.getType(def_value)
+            value = def_value
+        elif data == 'default_tag_xml' :
+            def_value = '/home/'+os.environ["USER"]+'/.telemeta/default_tags.xml'
+            type_def_value = typeToolBox.getType(def_value)
+            value = def_value
+        else :
+            def_value = collection.__dict__[data]
+            type_def_value = typeToolBox.getType(def_value)
+            value = raw_input(data+' ? ['+str(def_value)+']: ')
+        if not value == '' :
+            value = typeToolBox.cast(value,type_def_value)
+            #value = string.replace(in_float,' ','')
+            collection.__dict__[data] = value
 
 def get_consts_value(data):
-       value = collection.__dict__[data]
-       type_value = typeToolBox.getType(value)
-       return value
+    value = collection.__dict__[data]
+    type_value = typeToolBox.getType(value)
+    return value
 
 # TAGS
 # =====
 
 def write_tags(enc_type,dir_out,file_out):
-       media_out = dir_out+file_out
-
-       if enc_type == 'flac':
-               audio = FLAC(media_out)
-               for tag in tags.__dict__.keys():
-                       if tag == 'COMMENT':
-                               audio['DESCRIPTION'] = tags.__dict__[tag]
-                       else:
-                               audio[tag] = tags.__dict__[tag]
-               audio.save()
-
-       if enc_type == 'ogg':
-               audio = OggVorbis(media_out)
-               for tag in tags.__dict__.keys():
-                       audio[tag] = tags.__dict__[tag]
-               audio.save()
-
-       if enc_type == 'mp3':
-               audio = ID3(media_out)
-               #tags = ['ALBUM','DATE','GENRE','SOURCE','ENCODER','COMMENT']
-               tag = tags.__dict__['TITLE']
-               audio.add(TIT2(encoding=3, text=tag))
-               tag = tags.__dict__['ARTIST']
-               audio.add(TP1(encoding=3, text=tag))
-               tag = tags.__dict__['ALBUM']
-               audio.add(TAL(encoding=3, text=tag))
-               tag = tags.__dict__['DATE']
-               audio.add(TDA(encoding=3, text=tag))
-               tag = tags.__dict__['GENRE']
-               audio.add(TCO(encoding=3, text=tag))
-               tag = tags.__dict__['COMMENT']
-               audio.add(COM(encoding=3, text=tag))
-               audio.save()
+    media_out = dir_out+file_out
+
+    if enc_type == 'flac':
+        audio = FLAC(media_out)
+        for tag in tags.__dict__.keys():
+            if tag == 'COMMENT':
+                audio['DESCRIPTION'] = tags.__dict__[tag]
+            else:
+                audio[tag] = tags.__dict__[tag]
+        audio.save()
+
+    if enc_type == 'ogg':
+        audio = OggVorbis(media_out)
+        for tag in tags.__dict__.keys():
+            audio[tag] = tags.__dict__[tag]
+        audio.save()
+
+    if enc_type == 'mp3':
+        audio = ID3(media_out)
+        #tags = ['ALBUM','DATE','GENRE','SOURCE','ENCODER','COMMENT']
+        tag = tags.__dict__['TITLE']
+        audio.add(TIT2(encoding=3, text=tag))
+        tag = tags.__dict__['ARTIST']
+        audio.add(TP1(encoding=3, text=tag))
+        tag = tags.__dict__['ALBUM']
+        audio.add(TAL(encoding=3, text=tag))
+        tag = tags.__dict__['DATE']
+        audio.add(TDA(encoding=3, text=tag))
+        tag = tags.__dict__['GENRE']
+        audio.add(TCO(encoding=3, text=tag))
+        tag = tags.__dict__['COMMENT']
+        audio.add(COM(encoding=3, text=tag))
+        audio.save()
 
 def write_def_tags(fic):
-       doc = xml.dom.minidom.Document()
-       root = doc.createElement('telemeta')
-       doc.appendChild(root)
-       for tag in tags.__dict__.keys() :
-               value = tags.__dict__[tag]
-               node = doc.createElement('tag')
-               node.setAttribute('name', tag)
-               node.setAttribute('value', str(value))
-               node.setAttribute('type', typeToolBox.getType(value))
-               root.appendChild(node)
-       for opt in options.__dict__.keys() :
-               value = options.__dict__[opt]
-               node = doc.createElement('opt')
-               node.setAttribute('name', opt)
-               node.setAttribute('value', str(value))
-               node.setAttribute('type', typeToolBox.getType(value))
-               root.appendChild(node)
-       file_object = open(fic, "w")
-       xml.dom.ext.PrettyPrint(doc, file_object)
-       file_object.close()
+    doc = xml.dom.minidom.Document()
+    root = doc.createElement('telemeta')
+    doc.appendChild(root)
+    for tag in tags.__dict__.keys() :
+        value = tags.__dict__[tag]
+        node = doc.createElement('tag')
+        node.setAttribute('name', tag)
+        node.setAttribute('value', str(value))
+        node.setAttribute('type', typeToolBox.getType(value))
+        root.appendChild(node)
+    for opt in options.__dict__.keys() :
+        value = options.__dict__[opt]
+        node = doc.createElement('opt')
+        node.setAttribute('name', opt)
+        node.setAttribute('value', str(value))
+        node.setAttribute('type', typeToolBox.getType(value))
+        root.appendChild(node)
+    file_object = open(fic, "w")
+    xml.dom.ext.PrettyPrint(doc, file_object)
+    file_object.close()
 
 def ask_write_tag():
-       global tags
-       global options
-       for tag in tags.__dict__.keys() :
-               def_value = tags.__dict__[tag]
-               type_def_value = typeToolBox.getType(def_value)
-               value = raw_input(tag+' ? ['+str(def_value)+']: ')
-               if not value == '' :
-                       value = typeToolBox.cast(value,type_def_value)
-                       #value = string.replace(in_float,' ','')
-                       tags.__dict__[tag] = value
-       for opt in options.__dict__.keys() :
-               def_value = options.__dict__[opt]
-               type_def_value = typeToolBox.getType(def_value)
-               value = raw_input(opt+' ? ['+str(def_value)+']: ')
-               if not value == '' :
-                       value = typeToolBox.cast(value,type_def_value)
-                       #value = string.replace(in_float,' ','')
-                       options.__dict__[opt] = value
+    global tags
+    global options
+    for tag in tags.__dict__.keys() :
+        def_value = tags.__dict__[tag]
+        type_def_value = typeToolBox.getType(def_value)
+        value = raw_input(tag+' ? ['+str(def_value)+']: ')
+        if not value == '' :
+            value = typeToolBox.cast(value,type_def_value)
+            #value = string.replace(in_float,' ','')
+            tags.__dict__[tag] = value
+    for opt in options.__dict__.keys() :
+        def_value = options.__dict__[opt]
+        type_def_value = typeToolBox.getType(def_value)
+        value = raw_input(opt+' ? ['+str(def_value)+']: ')
+        if not value == '' :
+            value = typeToolBox.cast(value,type_def_value)
+            #value = string.replace(in_float,' ','')
+            options.__dict__[opt] = value
 
 def get_def_tags(doc):
-       for tag in doc.documentElement.getElementsByTagName('tag') :
-               name = tag.getAttribute('name')
-               value = typeToolBox.cast(tag.getAttribute('value'), tag.getAttribute('type'))
-               tags.__dict__[name] = value
-       for opt in doc.documentElement.getElementsByTagName('opt') :
-               name = opt.getAttribute('name')
-               value = typeToolBox.cast(opt.getAttribute('value'), opt.getAttribute('type'))
-               options.__dict__[name] = value
+    for tag in doc.documentElement.getElementsByTagName('tag') :
+        name = tag.getAttribute('name')
+        value = typeToolBox.cast(tag.getAttribute('value'), tag.getAttribute('type'))
+        tags.__dict__[name] = value
+    for opt in doc.documentElement.getElementsByTagName('opt') :
+        name = opt.getAttribute('name')
+        value = typeToolBox.cast(opt.getAttribute('value'), opt.getAttribute('type'))
+        options.__dict__[name] = value
 
 def rename_tag(old_tag,new_tag):
-       tag_list = tags.__dict__.keys()
-       if old_tag in tag_list:
-               tag_index = tag_list.index(old_tag)
-               tag_list.remove(old_tag)
-               tag_list.insert(tag_index,new_tag)
+    tag_list = tags.__dict__.keys()
+    if old_tag in tag_list:
+        tag_index = tag_list.index(old_tag)
+        tag_list.remove(old_tag)
+        tag_list.insert(tag_index,new_tag)
 
 def get_tag_value(tag):
-       value = tags.__dict__[tag]
-       type_value = typeToolBox.getType(value)
-       return value
+    value = tags.__dict__[tag]
+    type_value = typeToolBox.getType(value)
+    return value
 
 def get_opt_value(opt):
-       value = options.__dict__[opt]
-       type_value = typeToolBox.getType(value)
-       return value
+    value = options.__dict__[opt]
+    type_value = typeToolBox.getType(value)
+    return value
 
 def add_tag(tag,value):
-       tag_list = tags.__dict__.keys()
-       tag_list.insert(0,tag)
-       tags.__dict__[tag] = value
+    tag_list = tags.__dict__.keys()
+    tag_list.insert(0,tag)
+    tags.__dict__[tag] = value
 
 def add_opt(opt,value):
-       opt_list = options.__dict__.keys()
-       opt_list.insert(0,opt)
-       options.__dict__[opt] = value
+    opt_list = options.__dict__.keys()
+    opt_list.insert(0,opt)
+    options.__dict__[opt] = value
 
 def rename_file(src_dir,file,file_name):
-       if (file_name != "" and file_name != file):
-               print "Renaming: %s -> %s\n" % (file,file_name)
-               os.rename(src_dir+file, src_dir+file_name)
+    if (file_name != "" and file_name != file):
+        print "Renaming: %s -> %s\n" % (file,file_name)
+        os.rename(src_dir+file, src_dir+file_name)
 
 def filename_split(file_name):
-       filename_split = file_name.split('.')
-       if len(filename_split) > 0:
-               file_ext = filename_split[len(filename_split)-1]
-       else:
-               file_ext = ''
-       file_name_woext = '.'.join(filename_split[:-1])
-       return file_name_woext, file_ext
+    filename_split = file_name.split('.')
+    if len(filename_split) > 0:
+        file_ext = filename_split[len(filename_split)-1]
+    else:
+        file_ext = ''
+    file_name_woext = '.'.join(filename_split[:-1])
+    return file_name_woext, file_ext
 
 #def check_ext():
-       #if not ext_is_audio(file):
-               #file_name_woext = file_name
-               #if iswav(src_dir+file) :
-                       #file_ext = "wav"
-               #if isaiff(src_dir+file) :
-                       #file_ext = "aiff"
-               #if ismp3(src_dir+file) :
-                       #file_ext = "mp3"
-               #if isogg(src_dir+file) :
-                       #file_ext = "ogg"
-               #if isflac(src_dir+file) :
-                       #file_ext = "flac"
+    #if not ext_is_audio(file):
+        #file_name_woext = file_name
+        #if iswav(src_dir+file) :
+            #file_ext = "wav"
+        #if isaiff(src_dir+file) :
+            #file_ext = "aiff"
+        #if ismp3(src_dir+file) :
+            #file_ext = "mp3"
+        #if isogg(src_dir+file) :
+            #file_ext = "ogg"
+        #if isflac(src_dir+file) :
+            #file_ext = "flac"
 
 def clean_filename(file_name) :
-       file_name = re.sub("^[^\w]+","",filename) #trim the beginning
-       file_name = re.sub("[^\w]+$","",file_name) #trim the end
-       file_name = string.replace(file_name,' ','_')
-       file_name = re.sub("_+","_",file_name) #squeeze continuous _ to one _
-       file_name = re.sub("^[^\w]+","",file_name) #trim the beginning _
-       #file_name = string.capitalize(file_name)
-       return file_name
+    file_name = re.sub("^[^\w]+","",filename) #trim the beginning
+    file_name = re.sub("[^\w]+$","",file_name) #trim the end
+    file_name = string.replace(file_name,' ','_')
+    file_name = re.sub("_+","_",file_name) #squeeze continuous _ to one _
+    file_name = re.sub("^[^\w]+","",file_name) #trim the beginning _
+    #file_name = string.capitalize(file_name)
+    return file_name
 
 def name2tag(src_dir,file_name_woext,file_ext):
-       # get main tag
-       tag_list = file_name_woext.split('-')
-       tag_list_new = range(len(tag_list))
-
-       #for num_t in tag_list[0]:
-       #       if num_t == str(int(num_t)):
-       #               i_t = 1
-       #       else:
-
-       # computing main tags if many tags
-       if len(tag_list) > 1 :
-               i_t = 0
-               artist_tmp = string.replace(tag_list[i_t],' ','_')
-               artist_tmp = artist_tmp.split('_')
-               i = 0
-               for artist_word in artist_tmp :
-                       artist_tmp[i] = string.capitalize(artist_word)
-                       i = i+1
-               artist = '_'.join(artist_tmp[:])
-               artist = re.sub("[\_]+$","",artist) #trim the end
-               tag_list_new[i_t] = artist
-               artist = string.replace(artist,'_',' ')
-
-               i_t = i_t + 1
-               title = string.replace(tag_list[i_t],' ','_')
-               title = re.sub("^[\_]+","",title) #trim the beginning
-               title = re.sub("[\_]+$","",title) #trim the end
-               title_tmp = title.split('_')
-               title_tmp[0] = string.capitalize(title_tmp[0])
-               title = '_'.join(title_tmp[:])
-               tag_list_new[i_t] = title
-               title = string.replace(title,'_',' ')
-
-       # computing main tag if only one tag
-       if len(tag_list) == 1 :
-               artist = get_tag_value('ARTIST')
-               i_t = 0
-               title = string.replace(tag_list[i_t],' ','_')
-               title = re.sub("^[\_]+","",title) #trim the beginning
-               title = re.sub("[\_]+$","",title) #trim the end
-               title_tmp = title.split('_')
-               title_tmp[0] = string.capitalize(title_tmp[0])
-               title = '_'.join(title_tmp[:])
-               tag_list_new[i_t] = title
-               title = string.replace(title,'_',' ')
-
-       file_name_new = '-'.join(tag_list_new[:])
-
-       # renaming main source file
-       file_name = file_name_new+'.'+file_ext
-
-       return title,artist,file_name_new
+    # get main tag
+    tag_list = file_name_woext.split('-')
+    tag_list_new = range(len(tag_list))
+
+    #for num_t in tag_list[0]:
+    #   if num_t == str(int(num_t)):
+    #       i_t = 1
+    #   else:
+
+    # computing main tags if many tags
+    if len(tag_list) > 1 :
+        i_t = 0
+        artist_tmp = string.replace(tag_list[i_t],' ','_')
+        artist_tmp = artist_tmp.split('_')
+        i = 0
+        for artist_word in artist_tmp :
+            artist_tmp[i] = string.capitalize(artist_word)
+            i = i+1
+        artist = '_'.join(artist_tmp[:])
+        artist = re.sub("[\_]+$","",artist) #trim the end
+        tag_list_new[i_t] = artist
+        artist = string.replace(artist,'_',' ')
+
+        i_t = i_t + 1
+        title = string.replace(tag_list[i_t],' ','_')
+        title = re.sub("^[\_]+","",title) #trim the beginning
+        title = re.sub("[\_]+$","",title) #trim the end
+        title_tmp = title.split('_')
+        title_tmp[0] = string.capitalize(title_tmp[0])
+        title = '_'.join(title_tmp[:])
+        tag_list_new[i_t] = title
+        title = string.replace(title,'_',' ')
+
+    # computing main tag if only one tag
+    if len(tag_list) == 1 :
+        artist = get_tag_value('ARTIST')
+        i_t = 0
+        title = string.replace(tag_list[i_t],' ','_')
+        title = re.sub("^[\_]+","",title) #trim the beginning
+        title = re.sub("[\_]+$","",title) #trim the end
+        title_tmp = title.split('_')
+        title_tmp[0] = string.capitalize(title_tmp[0])
+        title = '_'.join(title_tmp[:])
+        tag_list_new[i_t] = title
+        title = string.replace(title,'_',' ')
+
+    file_name_new = '-'.join(tag_list_new[:])
+
+    # renaming main source file
+    file_name = file_name_new+'.'+file_ext
+
+    return title,artist,file_name_new
index 0d5076262bca83106ca4701bffc7cc02cf44d311..3ae48530fbfd126c547c654dbc9477ed12d12e07 100644 (file)
@@ -42,75 +42,75 @@ from audio_tools import *
 # Info, error
 # ===========
 if len(sys.argv) == 1 :
-       print "telemeta v"+str(version)+" (c) 2006-2007 Guillaume Pellerin <yomguy@altern.org>>"
-       print "version: "+str(version)
-       print "depends: python, python-xml, python-mutagen, sox, oggenc, flac, lame, normalize-audio, ecasound, wavbreaker, festival"
-       print "distributed under the terms of the GNU Public License v2.\n"
-       print """   This program is distributed in the hope that it will be useful,
+    print "telemeta v"+str(version)+" (c) 2006-2007 Guillaume Pellerin <yomguy@altern.org>>"
+    print "version: "+str(version)
+    print "depends: python, python-xml, python-mutagen, sox, oggenc, flac, lame, normalize-audio, ecasound, wavbreaker, festival"
+    print "distributed under the terms of the GNU Public License v2.\n"
+    print """   This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.\n"""
-       sys.exit('Type telemeta --help for help !\n')
+    sys.exit('Type telemeta --help for help !\n')
 
 elif sys.argv[1] == '--help':
-       print "TELEMETA:"
-       print "         backups, transcodes, tags and marks any audio content with metadata\n"
-       print "VERSION:"
-       print "         "+str(version)+'\n'
-       print "DEPENDS:"
-       print "         python, python-xml, python-mutagen, sox, oggenc, flac, lame, normalize-audio, ecasound, wavbreaker, festival\n"
-       print "COPYRIGHT:"
-       print "         Copyright (c) 2006-2007 Guillaume Pellerin <yomguy@altern.org>\n"
-       print "LICENSE:"
-       print "         distributed under the terms of the GNU Public License v2.\n"
-       print "USAGE:"
-       print "         telemeta [OPTIONS] COLLECTION [OPTIONS] [MEDIA] \n"
-       print "COLLECTION:"
-       print "         - the name of collection you want to create"
-       print "         - the name of collection you want to backup or process into\n"
-       print "MEDIA:"
-       print "         - an audio file"
-       print "         - a directory when the --album option is given\n"
-       print "OPTIONS:"
-       print "         --create       creates a collection repository"
-       print "         --backup       backups and transcodes wave files to a collection"
-       print "         --album        proccesses an entire directory (one shot album)"
-       print "         --from-xml     takes tags and opts in original xml source"
-       print "         --force        forces file conversion"
-       print "         --add-tag      add a tag to a collection"
-       print '         --par2         forces security "par2" key creation'
-       print "         --all-default  chooses default argument for all question"
-       print '         --recover      check an repair the backuped media with the previously created "par2" security key'
-       print "         --rsync        synchronizes a collection with a remote server repository (ssh+rsync)"
-       print "         --erase        erases a collection (flac, ogg, mp3 only !)"
-       print "         --version      gives the program version"
-       print "         --help         gives help page\n"
-       print "EXAMPLES:"       
-       print "         telemeta --create my_collection"
-       print "         telemeta --backup my_collection file.wav"
-       print "         telemeta --backup my_collection --album /path/to/directory/"
-       print "         telemeta --backup my_collection --album --par2 --rsync /path/to/directory/"
-       print "         telemeta --backup my_collection --album --par2 --rsync --force /path/to/directory/\n"
-       print "AUTHOR:"
-       print "         Guillaume Pellerin <yomguy@altern.org>\n"
-       print "URL:"
-       print "         http://svn.parisson.org/telemeta\n"
-       print 'IMPORTANT:'
-       print "         With the '--album' option, it supposed that all your wav files in the directory are named respectively to this scheme :"
-       print "            artist-title[-album-date-genre-description][.wav]"
-       print "         where the 'artist' and 'title' tags are necessary needed."
-       print "         Tags between [] are optional main tags.\n"
-       print "FOR MORE INFORMATIONS :"
-       print "         - read the README file"
-       print "         - go to http://svn.parisson.org/telemeta"
-       sys.exit('         - email me !\n')
+    print "TELEMETA:"
+    print "         backups, transcodes, tags and marks any audio content with metadata\n"
+    print "VERSION:"
+    print "         "+str(version)+'\n'
+    print "DEPENDS:"
+    print "         python, python-xml, python-mutagen, sox, oggenc, flac, lame, normalize-audio, ecasound, wavbreaker, festival\n"
+    print "COPYRIGHT:"
+    print "         Copyright (c) 2006-2007 Guillaume Pellerin <yomguy@altern.org>\n"
+    print "LICENSE:"
+    print "         distributed under the terms of the GNU Public License v2.\n"
+    print "USAGE:"
+    print "         telemeta [OPTIONS] COLLECTION [OPTIONS] [MEDIA] \n"
+    print "COLLECTION:"
+    print "         - the name of collection you want to create"
+    print "         - the name of collection you want to backup or process into\n"
+    print "MEDIA:"
+    print "         - an audio file"
+    print "         - a directory when the --album option is given\n"
+    print "OPTIONS:"
+    print "         --create       creates a collection repository"
+    print "         --backup       backups and transcodes wave files to a collection"
+    print "         --album        proccesses an entire directory (one shot album)"
+    print "         --from-xml     takes tags and opts in original xml source"
+    print "         --force        forces file conversion"
+    print "         --add-tag      add a tag to a collection"
+    print '         --par2         forces security "par2" key creation'
+    print "         --all-default  chooses default argument for all question"
+    print '         --recover      check an repair the backuped media with the previously created "par2" security key'
+    print "         --rsync        synchronizes a collection with a remote server repository (ssh+rsync)"
+    print "         --erase        erases a collection (flac, ogg, mp3 only !)"
+    print "         --version      gives the program version"
+    print "         --help         gives help page\n"
+    print "EXAMPLES:"   
+    print "         telemeta --create my_collection"
+    print "         telemeta --backup my_collection file.wav"
+    print "         telemeta --backup my_collection --album /path/to/directory/"
+    print "         telemeta --backup my_collection --album --par2 --rsync /path/to/directory/"
+    print "         telemeta --backup my_collection --album --par2 --rsync --force /path/to/directory/\n"
+    print "AUTHOR:"
+    print "         Guillaume Pellerin <yomguy@altern.org>\n"
+    print "URL:"
+    print "         http://svn.parisson.org/telemeta\n"
+    print 'IMPORTANT:'
+    print "         With the '--album' option, it supposed that all your wav files in the directory are named respectively to this scheme :"
+    print "            artist-title[-album-date-genre-description][.wav]"
+    print "         where the 'artist' and 'title' tags are necessary needed."
+    print "         Tags between [] are optional main tags.\n"
+    print "FOR MORE INFORMATIONS :"
+    print "         - read the README file"
+    print "         - go to http://svn.parisson.org/telemeta"
+    sys.exit('         - email me !\n')
 
 elif sys.argv[1] == '--version':
-       sys.exit('Version: '+str(version))
+    sys.exit('Version: '+str(version))
 
 else :
-       print "telemeta v"+str(version)+" (c) 2006-2007 Guillaume Pellerin <yomguy@altern.org>"
-       print """   This program is distributed in the hope that it will be useful,
+    print "telemeta v"+str(version)+" (c) 2006-2007 Guillaume Pellerin <yomguy@altern.org>"
+    print """   This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.\n"""
@@ -127,128 +127,128 @@ collection = consts.Collection()
 
 # Get arguments
 if '--recover' in argv :
-       index = argv.index('--recover')
-       audio_tools.recover_par_key(argv[index+1]+os.sep)
-       sys.exit('Directory successfully recovered !')
+    index = argv.index('--recover')
+    audio_tools.recover_par_key(argv[index+1]+os.sep)
+    sys.exit('Directory successfully recovered !')
 
 if '--erase' in argv :
-       type_list = tag_tools.get_consts_value('type_list')
-       type_list = type_list.split(',')
-       index = argv.index('--erase')
-       audio_tools.clean_directory(argv[index+1],type_list)
-       sys.exit('Media directories successfully cleaned !')
+    type_list = tag_tools.get_consts_value('type_list')
+    type_list = type_list.split(',')
+    index = argv.index('--erase')
+    audio_tools.clean_directory(argv[index+1],type_list)
+    sys.exit('Media directories successfully cleaned !')
 
 if '--force' in argv :
-       print 'Warning: forcing file transfert and conversion (no audio test) !\n'
-       mode_force = True
+    print 'Warning: forcing file transfert and conversion (no audio test) !\n'
+    mode_force = True
 else :
-       mode_force = False
+    mode_force = False
 
 if '--album' in argv :
-       print 'Warning: album (recusive) mode...\n'
-       mode_album = True
+    print 'Warning: album (recusive) mode...\n'
+    mode_album = True
 else :
-       mode_album = False
+    mode_album = False
 
 if '--backup' in argv :
-       print 'Warning: backup mode...\n'
-       mode_backup = True
+    print 'Warning: backup mode...\n'
+    mode_backup = True
 else :
-       mode_backup = False
+    mode_backup = False
 
 if '--tags' in argv :
-       print 'Warning: making tags...\n'
-       mode_tags = True
+    print 'Warning: making tags...\n'
+    mode_tags = True
 else :
-       mode_tags = False
+    mode_tags = False
 
 if '--add-tag' in argv :
-       print 'Warning: adding tags...\n'
-       mode_add_tag = True
+    print 'Warning: adding tags...\n'
+    mode_add_tag = True
 else :
-       mode_add_tag = False
+    mode_add_tag = False
 
 if '--from-xml' in argv :
-       print 'Warning: processing from XML...\n'
-       mode_from_xml = True
+    print 'Warning: processing from XML...\n'
+    mode_from_xml = True
 else :
-       mode_from_xml = False
+    mode_from_xml = False
 
 if '--clean-strings' in argv :
-       print 'Warning: Cleaning strings...\n'
-       mode_clean = True
+    print 'Warning: Cleaning strings...\n'
+    mode_clean = True
 else :
-       mode_clean = False
+    mode_clean = False
 
 if '--all-default' in argv :
-       print 'Warning: default mode enabled...\n'
-       mode_default = True
+    print 'Warning: default mode enabled...\n'
+    mode_default = True
 else :
-       mode_default = False
+    mode_default = False
 
 if '--par2' in argv :
-       print 'Warning: creates par2 security keys...\n'
-       mode_par2 = True
+    print 'Warning: creates par2 security keys...\n'
+    mode_par2 = True
 else :
-       mode_par2 = False
+    mode_par2 = False
 
 if '--rsync' in argv :
-       print 'Warning: synchronize with remote host...\n'
-       mode_rsync = True
+    print 'Warning: synchronize with remote host...\n'
+    mode_rsync = True
 else :
-       mode_rsync = False
+    mode_rsync = False
 
 if '--create' in argv :
-       print 'Warning: creating a telemeta collection...\n'
-       mode_create = True
+    print 'Warning: creating a telemeta collection...\n'
+    mode_create = True
 else :
-       mode_create = False
+    mode_create = False
 
 # Creates user default dir
 user_dir = tag_tools.get_consts_value('user_dir')
 if not os.path.exists(user_dir):
-       os.mkdir(user_dir)
+    os.mkdir(user_dir)
 
 # Create or check the databse config
 default_collection_xml = tag_tools.get_consts_value('default_collection_xml')
 if not os.access(default_collection_xml, os.F_OK) :
-       tag_tools.write_collection_consts(default_collection_xml)
+    tag_tools.write_collection_consts(default_collection_xml)
 
 # Create the collection
 if mode_create :
-       if len(argv) == 3 :
-               index = argv.index('--create')
-               collection_name = argv[index+1]
-               tag_tools.ask_write_collection(collection_name)
-               default_collection_xml = tag_tools.get_consts_value('default_collection_xml')
-               collection_dir = tag_tools.get_consts_value('collection_dir')
-               if not os.path.exists(collection_dir):
-                       os.mkdir(collection_dir)
-               else :
-                               sys.exit('ERROR: the collection '+collection_name+' already exists')
-               tag_tools.write_collection_consts(default_collection_xml)
-               tag_tools.write_collection_consts(collection_dir+os.sep+collection_name+'.xml')
-               # Parses collection data
-               sys.exit("\nCollection created ! You can now --backup media in it...")
-       else :
-               sys.exit("ERROR: no collection name given... : give a name for your collection.")
+    if len(argv) == 3 :
+        index = argv.index('--create')
+        collection_name = argv[index+1]
+        tag_tools.ask_write_collection(collection_name)
+        default_collection_xml = tag_tools.get_consts_value('default_collection_xml')
+        collection_dir = tag_tools.get_consts_value('collection_dir')
+        if not os.path.exists(collection_dir):
+            os.mkdir(collection_dir)
+        else :
+                sys.exit('ERROR: the collection '+collection_name+' already exists')
+        tag_tools.write_collection_consts(default_collection_xml)
+        tag_tools.write_collection_consts(collection_dir+os.sep+collection_name+'.xml')
+        # Parses collection data
+        sys.exit("\nCollection created ! You can now --backup media in it...")
+    else :
+        sys.exit("ERROR: no collection name given... : give a name for your collection.")
 # Backup into the collection
 elif mode_backup :
-       # Check syntax
-       if not os.path.exists(sys.argv[len(sys.argv)-1]) :
-               sys.exit("ERROR: no such media... : give a directory or a file as last argument.")
-       index = argv.index('--backup')
-       collection_name = argv[index+1]
-       collection_xml = user_dir+os.sep+collection_name+'.xml'
-       if not os.path.exists(collection_xml) :
-               sys.exit("This collection doesn't exists. Create it first ! (--create)")
-       else :
-               doc = xml.dom.minidom.parse(user_dir+os.sep+collection_name+'.xml')
-               print "Parsing collection XML file..."
-               tag_tools.get_collection_consts(doc)
-               collection_dir = tag_tools.get_consts_value('collection_dir')
-               print "OK\n"
-       
+    # Check syntax
+    if not os.path.exists(sys.argv[len(sys.argv)-1]) :
+        sys.exit("ERROR: no such media... : give a directory or a file as last argument.")
+    index = argv.index('--backup')
+    collection_name = argv[index+1]
+    collection_xml = user_dir+os.sep+collection_name+'.xml'
+    if not os.path.exists(collection_xml) :
+        sys.exit("This collection doesn't exists. Create it first ! (--create)")
+    else :
+        doc = xml.dom.minidom.parse(user_dir+os.sep+collection_name+'.xml')
+        print "Parsing collection XML file..."
+        tag_tools.get_collection_consts(doc)
+        collection_dir = tag_tools.get_consts_value('collection_dir')
+        print "OK\n"
+    
 
 # Creates source dir
 src_dir = collection_dir+os.sep+'src'+os.sep
@@ -258,7 +258,7 @@ if not os.path.exists(src_dir) :
 # Creates user default tag/opt file and parse it
 default_tag_xml = tag_tools.get_consts_value('default_tag_xml')
 if not os.access(default_tag_xml, os.F_OK) :
-       tag_tools.write_def_tags(default_tag_xml)
+    tag_tools.write_def_tags(default_tag_xml)
 
 # Parses tag data
 doc = xml.dom.minidom.parse(default_tag_xml)
@@ -269,192 +269,192 @@ file_master_list = range(1)
 
 # File listing for album mode
 if mode_album :
-       master_dir = argv[len_argv-1]+os.sep
-       if os.path.isdir(master_dir):
-               file_master_list = os.listdir(master_dir)
-       else:
-               sys.exit('Please give a directory path for the last argument (album mode)...')
+    master_dir = argv[len_argv-1]+os.sep
+    if os.path.isdir(master_dir):
+        file_master_list = os.listdir(master_dir)
+    else:
+        sys.exit('Please give a directory path for the last argument (album mode)...')
 # File listing in normal mode
 else :
-       master_dir = argv[len_argv-1]
-       if os.path.isdir(master_dir):
-               file_master_list = os.listdir(master_dir)
-       elif os.path.isfile(master_dir):
-               master_dir = os.getcwd()+os.sep
-               file_master_list[0] = str(argv[len_argv-1])
-       else:
-               sys.exit('Please give a directory or a file path for the last argument...')
+    master_dir = argv[len_argv-1]
+    if os.path.isdir(master_dir):
+        file_master_list = os.listdir(master_dir)
+    elif os.path.isfile(master_dir):
+        master_dir = os.getcwd()+os.sep
+        file_master_list[0] = str(argv[len_argv-1])
+    else:
+        sys.exit('Please give a directory or a file path for the last argument...')
 
 # Asks tags if mode album
 if mode_album and not mode_from_xml :
-       tag_tools.ask_write_tag()
-       tag_tools.write_def_tags(default_tag_xml)
+    tag_tools.ask_write_tag()
+    tag_tools.write_def_tags(default_tag_xml)
 
 
 # Main loop
 # =========
 
 for file in file_master_list :
-       if isaudio(master_dir+os.sep+file) or (mode_force and ext_is_audio(master_dir+os.sep+file)):
-               print '\n'
-               print '+------------------------------------------------------------------------------------'
-               print '| Processing '+master_dir+file
-               print '+------------------------------------------------------------------------------------'
-
-               # Init
-               file_name = file
-               file_in = file
-               dir_in = src_dir
-
-               # Backup mode
-               if mode_backup :
-                       album_dir_tmp = tag_tools.get_tag_value('ALBUM')
-                       album_dir = collection_dir+os.sep+'src'+os.sep+album_dir_tmp+os.sep
-                       if not os.path.exists(album_dir) :
-                               os.mkdir(album_dir)
-                       if isaudio(master_dir+file) and ( not audio_tools.compare_md5_key(master_dir+file,album_dir+file) or mode_force ) :
-                               print 'Copying files into: '+album_dir+''
-                               os.system('cp -ra "'+master_dir+file+'" '+album_dir)
-                               print 'OK\n'
-                       #else:
-                       #       sys.exit(master_dir+file+' is not an audio file...')
-                       src_dir = album_dir
-                       dir_in = src_dir
-               else :
-                       dir_in = master_dir
-
-               # Creating par2 key
-               par_key_value = tag_tools.get_opt_value('par_key')
-               if mode_par2 and par_key_value :
-                       # Creating "par2" security keys
-                       print 'Creating "par2" security keys...'
-                       audio_tools.create_par_key(dir_in,file)
-
-               # Name, extension
-               file_name_woext, file_ext = tag_tools.filename_split(file)
-               tag_tools.add_tag('ORIGINAL_FILENAME',file)
-               tag_tools.add_tag('ORIGINAL_TYPE',file_ext)
-
-               # Get original XML
-               if mode_from_xml :
-                       doc = xml.dom.minidom.parse(dir_in+file_name+'.xml')
-                       tag_tools.get_def_tags(doc)
-
-               # Album mode
-               if mode_album :
-                       # Getting file main tags
-                       title,artist,file_name_new = tag_tools.name2tag(dir_in,file_name_woext,file_ext)
-                       tag_tools.add_tag('ARTIST',artist)
-                       tag_tools.add_tag('TITLE',title)
-                       print "Artist: "+artist
-                       print "Title: "+title+'\n'
-                       #tag_tools.write_def_tags(default_tag_xml)
-
-               # Asks for new metadata and write default user tags/options
-               if not mode_default and not mode_from_xml and not mode_album:
-                       tag_tools.ask_write_tag()
-               tag_tools.write_def_tags(default_tag_xml)
-
-
-
-               # Clean mode
-               if mode_clean :
-                       file_name = tag_tools.clean_filename(file_name)
-                       # Renaming backup source file
-                       tag_tools.rename_file(dir_in,dir_out,file,file_name)
-
-               # Writing xml data
-               if not mode_from_xml :
-                       print 'Writing xml data...'
-                       tag_tools.write_def_tags(dir_in+file_name+'.xml')
-
-               # Getting encoding types
-               enc_types = tag_tools.get_opt_value('enc_types')
-               enc_types = string.replace(enc_types,' ','').split(',')
-
-               # Checking existing file
-               for enc_type in enc_types:
-                       dir_out = master_dir+enc_type+os.sep
-                       file_out = file_name_woext+'.'+enc_type
-                       if not os.path.exists(dir_out+file_out):
-                               new_track = True
-                       else :
-                               new_track = False
-
-               # Decoding to a new 16 bits wav file if needed
-               if not iswav16(dir_in+file_in) and new_track:
-                       print "Decoding to wav 16 bits..."
-                       audio_tools.decode(dir_in+file_in,file_ext)
-                       # Important !
-                       type_list = tag_tools.get_consts_value('type_list')
-                       type_list = type_list.split(',')
-                       if not file_ext in type_list :
-                               file_in=file_in+'.wav'
-
-               # Normalize file if needed
-               normalize_value = tag_tools.get_opt_value('normalize')
-               if normalize_value:
-                       print 'Normalizing...'
-                       audio_tools.normalize(dir_in+file_in)
-
-               # Marking
-               audio_marking_value = tag_tools.get_opt_value('audio_marking')
-               auto_audio_marking = tag_tools.get_opt_value('auto_audio_marking')
-               audio_marking_file = tag_tools.get_opt_value('audio_marking_file')
-               audio_marking_timeline = tag_tools.get_opt_value('audio_marking_timeline')
-               audio_marking_timeline = string.replace(audio_marking_timeline,' ','').split(',')
-               if audio_marking_value and new_track:
-                       if auto_audio_marking:
-                               print 'Creating track audio mark...'
-                               audio_marking.make_auto_mark(dir_in,file_in)
-                               audio_marking_file = dir_in+file_in+'_mark.wav'
-                       print 'Marking '+file_in+' with '+audio_marking_file+'...'
-                       audio_marking.mark_audio(dir_in,file_in,audio_marking_file,audio_marking_timeline)
-                       file_in = 'marked_'+file_in
-
-               # Encoding loop
-               for enc_type in enc_types:
-                       dir_out = collection_dir+os.sep+enc_type+os.sep
-                       if not os.path.exists(dir_out):
-                               os.mkdir(dir_out)
-                       album = tag_tools.get_tag_value('ALBUM')
-                       dir_out = collection_dir+os.sep+enc_type+os.sep+album+os.sep
-                       if not os.path.exists(dir_out):
-                               os.mkdir(dir_out)
-                       file_out = file_name_woext+'.'+enc_type
-
-                       if not os.path.exists(dir_out+file_out) or mode_force :
-                               print 'Converting '+dir_in+file_name+' to '+enc_type+'...'
-                               # Encoding
-                               print 'Encoding file...'
-                               audio_tools.encode(enc_type,dir_in,file_in,dir_out,file_out)
-                               print 'Writing tags to encoded file...'
-                               tag_tools.write_tags(enc_type,dir_out,file_out)
-
-                       else :
-                               print dir_out+file_out+' already exists !'
-                               if mode_tags :
-                                       print 'But writing tags to encoded file...'
-                                       tag_tools.write_tags(enc_type,dir_out,file_out)
-
-               # Remove tmp files
-               file_list = os.listdir(src_dir)
-               for file in file_list:
-                       if 'marked_' in file or '.ewf' in file or '_mark.wav' in file or file_ext+'.wav' in file:
-                               os.system('rm "'+dir_in+file+'"')
-
-       else :
-               print file+" is not an audio file !"
+    if isaudio(master_dir+os.sep+file) or (mode_force and ext_is_audio(master_dir+os.sep+file)):
+        print '\n'
+        print '+------------------------------------------------------------------------------------'
+        print '| Processing '+master_dir+file
+        print '+------------------------------------------------------------------------------------'
+
+        # Init
+        file_name = file
+        file_in = file
+        dir_in = src_dir
+
+        # Backup mode
+        if mode_backup :
+            album_dir_tmp = tag_tools.get_tag_value('ALBUM')
+            album_dir = collection_dir+os.sep+'src'+os.sep+album_dir_tmp+os.sep
+            if not os.path.exists(album_dir) :
+                os.mkdir(album_dir)
+            if isaudio(master_dir+file) and ( not audio_tools.compare_md5_key(master_dir+file,album_dir+file) or mode_force ) :
+                print 'Copying files into: '+album_dir+''
+                os.system('cp -ra "'+master_dir+file+'" '+album_dir)
+                print 'OK\n'
+            #else:
+            #   sys.exit(master_dir+file+' is not an audio file...')
+            src_dir = album_dir
+            dir_in = src_dir
+        else :
+            dir_in = master_dir
+
+        # Creating par2 key
+        par_key_value = tag_tools.get_opt_value('par_key')
+        if mode_par2 and par_key_value :
+            # Creating "par2" security keys
+            print 'Creating "par2" security keys...'
+            audio_tools.create_par_key(dir_in,file)
+
+        # Name, extension
+        file_name_woext, file_ext = tag_tools.filename_split(file)
+        tag_tools.add_tag('ORIGINAL_FILENAME',file)
+        tag_tools.add_tag('ORIGINAL_TYPE',file_ext)
+
+        # Get original XML
+        if mode_from_xml :
+            doc = xml.dom.minidom.parse(dir_in+file_name+'.xml')
+            tag_tools.get_def_tags(doc)
+
+        # Album mode
+        if mode_album :
+            # Getting file main tags
+            title,artist,file_name_new = tag_tools.name2tag(dir_in,file_name_woext,file_ext)
+            tag_tools.add_tag('ARTIST',artist)
+            tag_tools.add_tag('TITLE',title)
+            print "Artist: "+artist
+            print "Title: "+title+'\n'
+            #tag_tools.write_def_tags(default_tag_xml)
+
+        # Asks for new metadata and write default user tags/options
+        if not mode_default and not mode_from_xml and not mode_album:
+            tag_tools.ask_write_tag()
+        tag_tools.write_def_tags(default_tag_xml)
+
+
+
+        # Clean mode
+        if mode_clean :
+            file_name = tag_tools.clean_filename(file_name)
+            # Renaming backup source file
+            tag_tools.rename_file(dir_in,dir_out,file,file_name)
+
+        # Writing xml data
+        if not mode_from_xml :
+            print 'Writing xml data...'
+            tag_tools.write_def_tags(dir_in+file_name+'.xml')
+
+        # Getting encoding types
+        enc_types = tag_tools.get_opt_value('enc_types')
+        enc_types = string.replace(enc_types,' ','').split(',')
+
+        # Checking existing file
+        for enc_type in enc_types:
+            dir_out = master_dir+enc_type+os.sep
+            file_out = file_name_woext+'.'+enc_type
+            if not os.path.exists(dir_out+file_out):
+                new_track = True
+            else :
+                new_track = False
+
+        # Decoding to a new 16 bits wav file if needed
+        if not iswav16(dir_in+file_in) and new_track:
+            print "Decoding to wav 16 bits..."
+            audio_tools.decode(dir_in+file_in,file_ext)
+            # Important !
+            type_list = tag_tools.get_consts_value('type_list')
+            type_list = type_list.split(',')
+            if not file_ext in type_list :
+                file_in=file_in+'.wav'
+
+        # Normalize file if needed
+        normalize_value = tag_tools.get_opt_value('normalize')
+        if normalize_value:
+            print 'Normalizing...'
+            audio_tools.normalize(dir_in+file_in)
+
+        # Marking
+        audio_marking_value = tag_tools.get_opt_value('audio_marking')
+        auto_audio_marking = tag_tools.get_opt_value('auto_audio_marking')
+        audio_marking_file = tag_tools.get_opt_value('audio_marking_file')
+        audio_marking_timeline = tag_tools.get_opt_value('audio_marking_timeline')
+        audio_marking_timeline = string.replace(audio_marking_timeline,' ','').split(',')
+        if audio_marking_value and new_track:
+            if auto_audio_marking:
+                print 'Creating track audio mark...'
+                audio_marking.make_auto_mark(dir_in,file_in)
+                audio_marking_file = dir_in+file_in+'_mark.wav'
+            print 'Marking '+file_in+' with '+audio_marking_file+'...'
+            audio_marking.mark_audio(dir_in,file_in,audio_marking_file,audio_marking_timeline)
+            file_in = 'marked_'+file_in
+
+        # Encoding loop
+        for enc_type in enc_types:
+            dir_out = collection_dir+os.sep+enc_type+os.sep
+            if not os.path.exists(dir_out):
+                os.mkdir(dir_out)
+            album = tag_tools.get_tag_value('ALBUM')
+            dir_out = collection_dir+os.sep+enc_type+os.sep+album+os.sep
+            if not os.path.exists(dir_out):
+                os.mkdir(dir_out)
+            file_out = file_name_woext+'.'+enc_type
+
+            if not os.path.exists(dir_out+file_out) or mode_force :
+                print 'Converting '+dir_in+file_name+' to '+enc_type+'...'
+                # Encoding
+                print 'Encoding file...'
+                audio_tools.encode(enc_type,dir_in,file_in,dir_out,file_out)
+                print 'Writing tags to encoded file...'
+                tag_tools.write_tags(enc_type,dir_out,file_out)
+
+            else :
+                print dir_out+file_out+' already exists !'
+                if mode_tags :
+                    print 'But writing tags to encoded file...'
+                    tag_tools.write_tags(enc_type,dir_out,file_out)
+
+        # Remove tmp files
+        file_list = os.listdir(src_dir)
+        for file in file_list:
+            if 'marked_' in file or '.ewf' in file or '_mark.wav' in file or file_ext+'.wav' in file:
+                os.system('rm "'+dir_in+file+'"')
+
+    else :
+        print file+" is not an audio file !"
 
 # Sync to the remote server
 if mode_rsync :
-       net_backup_host = tag_tools.get_consts_value('net_backup_host')
-       net_backup_dir = tag_tools.get_consts_value('net_backup_dir')
-       print '+------------------------------------------------------------------------------------'
-       print '| Synchronizing with '+net_backup_host
-       print '+------------------------------------------------------------------------------------'
-       os.system('rsync -avzLp --delete --rsh="ssh -l '+os.environ["USER"]+'" '+collection_dir+' '+os.environ["USER"]+'@'+net_backup_host+':'+net_backup_dir)
-       print "Collection Synchronized !"
+    net_backup_host = tag_tools.get_consts_value('net_backup_host')
+    net_backup_dir = tag_tools.get_consts_value('net_backup_dir')
+    print '+------------------------------------------------------------------------------------'
+    print '| Synchronizing with '+net_backup_host
+    print '+------------------------------------------------------------------------------------'
+    os.system('rsync -avzLp --delete --rsh="ssh -l '+os.environ["USER"]+'" '+collection_dir+' '+os.environ["USER"]+'@'+net_backup_host+':'+net_backup_dir)
+    print "Collection Synchronized !"
 
 
 # End
index 020ea24895a0219d5928e9eca91ca82eda543b97..a02590c333319920541666b14de828b40d36506a 100644 (file)
@@ -10,7 +10,7 @@
 # are also available at http://svn.parisson.org/telemeta/TelemetaLicense.
 #
 # Author: Olivier Guilyardi <olivier@samalyse.com>
-#                Guillaume Pellerin <pellerin@parisson.com>
+#         Guillaume Pellerin <pellerin@parisson.com>
 
 from telemeta.core import *
 
@@ -55,7 +55,7 @@ class IExporter(Interface):
         resource
 
         source is the audio/video source file absolute path. For audio that
-               should be a WAV file
+        should be a WAV file
 
         metadata is a dictionary
 
@@ -63,8 +63,8 @@ class IExporter(Interface):
         should be considered temporary/volatile by the caller.
 
         It is highly recommended that export drivers implement some sort of
-               cache instead of re-encoding each time process() is called.
+        cache instead of re-encoding each time process() is called.
 
         It should be possible to make subsequent calls to process() with
-               different items, using the same driver instance.
+        different items, using the same driver instance.
         """
index fffd0d9c0f0e641c04c14b95c03960315c40c4dc..7e176328e3540d45684468451d4eeb2250368c27 100644 (file)
@@ -22,231 +22,231 @@ import xml.dom.minidom
 import xml.dom.ext
 
 class ExporterCore(Component):
-       """Defines the main parts of the exporting tools :
-       paths, formats, metadata..."""
-
-       def __init__(self):
-               self.source = ''
-               self.collection = ''
-               self.verbose = ''
-               self.dest = ''
-               self.metadata = []
-               self.cache_dir = 'cache'
-
-       def set_cache_dir(self,path):
-               self.cache_dir = path
-
-       def normalize(self):
-               """ Normalize the source and return its path """
-               args = ''
-               if self.verbose == '0':
-                       args = '-q'
-               try:
-                       os.system('normalize-audio '+args+' "'+self.source+'"')
-                       return self.source
-               except IOError:
-                       return 'Exporter error: Cannot normalize, path does not exist.'
-
-       def check_md5_key(self):
-               """ Check if the md5 key is OK and return a boolean """
-               try:
-                       md5_log = os.popen4('md5sum -c "'+self.dest+ \
-                                                               '" "'+self.dest+'.md5"')
-                       return 'OK' in md5_log.split(':')
-               except IOError:
-                       return 'Exporter error: Cannot check the md5 key...'
-       
-       def get_file_info(self):
-               """ Return the list of informations of the dest """
-               return self.export.get_file_info()
-
-       def get_wav_length_sec(self) :
-               """ Return the length of the audio source file in seconds """
-               try:
-                       file1, file2 = os.popen4('wavinfo "'+self.source+ \
-                                                                        '" | grep wavDataSize')
-                       for line in file2.readlines():
-                               line_split = line.split(':')
-                               value = int(int(line_split[1])/(4*44100))
-                               return value
-               except IOError:
-                       return 'Exporter error: Cannot get the wav length...'
-
-       def compare_md5_key(self):
-               """ Compare 2 files wih md5 method """
-               in1, in2 = os.popen4('md5sum -b "'+self.source+'"')
-               out1, out2 = os.popen4('md5sum -b "'+self.dest+'"')
-               for line in in2.readlines():
-                       line1 = line.split('*')[0]
-               for line in out2.readlines():
-                       line2 = line.split('*')[0]
-               return line1 == line2
-
-       def write_metadata_xml(self,path):
-               doc = xml.dom.minidom.Document()
-               root = doc.createElement('telemeta')
-               doc.appendChild(root)
-               for tag in self.metadata.keys() :
-                       value = self.metadata[tag]
-                       node = doc.createElement(tag)
-                       node.setAttribute('value', str(value))
-                       #node.setAttribute('type', get_type(value))
-                       root.appendChild(node)
-               xml_file = open(path, "w")
-               xml.dom.ext.PrettyPrint(doc, xml_file)
-               xml_file.close()
-
-       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)
-               self.source = source
-               file_name = get_file_name(self.source)
-               file_name_wo_ext, file_ext = split_file_name(file_name)
-               self.cache_dir = cache_dir
-
-               self.metadata = metadata
-               #self.collection = self.metadata['Collection']
-               #self.artist = self.metadata['Artist']
-               #self.title = self.metadata['Title']
-
-               # Decode the source if needed
-               if os.path.exists(self.source) and not iswav16(self.source):
-                       # TO FIX !
-                       self.source = self.export.decode()
-
-               # Normalize if demanded
-               if 'normalize' in self.metadata and self.metadata['normalize']:
-                       self.normalize()
-
-               # Define the cache directory
-               self.ext = self.get_file_extension()
-
-               # Define and create the destination path
-               # At the moment, the target directory is built with this scheme in
-               # the cache directory : ./%Format/%Collection/%Artist/
-               self.dest = self.cache_dir
-
-               #export_dir = os.path.join(self.ext,self.collection,self.artist)
-               export_dir = self.ext
-               if not os.path.exists(os.path.join(self.dest,export_dir)):
-                       for _dir in export_dir.split(os.sep):
-                               self.dest = os.path.join(self.dest,_dir)
-                               if not os.path.exists(self.dest):
-                                       os.mkdir(self.dest)
-               else:
-                       self.dest = os.path.join(self.dest,export_dir)
-
-               # Set the target file
-               #target_file = file_name_wo_ext+'.'+self.ext
-               target_file = self.item_id+'.'+self.ext
-               self.dest = os.path.join(self.dest,target_file)
-               return self.dest
-
-
-       def post_process(self, item_id, source, metadata, ext, 
-                                        cache_dir, options=None):
-               """ Post processing of the Core. Print infos, etc..."""
-               if not options is None:
-                       if 'verbose' in self.options and self.options['verbose'] != '0':
-                               print self.dest
-                               print self.get_file_info()
+    """Defines the main parts of the exporting tools :
+    paths, formats, metadata..."""
+
+    def __init__(self):
+        self.source = ''
+        self.collection = ''
+        self.verbose = ''
+        self.dest = ''
+        self.metadata = []
+        self.cache_dir = 'cache'
+
+    def set_cache_dir(self,path):
+        self.cache_dir = path
+
+    def normalize(self):
+        """ Normalize the source and return its path """
+        args = ''
+        if self.verbose == '0':
+            args = '-q'
+        try:
+            os.system('normalize-audio '+args+' "'+self.source+'"')
+            return self.source
+        except IOError:
+            return 'Exporter error: Cannot normalize, path does not exist.'
+
+    def check_md5_key(self):
+        """ Check if the md5 key is OK and return a boolean """
+        try:
+            md5_log = os.popen4('md5sum -c "'+self.dest+ \
+                                '" "'+self.dest+'.md5"')
+            return 'OK' in md5_log.split(':')
+        except IOError:
+            return 'Exporter error: Cannot check the md5 key...'
+    
+    def get_file_info(self):
+        """ Return the list of informations of the dest """
+        return self.export.get_file_info()
+
+    def get_wav_length_sec(self) :
+        """ Return the length of the audio source file in seconds """
+        try:
+            file1, file2 = os.popen4('wavinfo "'+self.source+ \
+                                     '" | grep wavDataSize')
+            for line in file2.readlines():
+                line_split = line.split(':')
+                value = int(int(line_split[1])/(4*44100))
+                return value
+        except IOError:
+            return 'Exporter error: Cannot get the wav length...'
+
+    def compare_md5_key(self):
+        """ Compare 2 files wih md5 method """
+        in1, in2 = os.popen4('md5sum -b "'+self.source+'"')
+        out1, out2 = os.popen4('md5sum -b "'+self.dest+'"')
+        for line in in2.readlines():
+            line1 = line.split('*')[0]
+        for line in out2.readlines():
+            line2 = line.split('*')[0]
+        return line1 == line2
+
+    def write_metadata_xml(self,path):
+        doc = xml.dom.minidom.Document()
+        root = doc.createElement('telemeta')
+        doc.appendChild(root)
+        for tag in self.metadata.keys() :
+            value = self.metadata[tag]
+            node = doc.createElement(tag)
+            node.setAttribute('value', str(value))
+            #node.setAttribute('type', get_type(value))
+            root.appendChild(node)
+        xml_file = open(path, "w")
+        xml.dom.ext.PrettyPrint(doc, xml_file)
+        xml_file.close()
+
+    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)
+        self.source = source
+        file_name = get_file_name(self.source)
+        file_name_wo_ext, file_ext = split_file_name(file_name)
+        self.cache_dir = cache_dir
+
+        self.metadata = metadata
+        #self.collection = self.metadata['Collection']
+        #self.artist = self.metadata['Artist']
+        #self.title = self.metadata['Title']
+
+        # Decode the source if needed
+        if os.path.exists(self.source) and not iswav16(self.source):
+            # TO FIX !
+            self.source = self.export.decode()
+
+        # Normalize if demanded
+        if 'normalize' in self.metadata and self.metadata['normalize']:
+            self.normalize()
+
+        # Define the cache directory
+        self.ext = self.get_file_extension()
+
+        # Define and create the destination path
+        # At the moment, the target directory is built with this scheme in
+        # the cache directory : ./%Format/%Collection/%Artist/
+        self.dest = self.cache_dir
+
+        #export_dir = os.path.join(self.ext,self.collection,self.artist)
+        export_dir = self.ext
+        if not os.path.exists(os.path.join(self.dest,export_dir)):
+            for _dir in export_dir.split(os.sep):
+                self.dest = os.path.join(self.dest,_dir)
+                if not os.path.exists(self.dest):
+                    os.mkdir(self.dest)
+        else:
+            self.dest = os.path.join(self.dest,export_dir)
+
+        # Set the target file
+        #target_file = file_name_wo_ext+'.'+self.ext
+        target_file = self.item_id+'.'+self.ext
+        self.dest = os.path.join(self.dest,target_file)
+        return self.dest
+
+
+    def post_process(self, item_id, source, metadata, ext, 
+                     cache_dir, options=None):
+        """ Post processing of the Core. Print infos, etc..."""
+        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
 
 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'
+    """ 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'
+    """ 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 IOError:
-               return 'Exporter error [1]: path does not exist.'
+    """ 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 IOError:
+        return 'Exporter error [1]: 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 IOError:
-               return 'Exporter error [1]: path does not exist.'
+    """ 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 IOError:
+        return 'Exporter error [1]: 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 IOError:
-               return 'Exporter error [1]: path does not exist.'
+    """ Tell if path is a WAV """
+    try:
+        mime = get_file_mime_type(path)
+        return mime == 'audio/x-wav'
+    except IOError:
+        return 'Exporter error [1]: 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 IOError:
-               return 'Exporter error [1]: path does not exist.'
+    """ 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 IOError:
+        return 'Exporter error [1]: path does not exist.'
 
 def get_file_name(path):
-       """ Return the file name targeted in the path """
-       return os.path.split(path)[1]
+    """ 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 IOError:
-               return 'Exporter error [1]: path does not exist.'
+    """ Return main file name and its extension """
+    try:
+        return os.path.splitext(file)
+    except IOError:
+        return 'Exporter error [1]: path does not exist.'
 
 def clean_word(word) :
-       """ Return the word without excessive blank spaces and underscores """
-       word = re.sub("^[^\w]+","",word)        #trim the beginning
-       word = re.sub("[^\w]+$","",word)        #trim the end
-       #word = string.replace(word,' ','_')
-       word = re.sub("_+","_",word)            #squeeze continuous _ to one _
-       word = re.sub("^[^\w]+","",word)        #trim the beginning _
-       #word = string.capitalize(word)
-       return word
+    """ Return the word without excessive blank spaces and underscores """
+    word = re.sub("^[^\w]+","",word)    #trim the beginning
+    word = re.sub("[^\w]+$","",word)    #trim the end
+    #word = string.replace(word,' ','_')
+    word = re.sub("_+","_",word)        #squeeze continuous _ to one _
+    word = re.sub("^[^\w]+","",word)    #trim the beginning _
+    #word = string.capitalize(word)
+    return word
 
 def recover_par_key(path):
-       """ Recover a file with par2 key """
-       os.system('par2 r "'+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"')
+    """ Verify a par2 key """
+    os.system('par2 v "'+path+'.par2"')
 
 def get_consts_value(self, data):
-       value = self.collection.__dict__[data]
-       value_type = getType(value)
-       return value, value_type
+    value = self.collection.__dict__[data]
+    value_type = getType(value)
+    return value, value_type
 
index a6a56f0fb03dd97d1956b45ea8937e9cc53ea8a2..6806d9196a10e028df9174e62ffe4d6156c19d91 100644 (file)
@@ -18,118 +18,118 @@ from telemeta.export.api import IExporter
 from mutagen.flac import FLAC
 
 class FlacExporter(ExporterCore):
-       """Defines methods to export to OGG Vorbis"""
+    """Defines methods to export to OGG Vorbis"""
 
-       implements(IExporter)
-       
-       def __init__(self):
-               self.item_id = ''
-               self.source = ''
-               self.metadata = {}
-               self.options = {}
-               self.description = ''
-               self.dest = ''
-               self.quality_default = '5'
-               self.info = []
-               
-       def get_format(self):
-               return 'FLAC'
-       
-       def get_file_extension(self):
-               return 'flac'
+    implements(IExporter)
+    
+    def __init__(self):
+        self.item_id = ''
+        self.source = ''
+        self.metadata = {}
+        self.options = {}
+        self.description = ''
+        self.dest = ''
+        self.quality_default = '5'
+        self.info = []
+        
+    def get_format(self):
+        return 'FLAC'
+    
+    def get_file_extension(self):
+        return 'flac'
 
-       def get_mime_type(self):
-               return 'application/flac'
+    def get_mime_type(self):
+        return 'application/flac'
 
-       def get_description(self):
-               return 'FIXME'
+    def get_description(self):
+        return 'FIXME'
 
-       def get_file_info(self):
-               try:
-                       file1, file2 = os.popen4('metaflac --list "'+self.dest+'"')
-                       info = []
-                       for line in file2.readlines():
-                               info.append(clean_word(line[:-1]))
-                       self.info = info
-                       return self.info
-               except IOError:
-                       return 'Exporter error [1]: file does not exist.'
+    def get_file_info(self):
+        try:
+            file1, file2 = os.popen4('metaflac --list "'+self.dest+'"')
+            info = []
+            for line in file2.readlines():
+                info.append(clean_word(line[:-1]))
+            self.info = info
+            return self.info
+        except IOError:
+            return 'Exporter error [1]: file does not exist.'
 
-       def set_cache_dir(self,path):
-               """Set the directory where cached files should be stored. Does nothing
+    def set_cache_dir(self,path):
+        """Set the directory where cached files should be stored. Does nothing
         if the exporter doesn't support caching. 
        
         The driver shouldn't assume that this method will always get called. A
         temporary directory should be used if that's not the case.
         """
-               self.cache_dir = path
+        self.cache_dir = path
 
-       def decode(self):
-               try:
-                       file_name, ext = get_file_name(self.source)
-                       dest = self.cache_dir+os.sep+file_name+'.wav'
-                       os.system('flac -d -o "'+dest+'" "'+self.source+'"')
-                       self.source = dest
-                       return dest
-               except IOError:
-                       return 'ExporterError [2]: decoder not compatible.'
+    def decode(self):
+        try:
+            file_name, ext = get_file_name(self.source)
+            dest = self.cache_dir+os.sep+file_name+'.wav'
+            os.system('flac -d -o "'+dest+'" "'+self.source+'"')
+            self.source = dest
+            return dest
+        except IOError:
+            return 'ExporterError [2]: decoder not compatible.'
 
-       def write_tags(self):
-               media = FLAC(self.dest)
-               for tag in self.metadata.keys():
-                       if tag == 'COMMENT':
-                               media['DESCRIPTION'] = str(self.metadata[tag])
-                       else:
-                               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 = {}
-               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 -f -V -'+self.quality_default
-       
-               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)
-                       
-                       # Encoding
-                       os.system('flac '+args+' -o "'+self.dest+'" "'+ \
-                                         self.source+'" > /dev/null')
+    def write_tags(self):
+        media = FLAC(self.dest)
+        for tag in self.metadata.keys():
+            if tag == 'COMMENT':
+                media['DESCRIPTION'] = str(self.metadata[tag])
+            else:
+                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 = {}
+        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 -f -V -'+self.quality_default
+    
+        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)
+            
+            # Encoding
+            os.system('flac '+args+' -o "'+self.dest+'" "'+ \
+                      self.source+'" > /dev/null')
 
-                       # Pre-proccessing (self)
-                       self.write_tags()
-                       self.post_process(self.item_id,
-                                                self.source,
-                                                self.metadata,
-                                                self.ext,
-                                                self.cache_dir,
-                                                self.options)
+            # Pre-proccessing (self)
+            self.write_tags()
+            self.post_process(self.item_id,
+                         self.source,
+                         self.metadata,
+                         self.ext,
+                         self.cache_dir,
+                         self.options)
 
-                       # Output
-                       return self.dest
+            # Output
+            return self.dest
 
-               except IOError:
-                       return 'ExporterError [3]: source file does not exist.'
+        except IOError:
+            return 'ExporterError [3]: source file does not exist.'
 
index 0b156f0566ec059ac49004481fb5f5632bb6c8b3..1cb58cad8b10634cb742970d88232128bdd7de8e 100644 (file)
@@ -19,129 +19,129 @@ from telemeta.export.api import IExporter
 
 
 class Mp3Exporter(ExporterCore):
-       """Defines methods to export to MP3"""
+    """Defines methods to export to MP3"""
 
-       implements(IExporter)
-       
-       def __init__(self):
-               self.item_id = ''
-               self.metadata = {}
-               self.description = ''
-               self.info = []
-               self.source = ''
-               self.dest = ''
-               self.options = {}
-               self.bitrate_default = '192'
-               self.dub2id3_dict = {'title': 'TIT2', #title2
-                                    'creator': 'TCOM', #composer
-                                    'creator': 'TPE1', #lead
-                                    'identifier': 'UFID', #Unique ID...
-                                    'identifier': 'TALB', #album
-                                    #'date': 'TYER', #year
-                                    'type': 'TCON', #genre
-                                    'publisher': 'TPUB', #comment
-                                    }
+    implements(IExporter)
+    
+    def __init__(self):
+        self.item_id = ''
+        self.metadata = {}
+        self.description = ''
+        self.info = []
+        self.source = ''
+        self.dest = ''
+        self.options = {}
+        self.bitrate_default = '192'
+        self.dub2id3_dict = {'title': 'TIT2', #title2
+                             'creator': 'TCOM', #composer
+                     'creator': 'TPE1', #lead
+                     'identifier': 'UFID', #Unique ID...
+                     'identifier': 'TALB', #album
+                     #'date': 'TYER', #year
+                     'type': 'TCON', #genre
+                     'publisher': 'TPUB', #comment
+                     }
 
-       def get_format(self):
-               return 'MP3'
-       
-       def get_file_extension(self):
-               return 'mp3'
+    def get_format(self):
+        return 'MP3'
+    
+    def get_file_extension(self):
+        return 'mp3'
 
-       def get_mime_type(self):
-               return 'audio/mpeg'
+    def get_mime_type(self):
+        return 'audio/mpeg'
 
-       def get_description(self):
-               return "FIXME"
+    def get_description(self):
+        return "FIXME"
 
-       def get_file_info(self):
-               try:
-                       file_out1, file_out2 = os.popen4('mp3info "'+self.dest+'"')
-                       info = []
-                       for line in file_out2.readlines():
-                               info.append(clean_word(line[:-1]))
-                       self.info = info
-                       return self.info
-               except IOError:
-                       return 'Exporter error [1]: file does not exist.'
+    def get_file_info(self):
+        try:
+            file_out1, file_out2 = os.popen4('mp3info "'+self.dest+'"')
+            info = []
+            for line in file_out2.readlines():
+                info.append(clean_word(line[:-1]))
+            self.info = info
+            return self.info
+        except IOError:
+            return 'Exporter error [1]: file does not exist.'
 
-       def decode(self):
-               try:
-                       os.system('sox "'+self.source+'" -w -r 44100 -t wav "' \
-                                               +self.cache_dir+os.sep+self.item_id+'"')
-                       return self.cache_dir+os.sep+self.item_id+'.wav'
-               except IOError:
-                       return 'ExporterError [2]: decoder not compatible.'
+    def decode(self):
+        try:
+            os.system('sox "'+self.source+'" -w -r 44100 -t wav "' \
+                        +self.cache_dir+os.sep+self.item_id+'"')
+            return self.cache_dir+os.sep+self.item_id+'.wav'
+        except IOError:
+            return 'ExporterError [2]: decoder not compatible.'
 
-       def write_tags(self):
-               """Write all ID3v2.4 tags by mapping dub2id3_dict dictionnary with the
-                       respect of mutagen classes and methods"""
-               from mutagen import id3
-               
-               id3 = id3.ID3(self.dest)
-               for tag in self.metadata.keys():
-                       if tag in self.dub2id3_dict.keys():
-                               frame_text = self.dub2id3_dict[tag]
-                               value = self.metadata[tag]
-                               #print frame_text+': '+value
-                               frame = mutagen.id3.Frames[frame_text](3,value)
-                               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 = {}
-               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 '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 -c -o '
-               
-               if os.path.exists(self.source) and not iswav16(self.source):
-                       self.source = self.decode()
-                       
-               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)
-                       
-                       # Encoding
-                       os.system('lame '+args+' --tc "default" "'+self.source+
-                                                                       '" "'+self.dest+'"')
-                       
-                       # Pre-proccessing (self)
-                       self.write_tags()
-                       self.post_process(self.item_id,
-                                                self.source,
-                                                self.metadata,
-                                                self.ext,
-                                                self.cache_dir,
-                                                self.options)
-                                               
-                       # Output
-                       return self.dest
+    def write_tags(self):
+        """Write all ID3v2.4 tags by mapping dub2id3_dict dictionnary with the
+            respect of mutagen classes and methods"""
+        from mutagen import id3
+        
+        id3 = id3.ID3(self.dest)
+        for tag in self.metadata.keys():
+            if tag in self.dub2id3_dict.keys():
+                frame_text = self.dub2id3_dict[tag]
+                value = self.metadata[tag]
+                #print frame_text+': '+value
+                frame = mutagen.id3.Frames[frame_text](3,value)
+                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 = {}
+        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 '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 -c -o '
+        
+        if os.path.exists(self.source) and not iswav16(self.source):
+            self.source = self.decode()
+            
+        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)
+            
+            # Encoding
+            os.system('lame '+args+' --tc "default" "'+self.source+
+                                    '" "'+self.dest+'"')
+            
+            # Pre-proccessing (self)
+            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:
-                       return 'ExporterError [3]: source file does not exist.'
+        except IOError:
+            return 'ExporterError [3]: source file does not exist.'
 
index dc14890dbd398f27a98d640bce4b688a3f798f86..3ebe7c8560ba287e4200a3343eed62a7e1b69c4b 100644 (file)
@@ -18,114 +18,114 @@ from telemeta.export.api import IExporter
 from mutagen.oggvorbis import OggVorbis
 
 class OggExporter(ExporterCore):
-       """Defines methods to export to OGG Vorbis"""
+    """Defines methods to export to OGG Vorbis"""
 
-       implements(IExporter)
-       
-       def __init__(self):
-               self.item_id = ''
-               self.metadata = {}
-               self.description = ''
-               self.info = []
-               self.source = ''
-               self.dest = ''
-               self.options = {}
-               self.bitrate_default = '192'
+    implements(IExporter)
+    
+    def __init__(self):
+        self.item_id = ''
+        self.metadata = {}
+        self.description = ''
+        self.info = []
+        self.source = ''
+        self.dest = ''
+        self.options = {}
+        self.bitrate_default = '192'
 
-       def get_format(self):
-               return 'OGG'
-       
-       def get_file_extension(self):
-               return 'ogg'
+    def get_format(self):
+        return 'OGG'
+    
+    def get_file_extension(self):
+        return 'ogg'
 
-       def get_mime_type(self):
-               return 'application/ogg'
+    def get_mime_type(self):
+        return 'application/ogg'
 
-       def get_description(self):
-               return 'FIXME'
+    def get_description(self):
+        return 'FIXME'
 
-       def get_file_info(self):
-               try:
-                       file_out1, file_out2 = os.popen4('ogginfo "'+self.dest+'"')
-                       info = []
-                       for line in file_out2.readlines():
-                               info.append(clean_word(line[:-1]))
-                       self.info = info
-                       return self.info
-               except IOError:
-                       return 'Exporter error [1]: file does not exist.'
+    def get_file_info(self):
+        try:
+            file_out1, file_out2 = os.popen4('ogginfo "'+self.dest+'"')
+            info = []
+            for line in file_out2.readlines():
+                info.append(clean_word(line[:-1]))
+            self.info = info
+            return self.info
+        except IOError:
+            return 'Exporter error [1]: file does not exist.'
 
-       #def set_cache_dir(self,path):
-       #       self.cache_dir = path
+    #def set_cache_dir(self,path):
+    #   self.cache_dir = path
 
-       def decode(self):
-               try:
-                       os.system('oggdec -o "'+self.cache_dir+os.sep+self.item_id+
-                                         '.wav" "'+self.source+'"')
-                       return self.cache_dir+os.sep+self.item_id+'.wav'
-               except IOError:
-                       return 'ExporterError [2]: decoder not compatible.'
+    def decode(self):
+        try:
+            os.system('oggdec -o "'+self.cache_dir+os.sep+self.item_id+
+                      '.wav" "'+self.source+'"')
+            return self.cache_dir+os.sep+self.item_id+'.wav'
+        except IOError:
+            return 'ExporterError [2]: decoder not compatible.'
 
-       def write_tags(self):
-               media = OggVorbis(self.dest)
-               for tag in self.metadata.keys():
-                       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 = {}
-               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 = args + '-b '+self.options['ogg_bitrate']
-                       elif 'ogg_quality' in self.options:
-                               args = args + '-q '+self.options['ogg_quality']
-                       else:
-                               args = args + '-b '+self.bitrate_default
+    def write_tags(self):
+        media = OggVorbis(self.dest)
+        for tag in self.metadata.keys():
+            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 = {}
+        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 = args + '-b '+self.options['ogg_bitrate']
+            elif 'ogg_quality' in self.options:
+                args = args + '-q '+self.options['ogg_quality']
+            else:
+                args = args + '-b '+self.bitrate_default
 
-               else:
-                       args = ' -Q -b '+self.bitrate_default
-                       
-               if os.path.exists(self.source) and not iswav16(self.source):
-                       self.source = self.decode()
-                       
-               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)
-                       
-                       # Encoding
-                       os.system('oggenc '+args+' -o "'+self.dest+
-                                         '" "'+self.source+'"')
-                       
-                       # Pre-proccessing (self)
-                       self.write_tags()
-                       self.post_process(self.item_id,
-                                                self.source,
-                                                self.metadata,
-                                                self.ext,
-                                                self.cache_dir,
-                                                self.options)
-                                               
-                       # Output
-                       return self.dest
+        else:
+            args = ' -Q -b '+self.bitrate_default
+            
+        if os.path.exists(self.source) and not iswav16(self.source):
+            self.source = self.decode()
+            
+        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)
+            
+            # Encoding
+            os.system('oggenc '+args+' -o "'+self.dest+
+                      '" "'+self.source+'"')
+            
+            # Pre-proccessing (self)
+            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:
-                       return 'ExporterError [3]: source file does not exist.'
+        except IOError:
+            return 'ExporterError [3]: source file does not exist.'
 
index 1cf061ddb092e10284658da4c05a5a8ef3e01858..132f8457f97ee88506772367fabcd420d7e44589 100644 (file)
@@ -17,129 +17,129 @@ from telemeta.export.core import *
 from telemeta.export.api import IExporter
 
 class WavExporter(ExporterCore):
-       """Defines methods to export to OGG Vorbis"""
-
-       implements(IExporter)
-       
-       def __init__(self):
-               self.item_id = ''
-               self.metadata = {}
-               self.description = ''
-               self.info = []
-               self.source = ''
-               self.dest = ''
-               self.options = {}
-               
-       def get_format(self):
-               return 'WAV'
-       
-       def get_file_extension(self):
-               return 'wav'
-
-       def get_mime_type(self):
-               return 'audio/x-wav'
-
-       def get_description(self):
-               return 'FIXME'
-
-       def get_file_info(self):
-               try:
-                       file1, file2 = os.popen4('wavinfo "'+self.dest+'"')
-                       info = []
-                       for line in file2.readlines():
-                               info.append(clean_word(line[:-1]))
-                       self.info = info
-                       return self.info
-               except IOError:
-                       return 'Exporter error [1]: file does not exist.'
-
-       def set_cache_dir(self,path):
-               """Set the directory where cached files should be stored. Does nothing
+    """Defines methods to export to OGG Vorbis"""
+
+    implements(IExporter)
+    
+    def __init__(self):
+        self.item_id = ''
+        self.metadata = {}
+        self.description = ''
+        self.info = []
+        self.source = ''
+        self.dest = ''
+        self.options = {}
+        
+    def get_format(self):
+        return 'WAV'
+    
+    def get_file_extension(self):
+        return 'wav'
+
+    def get_mime_type(self):
+        return 'audio/x-wav'
+
+    def get_description(self):
+        return 'FIXME'
+
+    def get_file_info(self):
+        try:
+            file1, file2 = os.popen4('wavinfo "'+self.dest+'"')
+            info = []
+            for line in file2.readlines():
+                info.append(clean_word(line[:-1]))
+            self.info = info
+            return self.info
+        except IOError:
+            return 'Exporter error [1]: file does not exist.'
+
+    def set_cache_dir(self,path):
+        """Set the directory where cached files should be stored. Does nothing
         if the exporter doesn't support caching. 
        
         The driver shouldn't assume that this method will always get called. A
         temporary directory should be used if that's not the case.
         """
-               self.cache_dir = path
-
-       def decode(self):
-               try:
-                       file_name, ext = get_file_name(self.source)
-                       dest = self.cache_dir+os.sep+file_name+'.wav'
-                       os.system('sox "'+self.source+'" -w -r 44100 -t wav -c2 "'+ \
-                                         dest+'.wav"')
-                       self.source = dest
-                       return dest
-               except IOError:
-                       return 'ExporterError [2]: decoder not compatible.'
-
-       def write_tags(self):
-               # Create metadata XML file !
-               self.write_metadata_xml(self.dest+'.xml')
-       
-       def create_md5_key(self):
-               """ Create the md5 keys of the dest """
-               try:
-                       os.system('md5sum -b "'+self.dest+'" >"'+self.dest+'.md5"')
-               except IOError:
-                       return 'Exporter error: Cannot create the md5 key...'
-       
-       def create_par_key(self):
-               """ Create the par2 keys of the dest """
-               args = 'c -n1 '
-               if 'verbose' in self.options and self.options['verbose'] != '0':
-                       args = args
-               else:
-                       args = args + '-q -q '
-
-               try:
-                       os.system('par2 '+args+' "'+self.dest+'"')
-               except IOError:
-                       return 'Exporter error: Cannot create the par2 key...'
-
-       def process(self, item_id, source, metadata, options=None):
-               self.item_id = item_id
-               self.source = source
-               self.metadata = metadata
-               self.options = {}
-               
-               if not options is None:
-                       self.options = options
-               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)
-
-                       #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
-                       #if 'md5' in self.metadata and self.metadata['md5']:
-                       self.create_md5_key()
-
-                       # Create the par2 key
-                       #if 'par2' in self.metadata and self.metadata['par2']:
-                       self.create_par_key()
-
-                       self.post_process(self.item_id,
-                                                self.source,
-                                                self.metadata,
-                                                self.ext,
-                                                self.cache_dir,
-                                                self.options)
-
-                       # Output                                
-                       return self.dest
-
-               except IOError:
-                       return 'ExporterError [3]: source file does not exist.'
+        self.cache_dir = path
+
+    def decode(self):
+        try:
+            file_name, ext = get_file_name(self.source)
+            dest = self.cache_dir+os.sep+file_name+'.wav'
+            os.system('sox "'+self.source+'" -w -r 44100 -t wav -c2 "'+ \
+                      dest+'.wav"')
+            self.source = dest
+            return dest
+        except IOError:
+            return 'ExporterError [2]: decoder not compatible.'
+
+    def write_tags(self):
+        # Create metadata XML file !
+        self.write_metadata_xml(self.dest+'.xml')
+    
+    def create_md5_key(self):
+        """ Create the md5 keys of the dest """
+        try:
+            os.system('md5sum -b "'+self.dest+'" >"'+self.dest+'.md5"')
+        except IOError:
+            return 'Exporter error: Cannot create the md5 key...'
+    
+    def create_par_key(self):
+        """ Create the par2 keys of the dest """
+        args = 'c -n1 '
+        if 'verbose' in self.options and self.options['verbose'] != '0':
+            args = args
+        else:
+            args = args + '-q -q '
+
+        try:
+            os.system('par2 '+args+' "'+self.dest+'"')
+        except IOError:
+            return 'Exporter error: Cannot create the par2 key...'
+
+    def process(self, item_id, source, metadata, options=None):
+        self.item_id = item_id
+        self.source = source
+        self.metadata = metadata
+        self.options = {}
+        
+        if not options is None:
+            self.options = options
+        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)
+
+            #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
+            #if 'md5' in self.metadata and self.metadata['md5']:
+            self.create_md5_key()
+
+            # Create the par2 key
+            #if 'par2' in self.metadata and self.metadata['par2']:
+            self.create_par_key()
+
+            self.post_process(self.item_id,
+                         self.source,
+                         self.metadata,
+                         self.ext,
+                         self.cache_dir,
+                         self.options)
+
+            # Output                
+            return self.dest
+
+        except IOError:
+            return 'ExporterError [3]: source file does not exist.'
 
index 22abefd42b9642055b2f1ae6c559360a31b76afb..c0afd45ca3b630a777bb6dbfa0b4653fb07ad13f 100644 (file)
@@ -20,28 +20,28 @@ cache_dir = 'cache/'
 source = 'samples/wav/Cellar - Show Me - 02.wav'
 item_id = '1'
 metadata = {'identifier': 'Test',  #collection
-                'title': 'Show Me',
-                'creator': 'Cellar',
-                'type': 'House',
-                'date': '2004',
-                'publisher': 'PArISs0n',
-                }
+         'title': 'Show Me',
+         'creator': 'Cellar',
+         'type': 'House',
+         'date': '2004',
+         'publisher': 'PArISs0n',
+         }
 options = {'verbose': '0'}
 
 
 class ExportTest(Component):
-       exporters = ExtensionPoint(IExporter)
-
-       def run(self):
-               for exporter in self.exporters:
-                       format = exporter.get_format()
-                       if options['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)
+    exporters = ExtensionPoint(IExporter)
+
+    def run(self):
+        for exporter in self.exporters:
+            format = exporter.get_format()
+            if options['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()