473,387 Members | 1,453 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,387 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 3752
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.