diff --git a/headphones/encode.py b/headphones/encode.py index f0b2464d..d5ecec90 100644 --- a/headphones/encode.py +++ b/headphones/encode.py @@ -4,6 +4,7 @@ import shutil import time from subprocess import call +from headphones import logger def encode(albumPath): @@ -33,16 +34,19 @@ def encode(albumPath): i=0 for music in musicFiles: return_code=1 - if headphones.ENCODER == 'lame': - cmd=encoder+' -h --resample ' + str(headphones.SAMPLINGFREQUENCY) + ' -b ' + str(headphones.BITRATE) - cmd=cmd+' "'+os.path.join(music)+'"' - cmd=cmd+' "'+os.path.join(musicTempFiles[i])+'"' - return_code = call(cmd, shell=True) - if return_code==0: - os.remove(music) - shutil.move(musicTempFiles[i],os.path.join(albumPath)) - i=i+1 - else: + if headphones.ENCODER == 'lame': + if not any(music.endswith('.' + x) for x in ["mp3", "wav"]): + logger.warn('Lame cant encode "%s" format for "%s", use ffmpeg' % (os.path.splitext(music)[1],music)) + else: + cmd=encoder+' -h --resample ' + str(headphones.SAMPLINGFREQUENCY) + ' -b ' + str(headphones.BITRATE) + cmd=cmd+' "'+os.path.join(music)+'"' + cmd=cmd+' "'+os.path.join(musicTempFiles[i])+'"' + return_code = call(cmd, shell=True) + if return_code==0: + os.remove(music) + shutil.move(musicTempFiles[i],os.path.join(albumPath)) + i=i+1 + else: cmd=encoder+' -i' cmd=cmd+' "'+os.path.join(music)+'"' cmd=cmd+' -ac 2 -vn -ar ' + str(headphones.SAMPLINGFREQUENCY) + ' -ab ' + str(headphones.BITRATE) +'k' @@ -55,4 +59,5 @@ def encode(albumPath): i=i+1 shutil.rmtree(tempDirEncode) - time.sleep(1) \ No newline at end of file + time.sleep(1) + logger.info('Encoding for folder "%s" is completed' % (albumPath)) \ No newline at end of file