From ddc015849f27563019226716b06ed89ea1e85067 Mon Sep 17 00:00:00 2001 From: pabloalcantara Date: Wed, 17 Aug 2011 11:28:15 -0300 Subject: [PATCH] Minors corrections: Changes to accept .flac encoding Reencode mp3 to the desired bitrate --- headphones/encode.py | 15 ++++++++------- headphones/postprocessor.py | 3 +-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/headphones/encode.py b/headphones/encode.py index 632e9a45..f5d8e578 100644 --- a/headphones/encode.py +++ b/headphones/encode.py @@ -25,10 +25,11 @@ def encode(albumPath): for r,d,f in os.walk(albumPath): for music in f: - if any(music.endswith('.' + x) for x in ["flac", "m4a", "wav"]): + if any(music.endswith('.' + x) for x in ["mp3", "flac", "m4a", "wav"]): musicFiles.append(os.path.join(r, music)) - musicTempFiles.append(os.path.join(tempDirEncode, music)) - + musicTemp = os.path.join(os.path.splitext(music)[0])+'.mp3' + musicTempFiles.append(os.path.join(tempDirEncode, musicTemp)) + if headphones.ENCODER=='lame': encoder=os.path.join(headphones.ENCODERFOLDER,'lame') else: @@ -37,24 +38,24 @@ def encode(albumPath): for music in musicFiles: return_code=1 if headphones.ENCODER == 'lame': - cmd=encoder+' -h --resample ' + headphones.SAMPLINGFREQUENCY + ' -b ' + headphones.BITRATE + 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) - os.rename(musicTempFiles[i],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 ' + headphones.SAMPLINGFREQUENCY + ' -ab ' + headphones.BITRATE +'k' + cmd=cmd+' -ac 2 -vn -ar ' + str(headphones.SAMPLINGFREQUENCY) + ' -ab ' + str(headphones.BITRATE) +'k' cmd=cmd+' "'+os.path.join(musicTempFiles[i])+'"' return_code = call(cmd, shell=True) print return_code if return_code==0: os.remove(music) - os.rename(musicTempFiles[i],music) + shutil.move(musicTempFiles[i],os.path.join(albumPath)) i=i+1 shutil.rmtree(tempDirEncode) \ No newline at end of file diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index ec4d7e6f..713b8764 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -198,11 +198,10 @@ def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list) logger.info('Starting post-processing for: %s - %s' % (release['ArtistName'], release['AlbumTitle'])) #start enconding - if headphones.ENCODE=='1': + if headphones.ENCODE: encode.encode(albumpath) if headphones.EMBED_ALBUM_ART or headphones.ADD_ALBUM_ART: - album_art_path = albumart.getAlbumArt(albumid) artwork = urllib.urlopen(album_art_path).read()