Here is a very simple wrapper to CDDBControl.dll
It will read and write ID3v2 tags to any mp3 file.
Not that it is currently very lightly tested—use with caution.
CDDBControl.dll can be found
here.
Sean's COM wrapper is required, and COM_Init() should be called before using any of these functions. Also, before using it for the first time, run (through AHK or Win+r or whatever else) "RegSvr32.exe CDDBControl.dll"
This only needs to be done once.
Documentation/Syntax can be found above each of the whopping 5 functions in the code, and here are some examples:
Code:
COM_Init() ;should be called before using any of these functions
; Ex. 1:
ID := ID3_Open("Song.mp3") ;Open "Song.mp3" for reading/editing
ID3_Write(ID,"Artist","MyArtist") ;write MyArtist to Artist tag
ID3_Write(ID,"LeadArtist","MyArtist") ;same as above
ID3_Write(ID,"Movie","MyMovie") ;write MyMovie to Movie tag
ID3_Write(ID,"Year","MyYear") ;write MyYear to Year tag
ID3_Write(ID,"Album","MyAlbum") ;write MyAlbum to Album tag
ID3_Write(ID,"CopyrightHolder","MyCopyrightHolder") ;...you get the point
ID3_Write(ID,"Title","MyTitle")
ID3_Write(ID,"Genre","MyGenre")
ID3_Write(ID,"Comments","MyComments")
ID3_Write(ID,"CopyrightYear","MyCopyrightYear")
ID3_Write(ID,"BeatsPerMinute","MyBeatsPerMinute")
ID3_Write(ID,"ISRC","MyISRC")
ID3_Write(ID,"Label","MyLabel")
ID3_Write(ID,"PartOfSet","MyPartOfSet")
ID3_Write(ID,"TrackPosition","MyTrack#")
ID3_Write(ID,"Track#","MyTrack#") ;same as above
ID3_Write(ID,"TrackNum","MyTrack#") ;same as above
ID3_Write(ID,"TrackNumber","MyTrack#") ;same as above
ID3_Write(ID,"FileID","MyFileID")
ID3_Save(ID,"Song.mp3")
;Ex. 2:
ID := ID3_Open("Song.mp3") ;Open "Song.mp3" for reading/editing
ID3_Write(ID) ;clears all tags
ID3_Save(ID,"Song.mp3")
;Ex. 3:
;For this example, Artist=A, Title=T, Year=Y,Album=AL,Genre=G
ID := ID3_Open("Song.mp3") ;Open "Song.mp3" for reading/editing
MsgBox % ID3_Read(ID) ;will show T/A/AL/Y/G
MsgBox % ID3_Read(ID,"Artist&Genre&Year","&") ;will show A&G&Y
ID3_Close(ID) ;no need to save, since no editing was done
Code:
Code:
;ID3_Open(FileName) : opens %FileName% for reading/editing
ID3_Open(FileName) {
If !(FileExist(FileName))
Return 0
tag := COM_CreateObject("CDDBControlAOL.CddbID3Tag")
COM_Invoke(tag,"LoadFromFile",FileName,0)
Return tag
}
;ID_Write(FileID, [Tag , NewInfo ] ) : Writes to the Tag
;FileID is the return from ID3_Open
;Tag should be : Artist,Track#,TrackNum,TrackNumber,LeadArtist,Title,Album,Genre,Year,Comments,CopyrightYear,CopyrightHolder
;,Label,BeatsPerMinute,PartOfSet,TrackPosition,FileID,ISRC, or Movie
;NewInfo is the information to write into the ID3 Tag specified
;Leave Tag and NewInfo blank to clear all tags.
ID3_Write(FileID,Tag="",NewInfo="") {
If !FileID
Return 0
Tag := RegExReplace(Tag,"i)(?<!Lead)(Artist)","LeadArtist")
Tag := RegExReplace(Tag,"i)TrackNum|Track#|TrackNumber","TrackPosition")
AllowedList:="LeadArtist,Title,Album,Genre,Year,Comments,CopyrightYear,CopyrightHolder,Label,BeatsPerMinute,PartOfSet,TrackPosition,FileID,ISRC,Movie"
If (!Tag && !NewInfo) {
Loop, Parse, AllowedList, `,
COM_Invoke(FileID,A_LoopField,"")
Return 1
}
If Tag not in %AllowedList%
Return 0
COM_Invoke(FileID,Tag,NewInfo)
Return 1
}
;ID3_Read(FileID, [ Tag , Delim ] ) : Reads info from specified tag(s)
;FileID is the return from ID3_Open()
;Tag should be a %Delim% delimited list of the tags that you want read
;See ID3_Write() for a list of allowed Tag names.
;If Tag is blank, will return Title/Artist/Album/Year/Genre
;Returns: %Delim% delimited list of the information
;, in the same order they are in the Tag parameter
ID3_Read(FileID,Tag="",Delim="/") {
If (!Delim || !FileID)
Return 0
If (!Tag)
Tag := "Title/LeadArtist/Album/Year/Genre", Delim:= "/"
Tag := RegExReplace(Tag,"i)(?<!Lead)(Artist)","LeadArtist")
Tag := RegExReplace(Tag,"i)TrackNum|Track#|TrackNumber","TrackPosition")
AllowedList:="LeadArtist,Title,Album,Genre,Year,Comments,CopyrightYear,CopyrightHolder,Label,BeatsPerMinute,PartOfSet,TrackPosition,FileID,ISRC,Movie"
Loop, Parse, Tag, %Delim%
If A_LoopField not in %AllowedList%
Return 0
Else
Info .= (A_Index = 1 ? "" : Delim) COM_Invoke(FileID,A_LoopField)
Return Info
}
;ID3_Save(FileID, FileName) : Saves changes made to the tags
;FileID is the return from ID3_Open()
;FileName is the file to save the new tags to,
;in most cases the same file used in ID3_Open()
ID3_Save(FileID,FileName) {
If (!FileID || !FileName)
Return 0
COM_Invoke(FileID, "SaveToFile", FileName)
COM_Release(FileID)
Return 1
}
;ID3_Close(FileID) : Closes/Releases the file
;FileID is the return from ID3_Open()
;Use this if you do not want to save the changes,
;but are done working with it.
ID3_Close(FileID) {
If !FileID
Return 0
COM_Release(FileID)
Return 1
}
Anyway, I'm sure there will be bugs I haven't noticed in my few minutes of testing. Please post any issues and I'll get to them as soon as I can.
Edit: Fixed a problem with the RegEx's for making some of the tag names more user friendly.