I need get a mp3 lenght(from a url) to transform the lenght in seconds for a delay, someone know how to do it?
Asked
Active
Viewed 2,511 times
2 Answers
1
Here is an example of retrieving the resource (mp3 file), and printing the track length via mutagen library:
from urllib import urlretrieve
from mutagen.mp3 import MP3
url = 'http://example.com/foo.mp3'
filename, headers = urlretrieve(url)
audio = MP3(filename)
print audio.info.length

Corey Goldberg
- 59,062
- 28
- 129
- 143
-
I tried to find the mutagen.mp3 module, and i not found it. – Esh Ka Mar 01 '14 at 16:18
-
pip install mutagen (for python 2) – Corey Goldberg Mar 01 '14 at 16:26
0
You don't need to retrieve he resource, you can just check the headers as here: How do you send a HEAD HTTP request in Python 2? You want to call the HEAD method which gets you the file size without downloading the file:

Community
- 1
- 1

Robert Moskal
- 21,737
- 8
- 62
- 86
-
the OP wants song length, not file size. afaik, you must have the track locally to get that. – Corey Goldberg Mar 01 '14 at 16:26