Discussion:
Access and write .mp3 metadata/tags using Python 3
andonefilms
2013-11-26 15:41:24 UTC
Permalink
Hey everyone.

I'm trying to figure out how to get python to access the properties section of an mp3 file. When you right click an mp3 file and go to properties you can edit the title, album, and things like that. I also want to be able to read the length of the mp3.

Is there a pythonic way to do this? I asked a professor of mine and he said to look into the OS module.

Any help is much appreciated!

Thank you

Tyler
Tim Chase
2013-11-26 15:59:01 UTC
Permalink
Post by andonefilms
Hey everyone.
I'm trying to figure out how to get python to access the properties
section of an mp3 file. When you right click an mp3 file and go to
properties you can edit the title, album, and things like that. I
also want to be able to read the length of the mp3.
Is there a pythonic way to do this? I asked a professor of mine and
he said to look into the OS module.
There are a couple libraries that ease that[1]. Matters are
complicated by the fact that there are two different versions of ID3
tags, v1 and v2. However most of those libraries should handle them
just fine.

Also, I don't believe that the playtime length is actually encoded in
the file itself, so you might have to do some calculations to find
that. I've wondered this myself and would be interested to learn
more. You might look at[2] which seems to offer code using one of
those modules.

Based on the two links, it looks like Mutagen might be the first stop
for getting both parts that you need.

-tkc


[1]
https://wiki.python.org/moin/UsefulModules#ID3_Handling

[2]
http://stackoverflow.com/questions/6037826/finding-the-length-of-an-mp3-file
Michael Torrie
2013-11-26 16:41:30 UTC
Permalink
Post by andonefilms
I'm trying to figure out how to get python to access the properties
section of an mp3 file. When you right click an mp3 file and go to
properties you can edit the title, album, and things like that. I
also want to be able to read the length of the mp3.
Is there a pythonic way to do this? I asked a professor of mine and
he said to look into the OS module.
A quick google search reveals this for the tags part:
https://wiki.python.org/moin/UsefulModules#ID3_Handling
andonefilms
2013-11-26 17:10:27 UTC
Permalink
Post by Tim Chase
There are a couple libraries that ease that[1]. Matters are
complicated by the fact that there are two different versions of ID3
tags, v1 and v2. However most of those libraries should handle them
just fine.
Also, I don't believe that the playtime length is actually encoded in
the file itself, so you might have to do some calculations to find
that. I've wondered this myself and would be interested to learn
more. You might look at[2] which seems to offer code using one of
those modules.
Based on the two links, it looks like Mutagen might be the first stop
for getting both parts that you need.
-tkc
[1]
https://wiki.python.org/moin/UsefulModules#ID3_Handling
[2]
http://stackoverflow.com/questions/6037826/finding-the-length-of-an-mp3-file
I'm still a bit new to this. When I download a module like Mutagen and unzip it I have a folder and tons of files within folders? I see no file simply called mutagen? So how can I import the module?
Michael Torrie
2013-11-26 17:22:23 UTC
Permalink
Post by andonefilms
I'm still a bit new to this. When I download a module like Mutagen
and unzip it I have a folder and tons of files within folders? I see
no file simply called mutagen? So how can I import the module?
Also you can install many things using python's built-in package manager:

pip-python install mutagen
alex23
2013-11-27 00:20:59 UTC
Permalink
Post by andonefilms
I also want to be able to read the length of the mp3.
import eyed3
mp3 = eyed3.load(r'pygame\examples\data\house_lo.mp3')
mp3.info.time_secs
7

https://pypi.python.org/pypi/eyeD3/0.7.4

Loading...