Read media file length with python

fxp007
fxp007 used Ask the Experts™
on
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?
thanks
Comment
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: http://www.pythonware.com/media/data/pil-handbook.pdf
Some libs you might look at though some of them are already rather old:

http://gstreamer.freedesktop.org/modules/gst-python.html (probably kind of overkill, but you should be able to get all info)
http://sourceforge.net/projects/mmpython/
http://id3-py.sourceforge.net/
http://pymedia.org/
One more lib to look at.
It is a little mor recent
http://doc.freevo.org/2.0/Kaa
Interesting for you is probably
http://sourceforge.net/projects/freevo/files/kaa-metadata/
HonorGodSoftware Engineer
Commented:
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

Commented:
> I guess

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

Commented:
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