mutagen使用简介

#-*- coding:utf-8 -*-

from mutagen.mp3 import MP3
from mutagen.easyid3 import EasyID3

def print_id3(id3info):
    print
    print '%-13s\t%s' % ('Field', 'Value')
    print '-' * 70
    for k, v in id3info.items():
        print '%-13s\t%s' % (k, v and v[0])

if __name__ == '__main__':
    id3info = MP3("e:/smile.mp3", ID3=EasyID3)
    print_id3(id3info)

    # change the title.
    old_title = id3info['title']
    id3info['title'] = u'new title'
    id3info.save()
    print_id3(id3info)

    # change the title back.
    id3info['title'] = old_title
    id3info.save()
    print_id3(id3info)

你可能感兴趣的:(tag)