Added peformance counters to encode process

This commit is contained in:
pabloalcantara
2011-08-22 15:55:35 -03:00
parent c7f80f7c79
commit f1aa1ddbb8

View File

@@ -13,12 +13,14 @@ except ImportError:
import lib.argparse as argparse
def encode(albumPath):
tempDirEncode=os.path.join(albumPath,"temp")
musicFiles=[]
musicFinalFiles=[]
musicTempFiles=[]
encoder =""
startAlbumTime=time.clock()
ifencoded=0
if not os.path.exists(tempDirEncode):
os.mkdir(tempDirEncode)
else:
@@ -30,7 +32,7 @@ def encode(albumPath):
for music in f:
if any(music.endswith('.' + x) for x in headphones.MEDIA_FORMATS):
musicFiles.append(os.path.join(r, music))
musicTemp = os.path.splitext(music)[0]+'.'+headphones.ENCODEROUTPUTFORMAT
musicTemp = os.path.normpath(os.path.splitext(music)[0]+'.'+headphones.ENCODEROUTPUTFORMAT).encode(headphones.SYS_ENCODING)
musicTempFiles.append(os.path.join(tempDirEncode, musicTemp))
if headphones.ENCODER=='lame':
@@ -49,31 +51,40 @@ def encode(albumPath):
logger.warn('Music "%s" has bitrate<="%skbit" will not be reencoded' % (music,headphones.BITRATE))
else:
command(encoder,music,musicTempFiles[i],albumPath)
ifencoded=1
else:
if headphones.ENCODEROUTPUTFORMAT=='ogg':
if music.endswith('.ogg'):
logger.warn('Can not reencode .ogg music "%s"' % (music))
else:
command(encoder,music,musicTempFiles[i],albumPath)
ifencoded=1
elif (headphones.ENCODEROUTPUTFORMAT=='mp3' or headphones.ENCODEROUTPUTFORMAT=='m4a'):
if (music.endswith('.'+headphones.ENCODEROUTPUTFORMAT) and (infoMusic.bitrate/1000<=headphones.BITRATE)):
logger.warn('Music "%s" has bitrate<="%skbit" will not be reencoded' % (music,headphones.BITRATE))
else:
command(encoder,music,musicTempFiles[i],albumPath)
ifencoded=1
i=i+1
shutil.rmtree(tempDirEncode)
time.sleep(1)
logger.info('Encoding for folder "%s" is completed' % (albumPath))
time.sleep(1)
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))
if ifencoded==0:
logger.info('Encoding for folder "%s" is not needed' % (albumPath))
else:
logger.info('Encoding for folder "%s" is completed in %s' % (albumPath,getTimeEncode(startAlbumTime)))
return musicFinalFiles
def command(encoder,musicSource,musicDest,albumPath):
return_code=1
cmd=''
startMusicTime=time.clock()
if headphones.ENCODER == 'lame':
cmd=encoder + ' -h --resample ' + str(headphones.SAMPLINGFREQUENCY) + ' -b ' + str(headphones.BITRATE)
cmd=cmd+ ' ' + headphones.ADVANCEDENCODER
@@ -92,4 +103,13 @@ def command(encoder,musicSource,musicDest,albumPath):
return_code = call(cmd, shell=True)
if (return_code==0) and (os.path.exists(musicDest)):
os.remove(musicSource)
shutil.move(musicDest,albumPath)
shutil.move(musicDest,albumPath)
logger.info('Music "%s" encoded in %s' % (musicSource,getTimeEncode(startMusicTime)))
def getTimeEncode(start):
seconds =int(time.clock()-start)
hours = seconds / 3600
seconds -= 3600*hours
minutes = seconds / 60
seconds -= 60*minutes
return "%02d:%02d:%02d" % (hours, minutes, seconds)