473,289 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

Finding file details...

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
10 3737
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
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
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
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

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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Cengiz Ulku | last post by:
Hi, I've already posted a question similar but will need some precisions and help. I have a rtf file displayed within a RTB control. Above it, I have a text box control with a scroller which...
0
by: Prem Soman | last post by:
hi! i heared that its possible to get user details inside the UDf by adding the mysql_priv.h header file. But where will this file be available. i am using MySql 3.23.52 on linux8.0 when i...
5
by: Robert Manea | last post by:
Hello everyone, I wrote, simply as an exercise, a small piece of code to find 'strings' (defined as an amount of at least 3 ASCII characters followed by a non ASCII character) in binary files. ...
20
by: Joel Hedlund | last post by:
Hi all! I use python for writing terminal applications and I have been bothered by how hard it seems to be to determine the terminal size. What is the best way of doing this? At the end I've...
13
by: athiane | last post by:
I want a way to parse out all function names that appear in a couple of C files. When the parsing logic finds a function name in a file, it should print out the Function name, line number and file...
0
by: NSF12345 | last post by:
Iv developed a small program that looks for a file over our network, and copy it to the location of another computer. Im using the "If FileExists("\\oldpc\main share\Folder\file.txt") Then" way of...
22
by: jobo | last post by:
Hello, I'm very new to C so please forgive my ineptitude. If I am given a file with "jfewuuj3uefi8jkw128jdmnsdf\s;'d1904" I want to capture each occurence of an integer 0-9 into an array. ...
0
by: U S Contractors Offering Service A Non-profit | last post by:
This Sunday the 26th 2006 there will be Music @ Tue Nov Inbox Reply Craig Somerford to me show details 9:54 pm (26 minutes ago) #1St "CLICK" HeAt frOm A blanket...
5
by: =?Utf-8?B?Qkw=?= | last post by:
Hello friends In c# 2005 I have written a function to access "font file name" by "Font name" and it is working fine in all the windows version other than vista, in vista it is throughing an...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.