0

I need get a mp3 lenght(from a url) to transform the lenght in seconds for a delay, someone know how to do it?

Esh Ka
  • 3
  • 2

2 Answers2

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
  • 56,214
  • 26
  • 121
  • 139
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
  • 20,867
  • 7
  • 59
  • 83