Read media file length with python

fxp007 used Ask the Experts™
I want to know the total duration of every media file(etc. mp3,wma,rm...) in a folder.
Is there any existed tools or some useful api library for python?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
HI, maybe you can find your answer in this document:
Some libs you might look at though some of them are already rather old: (probably kind of overkill, but you should be able to get all info)
One more lib to look at.
It is a little mor recent
Interesting for you is probably
HonorGodSoftware Engineer
What operating system?

On *ix type systems, I would probably use something simple like:

wc -c *.mp3

There are Windows versions of the wc utility if you need them.

Hi honourgodd

wc -c will count the bytes in the mp3 file (at least on my host)

to do this in python you would just use:
 import os
 print os.path.getsize('filename')

more pythonic and platform independent

However I guess, that the OP is really asking for info like playtime (duration)
For this you need different programs, like for example eyed3 (for mp3 tags)
or ideally a wrapper library like Kaa

HonorGodSoftware Engineer

> I guess

  Exactly.  We are guessing what it is fxp007 is asking about...
HonorGodSoftware Engineer

Thanks for the assist, and the points.

Good luck & have a great day.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial