Finding file details...

Roger Upole rupole at hotmail.com
Thu May 29 11:41:27 EDT 2008


Kalibr wrote:
> I've been trying to figure out how to find the details of files
> (specifically music for now) for a little sorting script I'm making,
> My aim is to get details on the artist, album, and genre for mp3 and
> wma files (possibly more in the future). My closest match was when I
> stumbled accross PyMedia, but it only supports up to 2.4 (I have 2.5).
> Now I see a bit mentioned on GetFileVersionInfo, but that doesn't seem
> to help (and most of it went over my head). Is there any module I can
> use to find this sort of data? I'm trying to not make it specialised
> in music, because I may want to extend this to picture, movie, text
> etc. files in the future. Any ideas how I could go about this?

You can use the shell COM objects to access media properties
as shown by Explorer.

import win32com.client
sh=win32com.client.Dispatch('Shell.Application')

folder= r'M:\Music\Bob Dylan\Highway 61 Revisited'
ns=sh.NameSpace(folder)

## the column index for Artist may vary from folder to folder
for c in range(0,255):
    colname=ns.GetDetailsOf(None, c)
    if colname=='Artists':  ## This shows up as just Artist on XP
        for i in ns.Items():
            artist=ns.GetDetailsOf(i, c)
            if artist:
                print ns.GetDetailsOf(i, 0), artist
        break


            Roger






More information about the Python-list mailing list