By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,907 Members | 1,963 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,907 IT Pros & Developers. It's quick & easy.

Finding file details...

P: n/a
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?
Jun 27 '08 #1
Share this Question
Share on Google+
10 Replies


P: n/a
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/libr...09(VS.85).aspx

TJG

[1] http://nedbatchelder.com/code/modules/id3reader.html
Jun 27 '08 #2

P: n/a
On May 29, 7:55 pm, Tim Golden <m...@timgolden.me.ukwrote:
>
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/libr...09(VS.85).aspx

TJG

[1]http://nedbatchelder.com/code/modules/id3reader.html
Hmm, thanks for the info. Yes, I am using Winders (Vista to be exact)
and I just assumed that there must be a way to programmatically get
the stuff you get from choosing properties in the right click menu.
But I guess there isn't (hard to believe, because I can't see MS hard-
coding each and every file format's metadata into it's OS). I might
have to learn more about the command prompt ( I hear there is a module
for fiddling with it) and work from there.

Cheers for the links though, I will be checking them out :)
Jun 27 '08 #3

P: n/a
Kalibr wrote:
On May 29, 7:55 pm, Tim Golden <m...@timgolden.me.ukwrote:
>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/libr...09(VS.85).aspx

TJG

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

Hmm, thanks for the info. Yes, I am using Winders (Vista to be exact)
and I just assumed that there must be a way to programmatically get
the stuff you get from choosing properties in the right click menu.
Ah. You didn't quite say that. Well, the thing is that the stuff in
the right-click menu (I think this is the case) comes from several
different sources. Some of it's held in Alternate
Data Streams. Some is Structured Storage within the docs themselves.
Some is simply, eg, ID3 data held in an MP3 file etc. I don't
think it all comes from one place. Again, I think.
But I guess there isn't (hard to believe, because I can't see MS hard-
coding each and every file format's metadata into it's OS). I might
have to learn more about the command prompt ( I hear there is a module
for fiddling with it) and work from there.
If you come up with useful info, do post back here. It's an area several
people have enquired about.

TJG
Jun 27 '08 #4

P: n/a
On May 29, 5:26*am, Kalibr <space.captain.f...@gmail.comwrote:
On May 29, 7:55 pm, Tim Golden <m...@timgolden.me.ukwrote:


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/libr...09(VS.85).aspx
TJG
[1]http://nedbatchelder.com/code/modules/id3reader.html

Hmm, thanks for the info. Yes, I am using Winders (Vista to be exact)
and I just assumed that there must be a way to programmatically get
the stuff you get from choosing properties in the right click menu.
But I guess there isn't (hard to believe, because I can't see MS hard-
coding each and every file format's metadata into it's OS). I might
have to learn more about the command prompt ( I hear there is a module
for fiddling with it) and work from there.

Cheers for the links though, I will be checking them out :)
You might also check out the ID3 library:

http://id3-py.sourceforge.net/

It doesn't look like it's been updated for a few years. I tested it on
XP and it seems to work though.

I also found this snippet, but it's pretty rudimentary:

http://snipplr.com/view/1624/python-...from-mp3-file/

Finally, check out the ID3 Handling section on this site:

http://wiki.python.org/moin/UsefulModules

-------
Mike

Blog: http://blog.pythonlibrary.org/
Jun 27 '08 #5

P: n/a

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

Jun 27 '08 #6

P: n/a
On May 30, 1:41 am, "Roger Upole" <rup...@hotmail.comwrote:
>
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
I shall give that a go. (is the module you reference this one?
http://python.net/crew/mhammond/win32/Downloads.html )
Jun 27 '08 #7

P: n/a
Roger Upole wrote:
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?
I think GetFileVersionInfo() only provides version information for DLL
and EXE files.

See: http://msdn.microsoft.com/en-us/library/ms646981.aspx
>
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
Great tip, Roger! This solution works for WMA files (I don't have any
MP3 files handy), so I think it would work for any media files in Windows.

--
Kam-Hung Soh <a href="http://kamhungsoh.com/blog">Software Salariman</a>

Jun 27 '08 #8

P: n/a
Kalibr wrote:
On May 30, 1:41 am, "Roger Upole" <rup...@hotmail.comwrote:
>>
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

I shall give that a go. (is the module you reference this one?
http://python.net/crew/mhammond/win32/Downloads.html )
--
That's the one.

Roger

Jun 27 '08 #9

P: n/a
Kalibr wrote:
On May 30, 1:41 am, "Roger Upole" <rup...@hotmail.comwrote:
>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

I shall give that a go. (is the module you reference this one?
http://python.net/crew/mhammond/win32/Downloads.html )
If you installed ActiveState's Python, the win32com module should be
installed.

--
Kam-Hung Soh <a href="http://kamhungsoh.com/blog">Software Salariman</a>

Jun 27 '08 #10

P: n/a
On May 30, 3:03 pm, Kam-Hung Soh <kamhung....@gmail.comwrote:
Kalibr wrote:
On May 30, 1:41 am, "Roger Upole" <rup...@hotmail.comwrote:
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
I shall give that a go. (is the module you reference this one?
http://python.net/crew/mhammond/win32/Downloads.html)

If you installed ActiveState's Python, the win32com module should be
installed.

--
Kam-Hung Soh <a href="http://kamhungsoh.com/blog">Software Salariman</a>
I gave your program a go, and it works magnificently.
Now I have to figure out how tro use it on a song by song basis
(I still suck at using classes).
Thanks so much for your help.
Jun 27 '08 #11

This discussion thread is closed

Replies have been disabled for this discussion.