Hi Guys,
i write this Code from
this Topic
but it is working only for 1 file. when the loop starts second time its giving me Error of (The COM Object may not be a valid Dispatch Object!)
please check the code and make correction.
Code:
#NoTrayIcon
#Include %A_ScriptDir%\Com.ahk
Gui, Add, GroupBox, x6 y10 w390 h150 , Writing Tags
Gui, Add, Text, x16 y30 w30 h20 , Path:
Gui, Add, Edit, x46 y30 w270 h20 vPath1,
Gui, Add, Button, x316 y30 w70 h20 gSelectFolder1, Browse...
Gui, Add, Text, x16 y60 w30 h20 , Artist:
Gui, Add, Edit, x46 y60 w70 h20 vArtist,
Gui, Add, Text, x126 y60 w40 h20 , Album:
Gui, Add, Edit, x166 y60 w70 h20 vAlbum
Gui, Add, Text, x246 y60 w50 h20 , Copyright:
Gui, Add, Edit, x296 y60 w90 h20 vCopyright
Gui, Add, Text, x16 y90 w30 h20 , Title:
Gui, Add, Edit, x46 y90 w70 h20 vTitle
Gui, Add, Text, x126 y90 w60 h20 , Comments:
Gui, Add, Edit, x186 y90 w80 h20 vComments
Gui, Add, Text, x276 y90 w30 h20 , Label:
Gui, Add, Edit, x306 y90 w80 h20 vLabel
Gui, Add, Button, x146 y120 w100 h30 gOKWrite, OK
Gui, Add, GroupBox, x6 y170 w390 h90 , Reading Tags
Gui, Add, Text, x16 y190 w60 h20 , Select File:
Gui, Add, Edit, x76 y190 w240 h20 vPath2,
Gui, Add, Button, x316 y190 w70 h20 gSelectFolder2, Browse...
Gui, Add, Button, x146 y220 w100 h30 gOKRead, OK
Gui, Add, GroupBox, x6 y270 w390 h90 , Clear Tags:
Gui, Add, Text, x16 y290 w70 h20 , Select Folder:
Gui, Add, Edit, x86 y290 w230 h20 vPath3,
Gui, Add, Button, x316 y290 w70 h20 gSelectFolder3, Browse...
Gui, Add, Button, x146 y320 w100 h30 gOKClear, OK
; Generated using SmartGUI Creator 4.0
Gui, Show, w404 h367, Wow Tagger v1.0
COM_Init()
Return
GuiClose:
ExitApp
SelectFolder1:
FileSelectFolder, Folder1, , 3
If Folder1 =
MsgBox, You didn't select a folder.
Else
GuiControl,, Path1, %Folder1%
Return
OKWrite:
Gui Submit, Nohide
If Path1 =
{
MsgBox, 16, Error, Please select a folder first for Tag writing.
Return
}
Loop, %Path1%\*.mp3
{
Name1=
Dir1=
WritePath=
TrackNo=
Title=%Name1%
TrackNo=%A_Index%
WritePath = %A_LoopFileLongPath%
SplitPath, WritePath,Name1, Dir1
Gosub, Write
}
MsgBox, 0, Done, Operation completed successfully
Return
SelectFolder2:
FileSelectFolder, Folder2, , 3
If Folder2 =
MsgBox, You didn't select a folder.
Else
GuiControl,, Path2, %Folder2%
Return
OKRead:
Gui, Submit, NoHide
If Path2 =
{
MsgBox, 16, Error, Please select a folder first for Tag Reading.
Return
}
Loop, %Path2%\*.mp3
{
;Ex. 3:
;For this example, Artist=A, Title=T, Year=Y,Album=AL,Genre=G
Name2=
Dir2=
FullFileName = %A_LoopFileLongPath%
SplitPath, FullFileName,Name2, Dir2
ID := ID3_Open(Dir2 . "\" . Name2) ;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
}
MsgBox, 0, Done, Operation completed successfully
Return
SelectFolder3:
FileSelectFolder, Folder3, , 3
If Folder3 =
MsgBox, You didn't select a folder.
Else
GuiControl,, Path3, %Folder3%
Return
OKClear:
Gui, Submit, NoHide
If Path3 =
{
MsgBox, 16, Error, Please select a folder first for Clear Tags.
Return
}
Loop, %Path3%\*.mp3
{
FullFileName = %A_LoopFileLongPath%
SplitPath, FullFileName,Name3, dir3
ID := ID3_Open(Dir3 . "\" . Name3)
ID3_Write(ID) ;clears all tags
ID3_Save(ID,Dir3 . "\" . Name3)
}
MsgBox, 0, Done, Operation completed successfully `nall Tags are Clear now
Return
Write:
COM_Init()
; Ex. 1:
ID=
ID := ID3_Open(Dir1 . "\" . Name1) ;Open "Song.mp3" for reading/editing
ID3_Write(ID,"Artist",Artist) ;write MyArtist to Artist tag
ID3_Write(ID,"LeadArtist",Artist) ;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",Album) ;write MyAlbum to Album tag
ID3_Write(ID,"CopyrightHolder",Copyright) ;...you get the point
ID3_Write(ID,"Title",Title)
;;ID3_Write(ID,"Genre","MyGenre")
ID3_Write(ID,"Comments",Comments)
;;ID3_Write(ID,"CopyrightYear","MyCopyrightYear")
;;ID3_Write(ID,"BeatsPerMinute","MyBeatsPerMinute")
;;ID3_Write(ID,"ISRC","MyISRC")
ID3_Write(ID,"Label",Label)
;;ID3_Write(ID,"PartOfSet","MyPartOfSet")
ID3_Write(ID,"TrackPosition",TrackNo)
ID3_Write(ID,"Track#",TrackNo) ;same as above
ID3_Write(ID,"TrackNum",TrackNo) ;same as above
ID3_Write(ID,"TrackNumber",TrackNo) ;same as above
;;ID3_Write(ID,"FileID","MyFileID")
ID3_Save(ID,Dir1 . "\" . Name1)
Return
;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
}
Please Help Me, i m so confused
