mirror of
https://github.com/rembo10/headphones.git
synced 2026-05-16 00:25:31 +01:00
Verify If mp3 to encode has higher bitrate than new file
If has the same o less bitrate, it does not reencode file Fix: Return for headphones the new downloaded_track_list because it has changed when reencoded from other codec
This commit is contained in:
@@ -5,12 +5,13 @@ import time
|
||||
|
||||
from subprocess import call
|
||||
from headphones import logger
|
||||
|
||||
from lib.mutagen.mp3 import MP3
|
||||
|
||||
def encode(albumPath):
|
||||
|
||||
tempDirEncode=os.path.join(albumPath,"temp")
|
||||
musicFiles=[]
|
||||
musicFinalFiles=[]
|
||||
musicTempFiles=[]
|
||||
encoder =""
|
||||
if not os.path.exists(tempDirEncode):
|
||||
@@ -38,26 +39,38 @@ def encode(albumPath):
|
||||
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)
|
||||
if (music.endswith('.mp3') and (MP3(music).info.bitrate/1000<=headphones.BITRATE)):
|
||||
logger.warn('Music "%s" has bitrate<="%skbit" will not be reencoded' % (music,headphones.BITRATE))
|
||||
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)
|
||||
print ('Return_code: ' + str(return_code))
|
||||
if return_code==0:
|
||||
os.remove(music)
|
||||
shutil.move(musicTempFiles[i],os.path.join(albumPath))
|
||||
else:
|
||||
if (music.endswith('.mp3')):
|
||||
if ((MP3(music).info.bitrate/1000<=headphones.BITRATE)):
|
||||
logger.warn('Music "%s" has bitrate<="%skbit" will not be reencoded' % (music,headphones.BITRATE))
|
||||
else:
|
||||
cmd=encoder+' -i'
|
||||
cmd=cmd+' "'+os.path.join(music)+'"'
|
||||
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)
|
||||
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'
|
||||
cmd=cmd+' "'+os.path.join(musicTempFiles[i])+'"'
|
||||
return_code = call(cmd, shell=True)
|
||||
print return_code
|
||||
if return_code==0:
|
||||
os.remove(music)
|
||||
shutil.move(musicTempFiles[i],os.path.join(albumPath))
|
||||
i=i+1
|
||||
|
||||
i=i+1
|
||||
|
||||
shutil.rmtree(tempDirEncode)
|
||||
time.sleep(1)
|
||||
logger.info('Encoding for folder "%s" is completed' % (albumPath))
|
||||
logger.info('Encoding for folder "%s" is completed' % (albumPath))
|
||||
for r,d,f in os.walk(albumPath):
|
||||
for music in f:
|
||||
if any(music.endswith('.' + x) for x in headphones.MEDIA_FORMATS):
|
||||
musicFinalFiles.append(os.path.join(r, music))
|
||||
return musicFinalFiles
|
||||
@@ -199,7 +199,7 @@ 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:
|
||||
encode.encode(albumpath)
|
||||
downloaded_track_list=encode.encode(albumpath)
|
||||
|
||||
if headphones.EMBED_ALBUM_ART or headphones.ADD_ALBUM_ART:
|
||||
album_art_path = albumart.getAlbumArt(albumid)
|
||||
|
||||
Reference in New Issue
Block a user