You are not logged in.

#1 2009-04-04 20:50:15

ltpl4y3r
Member
Registered: 2008-08-23
Posts: 28

[Solved] Simple way to edit id3v2 comment tag in python?

I'm working on a project right now that is going to read the id3v2 comment tag from an MP3 file, parse some things from it, and then append some text to the end.

Right now I'm using id3v2 from extra to do this:

comm = commands.getoutput( "id3info '%s' | grep '(Comments): ()'" % fileName )

Then I use this to put it back:

os.system( "id3tag -c \"%s\" '%s'" % (commNew, fileName) )

I really don't want to rely on this package to insert this comment. I've been looking at eyeD3 and mutagen for a better way to do this, but I'm having trouble figuring it out.

I know there has to be a more elegant solution out there. Any ideas?

Last edited by ltpl4y3r (2009-04-05 05:00:52)

Offline

#2 2009-04-04 20:59:39

Zariel
Member
Registered: 2008-10-07
Posts: 446

Re: [Solved] Simple way to edit id3v2 comment tag in python?

you can use mutagen, a tagging lib written in python.

Offline

#3 2009-04-05 05:00:38

ltpl4y3r
Member
Registered: 2008-08-23
Posts: 28

Re: [Solved] Simple way to edit id3v2 comment tag in python?

Thanks Zariel, I had looked at mutagen before, but had never been able to edit the COMM tag properly. After toying with it and dissecting mid3v2. I was able to come up with the following:

import mutagen.id3
filename = 'File.mp3'
id3 = mutagen.id3.ID3(filename)
frame = mutagen.id3.COMM(encoding=3, lang='XXX', desc=u'', text=[u'Great comment!'])
id3.add(frame)
id3.save()

Adding [Solved] tag...

Offline

#4 2009-04-05 10:58:46

Zariel
Member
Registered: 2008-10-07
Posts: 446

Re: [Solved] Simple way to edit id3v2 comment tag in python?

I think you can use EasyID3 and just do

from mutagen.id3 import EasyID3
file = EasyID3("file")
file["comment"] = comment
file.save()

(not sure if its actually that though)

Offline

Board footer

Powered by FluxBB