126
« kdy: 17. 09. 2013, 21:34:08 »
toto používám již delší dobu, je v tom i normalizace
# -*- coding: utf-8 -*-
import os, random, shutil, stat, re, time, sys
bitrate="128k"
inDir="."
outDir="_normalize_and_%s" % (bitrate)
tempName="normalize+%s-temp.mp3" % (bitrate)
command1=r'call "c:\Program Files\FreeTime\FormatFactory\FFModules\ffmpeg.exe" -v 1 -loglevel warning -y -map_meta_data "%s":"%s" -i "%s" -ab %s "%s"'
command2='c:\prg\mp3gain\mp3gain.exe /r /c "%s"'
for root, dirs, files in os.walk(inDir):
if os.path.normpath(root).startswith(outDir):
continue
print("="*60)
print(root)
for i in sorted(files):
if os.path.isfile(tempName): os.remove(tempName)
if i==tempName or i.endswith(".py"):
continue
if i.lower().endswith(("mp3","flac","wma","wav","mpa")):
inNameFull=os.path.join(root,i)
outname, ext=os.path.splitext(i)
outNamemp3=outname+".mp3"
outNameFull=os.path.normpath(os.path.join(outDir,root,outNamemp3))
print("-"*60)
print(outNameFull)
if os.path.isfile(outNameFull):
print ("...same file")
continue
outDirFull, f=os.path.split(outNameFull)
commandFull1=command1 %(inNameFull, tempName, inNameFull, bitrate, tempName)
os.system (commandFull1)
if not os.path.isdir(outDirFull):
os.makedirs(outDirFull)
shutil.copy(tempName, outNameFull)
commandFull2=command2 %(outNameFull)
os.system (commandFull2)
print("\n")
else:
print ("jen kopiruji: ",i)
inNameFull=os.path.join(root,i)
outDirFull=os.path.normpath(os.path.join(outDir,root))
if not os.path.isdir(outDirFull):
os.makedirs(outDirFull)
shutil.copy(inNameFull, outDirFull)
if os.path.isfile(tempName): os.remove(tempName)