Read ID3 tags from a MP3

From IronPython Cookbook

This simple routine uses the Windows Shell to get MP3 file information from the tags. Due to the differences between Vista and XP different magic numbers are required to get the tags.

import os
from System import Type, Activator
from System.Environment import OSVersion

def GetID3Tags(mp3file):
    
    TheShell = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"))
    AFolder = TheShell.NameSpace(os.path.dirname(mp3file))
    AFile = AFolder.ParseName(os.path.basename(mp3file))
    if OSVersion.Version.Major == 6:
        #VISTA
        print "Artist Name : " + AFolder.GetDetailsOf(AFile,13)
        print "Album : " + AFolder.GetDetailsOf(AFile,14)
        print "Title : " + AFolder.GetDetailsOf(AFile,21)
        print "Track No : " + AFolder.GetDetailsOf(AFile,26)
    else:
        #XP
        print "Artist Name : " + AFolder.GetDetailsOf(AFile,9)
        print "Album : " + AFolder.GetDetailsOf(AFile,17)
        print "Title : " + AFolder.GetDetailsOf(AFile,10)
        print "Track No : " + AFolder.GetDetailsOf(AFile,19)

GetID3Tags("C:\\My\\Funky.mp3")

Back to Contents.

TOOLBOX
LANGUAGES