Finding file details...

Tim Golden mail at timgolden.me.uk
Thu May 29 05:55:08 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 don't say, but I assume you're on Windows since you mention
GetFileVersionInfo (which doesn't have anything to do with media
files, by the way) and WMA. There may be packages out there
to do all this already but if not you'll need to pull in a few disparate
modules and mix'n'match.

While ID3 readers (which determine the metadata for MP3) are reasonably
common few of them come ready-compiled for Windows. I've used Ned
Batchelder's id3reader [1] successfully for simple tasks so you might try
that. On the WMA side, you can automate Windows Media Player to get
metadata. (And it might work for .mp3; I've not tried).

<code>
import win32com.client

player = win32com.client.gencache.EnsureDispatch ("WMPlayer.OCX")
wmedia = player.mediaCollection.add (r"c:\temp\bells.mp3")
try:
  artist = wmedia.getItemInfo ("Artist")
finally:
  player.mediaCollection.remove (wmedia, False)

print "bells.mp3 has artist", artist

</code>

You're going to have to dig around for docs on this one. And it's not
pretty. Try starting from: 

http://msdn.microsoft.com/en-us/library/bb249009(VS.85).aspx

TJG

[1] http://nedbatchelder.com/code/modules/id3reader.html



More information about the Python-list mailing list