Created
January 23, 2017 09:02
-
-
Save JasonSpine/54abddd0082af3b6c740f498c6a489f5 to your computer and use it in GitHub Desktop.
Get overall time of all mp3s in the current directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os,commands,re | |
path = './' # the directory path to calc | |
listing = os.listdir(path) # list all files | |
result=0 # result [seconds] | |
for i in listing: | |
if i[-4:].lower()==".mp3": # check the file extension | |
command = "ffmpeg -i '%s' 2>&1 | grep Duration"%i | |
durationString=commands.getoutput(command) | |
results=re.findall("(\d{2}):(\d{2}):(\d{2}).(\d{2})",durationString) | |
if results: | |
result+=int(results[0][0])*60*60 | |
result+=int(results[0][1])*60 | |
result+=int(results[0][2]) | |
#formatting the result | |
hours=result/(60*60) | |
result-=hours*60*60 | |
minutes=result/60 | |
result-=minutes*60 | |
seconds=result | |
print "Overall Mp3s time: %02d:%02d:%02d"%(hours,minutes,seconds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment