Leon
(Fresh Scripter)
2006-06-06 12:42 PM
Read ID3 tag information

Right I'm trying to knock up a script that can read the information held within the ID3 tags on an mp3 file using KIX.

I'm primarily concerned with reading the information but long term the ability to change the tag would be useful.

I've not been able to find any useful information on this so far so any help will be much appreciated.


LonkeroAdministrator
(KiX Master Guru)
2006-06-06 12:52 PM
Re: Read ID3 tag information

well, you need to open the file for reading.
if you do normal readline stuff, it is rather cryptic.
other option is to use kixforms .net's binary file reading capabilities.

but anyways, it can be rather not that simple.


Mart
(KiX Supporter)
2006-06-06 12:55 PM
Re: Read ID3 tag information

Found a VBScript that does this (so they say). Iím almost blind in the VBS world so maybe someone else can try to convert it to kix?

http://www.motobit.com/tips/detpg_list-id3-tags-script/

Code:

'List of all mp3 files In one folder
'Read it's id3 tags
'2005 Antonin Foller, Motobit Software
Sub ListID3Tags(sFolder)
'get FileSystemObject To enumerate files
Dim FS: Set FS = CreateObject("Scripting.FileSystemObject")

'call ListID3TagsFS Function with a folder object
ListID3TagsFS FS.GetFolder(sFolder)
End Sub

Sub ListID3TagsFS(Root)
Dim SubFolder, File

'enumerate all files In the folder
For Each File In Root.Files
'select only mp3 And wma files
Select Case LCase(Right(File.Name, 4))
Case ".mp3", ".wma": ListID3TagsFile File
End Select
Next

'process all subfolders
For Each SubFolder In Root.SubFolders
ListID3TagsFS SubFolder
Next
End Sub

Sub ListID3TagsFile(File)
'Get id3 object To change data
Dim id3: Set id3 = CreateObject("CDDBControl.CddbID3Tag")

'load id3 data from a file, read only
id3.LoadFromFile File.Path, True

'print some of id3 tags
WScript.Echo File.Name, id3.Album, id3.Title, id3.LeadArtist
End Sub



AllenAdministrator
(KiX Supporter)
2006-06-06 02:03 PM
Re: Read ID3 tag information

While not a solution to make changes to those settings, GetExtFileProperties() - Get Extended File Properties / Attributes of Files , will get many of the tags of a MP3.

Arend_
(MM club member)
2006-06-07 11:46 AM
Re: Read ID3 tag information

Here's a script I've been toying around with, haven't gotten all the properties yet and basically abandoned the project since it's dependable on cbbdcontrol.dll which gets installed with all soundblaster enabled audio cards. I'll post my Windows version later if I find it.
It's based upon the same VBS script as Mart displayed.

just use ListID3Tags("C:\Folderhere")
Code:

Function ListID3Tags($sFolder)
Dim $FSO
$FSO = CreateObject("Scripting.FileSystemObject")
ListID3TagsFS($FSO.GetFolder($sFolder))
EndFunction

Function ListID3TagsFS($Root)
Dim $SubFolder, $mp3
For Each $mp3 In $Root.Files
If LCase(Right($mp3.Name, 3)) == "mp3"
ListID3TagsFile($mp3)
EndIf
Next
For Each $SubFolder In $Root.SubFolders
ListID3TagsFS($SubFolder)
Next
EndFunction

Function ListID3TagsFile($mp3)
Dim $id3
$id3 = CreateObject("CDDBControl.CddbID3Tag")
$id3.LoadFromFile($mp3.Path,1)
? "File Name: " $mp3.Path
? "Artist: "$id3.LeadArtist
? "Title: " $id3.Title
? "Album: " $id3.Album
? "Comment: " $id3.Comments + @CRLF
EndFunction



Side Note: The cddbcontrol will enable you to change the file tag information as well, the windows version will not.


Arend_
(MM club member)
2006-06-07 08:50 PM
Re: Read ID3 tag information

And here the windows version as promised, basically using the 'GetDetailsOf' property. Unfortunately as far as I know windows won't let you change any info.

Code:

Function fnGetDetailsOf()
dim $objShell
dim $objFolder
$objShell = CreateObject("Shell.Application")
$objFolder = $objShell.NameSpace("D:\MP3")
If $objFolder <> ""
dim $objFolderItem
$objFolderItem = $objFolder.ParseName("Guns N' Roses - Madagascar.mp3")
If $objFolderItem <> ""
dim $objInfo
? "File Name: " $objFolder.GetDetailsOf($objFolderItem, 0)
? "File Size: " $objFolder.GetDetailsOf($objFolderItem, 1)
? "File Type: " $objFolder.GetDetailsOf($objFolderItem, 2)
? "File Date Modified: " $objFolder.GetDetailsOf($objFolderItem, 3)
? "File Date Created: " $objFolder.GetDetailsOf($objFolderItem, 4)
? "File Date Accessed: " $objFolder.GetDetailsOf($objFolderItem, 5)
? "File Attributes: " $objFolder.GetDetailsOf($objFolderItem, 6)
? "File Status: " $objFolder.GetDetailsOf($objFolderItem, 7)
? "File Owner: " $objFolder.GetDetailsOf($objFolderItem, 8)
? "File Author: "$objFolder.GetDetailsOf($objFolderItem, 9)
? "File Title: " $objFolder.GetDetailsOf($objFolderItem, 10)
? "File Subject: " $objFolder.GetDetailsOf($objFolderItem, 11)
? "File Category: " $objFolder.GetDetailsOf($objFolderItem, 12)
? "File Pages: " $objFolder.GetDetailsOf($objFolderItem, 13)
? "File Comments: " $objFolder.GetDetailsOf($objFolderItem, 14)
? "File Copyright: " $objFolder.GetDetailsOf($objFolderItem, 15)
? "File Artist: " $objFolder.GetDetailsOf($objFolderItem, 16)
? "File Album Title: " $objFolder.GetDetailsOf($objFolderItem, 17)
? "File Year: " $objFolder.GetDetailsOf($objFolderItem, 18)
? "File Track Number: " $objFolder.GetDetailsOf($objFolderItem, 19)
? "File Genre: " $objFolder.GetDetailsOf($objFolderItem, 20)
? "File Duration: " $objFolder.GetDetailsOf($objFolderItem, 21)
? "File Bit Rate: " $objFolder.GetDetailsOf($objFolderItem, 22)
? "File Protected: " $objFolder.GetDetailsOf($objFolderItem, 23)
? "File Camera Model: " $objFolder.GetDetailsOf($objFolderItem, 24)
? "File Date Picture Taken: " $objFolder.GetDetailsOf($objFolderItem, 25)
? "File Dimensions: " $objFolder.GetDetailsOf($objFolderItem, 26)
? "File Not Used: " $objFolder.GetDetailsOf($objFolderItem, 27)
? "File Not Used: " $objFolder.GetDetailsOf($objFolderItem, 28)
? "File Not Used: " $objFolder.GetDetailsOf($objFolderItem, 29)
? "File Company: " $objFolder.GetDetailsOf($objFolderItem, 30)
? "File Description: " $objFolder.GetDetailsOf($objFolderItem, 31)
? "File File Version: " $objFolder.GetDetailsOf($objFolderItem, 32)
? "File Product Name: " $objFolder.GetDetailsOf($objFolderItem, 33)
? "File Product Version: " $objFolder.GetDetailsOf($objFolderItem, 34)
EndIf
$objFolderItem = ""
EndIf
$objFolder = ""
$objShell = ""
EndFunction



Just call for: fnGetDetailsOf()
You'd have to edit the path and mp3 in the function for now, like I said it's WIP so I haven't optimised it yet, was just testing the GetDetailsOf stuff, haven't bothered to really continue it yet.


Leon
(Fresh Scripter)
2006-06-17 10:18 AM
Re: Read ID3 tag information

Thats spot on dude! Excellent... Cheers for the input everyone. I've managed to do pretty much what I need to for the moment. I'm gonna stick to just reading the info for now.

Thanks


dennywong
(Just in Town)
2008-04-06 11:18 PM
Re: Read ID3 tag information

I'd like to know then, is there a way for me to attach a jpg to the mp3? So say I got this "BryanAdam.mp3" and I have bryanadam.jpg on my C:\ drive, what CDDBControl.DLL method do I use to link (or embed) the image to the mp3 file?
Thanks
Denny


NTDOCAdministrator
(KiX Master)
2008-04-07 05:40 AM
Re: Read ID3 tag information

On an NTFS volume you could use ADS
How To Use NTFS Alternate Data Streams


dennywong
(Just in Town)
2008-04-07 06:16 PM
Re: Read ID3 tag information

Hi NTDOC, thanks for your reply... I'm not sure if I understand your message at all, is it a reply to my question? I want to know how to embed a jpg into mp3 with the CDDBControl.dll, and I was hoping there would be a function or method to do that, even though I couldn't find any.....

Thanks again


NTDOCAdministrator
(KiX Master)
2008-04-07 11:14 PM
Re: Read ID3 tag information

Yes it was in reply but I suppose my fault for taking the word EMBED out of context.

I think what you're wanting to do is update the ID record tags - which so far no one has shown that it can be done with that object.

Sorry for the confusion.


Arend_
(MM club member)
2008-04-08 10:37 AM
Re: Read ID3 tag information

I could be wrong off course but as far as I know there is no way to include an jpg in the ID3 tag.

dennywong
(Just in Town)
2008-04-16 07:53 PM
Re: Read ID3 tag information

Thanks guy... But I just want to make sure I'm not crazy: there are in fact ways that you can attach and embed an jpg into an mp3 file, maybe just not with DLL, right? (That's why the image will show up in the Media Player when I play that mp3 file)

AllenAdministrator
(KiX Supporter)
2008-04-16 08:20 PM
Re: Read ID3 tag information

I'm not speaking on any kind of programming experience, but from cleaning up files and having my hidden files shown. WMP downloads all sorts of hidden files (if enabled), and if memory serves me, the names are like AlbumArt______.jpg. I thought if you deleted these files, the album covers did not show up, but just looking at some of my recent downloads from Amazon, all seem to have a pic and there is no noticable jpgs.

Now you got me wondering....


Sealeopard
(KiX Master)
2008-04-17 03:36 AM
Re: Read ID3 tag information

Actually, ID3v2.3+ supports the APIC tag, see http://www.id3.org/id3v2.4.0-frames in section 4.14.

Bryce
(KiX Supporter)
2008-04-18 07:14 PM
Re: Read ID3 tag information

You can put pictures in mp3's, just don't know how to via COM...