pythoneyed3

Setting an ID3 comment using EyeD3 in Python


I have the following python script in a folder with a mp3 file:

import os
import eyed3

def track(file):
    tag = eyed3.load(file)
    tag.tag.comment = u"teststring"
    tag.tag.genre = u"Pop"
    tag.tag.save()

for fn in os.listdir('.'):
    print fn[-3:]
    if fn[-3:] == 'mp3':
        track(fn)

The 'genre' is set or changed correctly, but my comment is just adding some garbage. I added a 'Test' in winamp to the comment, and after I run my script and output the ID3 info from the commandline, I see this:

ys3(01).mp3 [ 3.86 MB ]
-------------------------------------------------------------------------------
Time: 03:02 MPEG1, Layer III    [ ~177 kb/s @ 48000 Hz - Joint stereo ]
-------------------------------------------------------------------------------
ID3 v2.3:
title: WANDERERS FROM YS    - ?
artist: 
album: 
track:      genre: Pop (id 13)
Comment: [Description: ] [Lang: eng]
Test
Comment: [Description: ÿþÿ] [Lang: eng]
þ
-------------------------------------------------------------------------------

Am I passing the 'Comment' in the wrong way?


Solution

  • I don't pretend to understand why this is the way it is, but check out how comments are set in the handy example file:

    from eyed3.id3 import Tag
    
    t = Tag()
    t.comments.set(u"Gritty, yo!")
    

    I believe this has to do with comments being placed into frames, but others may have to chime in with corrections on that. Note that this will fail unless you pass it unicode.

    This works on version:

    ↪ eyeD3 --version
    eyeD3 0.7.4-beta (C) Copyright 2002-2013 Travis Shirk