Hi all,
I would like to write a script that extracts mp3 ID3 tag info by reading the mp3 file directly. What would be the best way to do this?
I know that there are a few tag versions so I would need to support those.
Thanks
EM
Hi all,
I would like to write a script that extracts mp3 ID3 tag info by reading the mp3 file directly. What would be the best way to do this?
I know that there are a few tag versions so I would need to support those.
Thanks
EM
EM:
I am sure you have noticed by searching this forum that this is not an easy task for AppleScript, especially when you consider the variety of ID3 tags out there. In today’s world of inexpensive hard drives, your best bet by far is to use the mdls system (UNIX) on an indexed volume. This system is the basis for Spotlight, and will provide voluminous amounts of metadata for any MP3 or other audio file that you examine. It will not work on optical media, but once you copy all the files over to a hard drive, Spotlight will index them pretty quickly, and you can read all the metadata you need.
I am no expert in UNIX shell scripting, but there are some out there. A simple AS method, using mdls could start like this:
set attrib_Want to {{"Artist", "kMDItemAuthors"}, {"Album", "kMDItemAlbum"}, {"Title", "kMDItemTitle"}, {"Bit Rate", "kMDItemAudioBitRate"}}
set a to (choose file with prompt "Select a music file:")
set attribute_List to {}
repeat with an_Att in attrib_Want
set end of attribute_List to {(an_Att's item 1), my GetAtt(an_Att's item 2, a)}
end repeat
-->{{"Artist", "(BNLadies)"}, {"Album", "\"Maroon\""}, {"Title", "\"Falling For the First Time\""}, {"Bit Rate", "192"}}
to GetAtt(atr, a_file)
set raw_return to (do shell script "mdls -name " & atr & space & (quoted form of POSIX path of a_file))
set split to offset of "=" in raw_return
return characters (split + 2) thru -1 of raw_return as string
end GetAtt
Good luck, I hope this helps.
Hi Craig
Thanks for the reply and suggestion to use mdls. It works GREAT !!!
I do have 2 problems though.
I can’t see the track number in the metadata.
Sometimes mdls does not return ALL the metadata. Here’s what I am doing:
set theFile to quoted form of "/Volumes/Music Library 2/Westar/WSR128_Drama - Dark and Powerful/WSR128_18_Web Of Darkness Alt.mp3"
set theMetadata to do shell script "mdls " & theFile
==>Result
“/Volumes/Music Library 2/Westar/WSR128_Drama - Dark and Powerful/WSR128_18_Web Of Darkness Alt.mp3 -------------
kMDItemAttributeChangeDate = 1970-01-01 02:00:00 +0200
kMDItemFSContentChangeDate = 2008-04-23 15:28:18 +0200
kMDItemFSCreationDate = 2006-09-04 21:14:30 +0200
kMDItemFSCreatorCode = 1752133483
kMDItemFSFinderFlags = 0
kMDItemFSInvisible = 0
kMDItemFSIsExtensionHidden = 0
kMDItemFSLabel = 0
kMDItemFSName = "WSR128_18_Web Of Darkness Alt.mp3"
kMDItemFSNodeCount = 0
kMDItemFSOwnerGroupID = 0
kMDItemFSOwnerUserID = 504
kMDItemFSSize = 7530677
kMDItemFSTypeCode = 1297106739
kMDItemID = 27203”
What happend to the other tags? There should also be “kMDItemTitle”,“kMDItemComposer”,“kMDItemAuthors”,“kMDItemAlbum” and a few others.
I should mention that this file resides on a Network volume. The thing is that most of my other mp3 files work fine on that volume. So why do some of them fail? I mount the Network volume with admin priviliges meaning that I can read & write to that volume. Is there something else I could try?
The info displays correctly for the file when I open it in iTunes.
kind regards
EM
After a lot of searching I came up with this solution. It “forces” a re-index of the selected volumes upon which mdls is able to find All data exept the track number. (Weird !!!) This really helped me a lot and I hope someone else might find it usefull !
Note that the Network volumes index is lost upon restart and will need to be re-indexed. You will also need a Admin Username and Password.
Here’s the code:
set Drivelist to {"/Volumes/Music Library 5/", "/Volumes/Music Library 4/", "/Volumes/Music Library 3/", "/Volumes/Music Library 2/"}
repeat with theDrive in Drivelist
set theDrive to quoted form of theDrive
do shell script "sudo mdutil -i on " & theDrive user name "YourUserName" password "YourPassword" with administrator privileges -- turn indexing on
do shell script "sudo mdutil -E " & theDrive user name "YourUserName" password "YourPassword" with administrator privileges -- flush and reindex cache
end repeat
Finally I can give some useful info back to this great forum !
kind regards
EM