I have lots of Music file in .flac format. I have to edit their metadata. Like Title, Artist, Album Artist, Album, Gener, Coverart, Copyright, etc. I used another third party software. Directory opus renaming is more powerful then I Think. But I have no skill to write a complex script or code. Here I try a button code that can write File Name from Title name. it's worked fine for me.
That would be very helpful for me if I can add all the tag (Title, Artist, Album Artist, Album, Gener, Coverart, Copyright) within a single click from the file name. Is there any way? Maybe I write all the tag in my filename with a separator like dots (.) then I just click on the button and all the tag will vanish from my file name and add in their won tag fields.
Thanks Leo. you know i am new and steel try to learn. That would be very helpful for me if I can add all the tag (Title, Artist, Album Artist, Album, Gener, Coverart, Copyright) within a single click from the file name. Is there any way? Maybe I write all the tag in my filename with a separator like dots (.) then I just click on the button and all the tag will vanish from my file name and add in their won tag fields.
What is my mistake?
Example : lekhe nao - jems - 12mas.flac
Here 'lekhe nao' is my title, 'james' is my artist, '12mas' is my album name.
old name: *
new name: {mp3title} - {mp3artist} - {mp3album}
I Think the rename presets 'sort music by tag' 11 - Sort Music by Tags.orp (229 Bytes)
is rename the file name from the tag of the file. But I want the Revert things. I want to Add Tag from the file name. Is that possible?
If you want to edit tags or other metadata, the Rename command is the wrong one to use. SetAttr META... is what you want.
But you will need to write a script or something to parse your filenames and split them out into tags.
I think these two posts have examples similar to what you're trying to do:
The first one looks easiest to edit, since it already splits multiple tags from the file names. You'd need to modify the re.Pattern = ... line to match your filename order/format, and remove things like year which you aren't using in your filenames.
First all Thanks Dear Leo for try to help me. I follow the first one post and try with This Code:
@nodeselect
Rename FILEINFO TO="{mp3track}%{mp3title}"
@script vbscript
Option Explicit
Dim DOpusRTPath
DOpusRTPath = "C:\Program Files\GPSoftware\Directory Opus\dopusrt.exe"
Dim Shell
Set Shell = CreateObject("WScript.Shell")
Function Rename_GetNewName ( strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName )
Dim re, strCommand, track, titre, path
Set re = new RegExp
re.Pattern = "^([0-9]*) - (.*)(\.mp3)"
track = re.Replace(strFileName, "$1")
titre = re.Replace(strFileName, "$2")
path = strFilePath & "\" & strFileName
strCommand = """" & DOpusRTPath & """ /cmd SetAttr """ & path & """ META ""track:" & track & """ ""title:" & titre & """"
Shell.Run strCommand,0,false
Dopus.OutputString "Commande : " & strCommand
strNewName = ""
End Function
I don't understand how to write my file name for use this code. what kinds of separator should I use in my file name between two tags like Title & Artist. I Try with a 'space short hyphen space' as the separator in my file name.
Example: 05 - My heart will go on
After Click this button Track number change to 5 nicely but my mp3title is change to the whole file name. Title changed like: 05 - My heart will go on
But I want to changed Like: My heart will go on
I don't know What is my mistake
Leo I want to modify the tags based on the filenames Only. Which part of this code should be removed? Which part of this code is trying to rename the files based on their tags? I use your regexp. But There is no changed in the result. Now the button code was....
@nodeselect
Rename FILEINFO TO="{mp3track}%{mp3title}"
@script vbscript
Option Explicit
Dim DOpusRTPath
DOpusRTPath = "C:\Program Files\GPSoftware\Directory Opus\dopusrt.exe"
Dim Shell
Set Shell = CreateObject("WScript.Shell")
Function Rename_GetNewName ( strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName )
Dim re, strCommand, track, titre, path
Set re = new RegExp
re.Pattern = "^([0-9]*) - (.*)(\.[^\.]+)"
track = re.Replace(strFileName, "$1")
titre = re.Replace(strFileName, "$2")
path = strFilePath & "\" & strFileName
strCommand = """" & DOpusRTPath & """ /cmd SetAttr """ & path & """ META ""track:" & track & """ ""title:" & titre & """"
Shell.Run strCommand,0,false
Dopus.OutputString "Commande : " & strCommand
strNewName = ""
End Function
Neither of the examples I linked to started with a Rename command or had a Rename_GetNewName function in the script code. Where did that stuff come from? You don't need any of it. Make it like the examples I linked to, which have everything you need (except any small changes you might need, like modifying the regexp).
Ok now I try with this code given below. here I just change the regexp as re.Pattern = "^([0-9]*) - (.*)(\.[^\.]+)" And Change 'Video' to 'Audio' in this line If selItem.metadata = "Audio" Then Because I trying with .Flac File.
This is The Full Code:
Option Explicit
Function OnClick(ByRef clickData)
Dim cmd, selItem, re, artist, year, comment, title, tags, path, strCommand
Set cmd = clickData.func.command
cmd.deselect = false
Set re = CreateObject("VBScript.RegExp")
re.IgnoreCase = true
re.Global = false
re.Pattern = "^([0-9]*) - (.*)(\.[^\.]+)"
If clickData.func.sourcetab.selected.count > 0 Then
For Each selItem In clickData.func.sourcetab.selected
If selItem.metadata = "Audio" Then
If re.test(selItem.name) Then
artist = re.Replace(selItem.name, "$1")
year = re.Replace(selItem.name, "$2")
comment = re.Replace(selItem.name, "$3")
title = re.Replace(selItem.name, "$4")
tags = re.Replace(selItem.name, "$5")
path = selItem
strCommand = "SetAttr """ & path & """ META ""artist:" & artist & """ ""year:" & year & """ ""comment:" & comment & """ ""title:" & title & """ ""keywords:" & tags & """"
' Dopus.Output "Command : " & strCommand
cmd.RunCommand strCommand
End If
End If
Next
End If
End Function
But after I click on this button it's show an error.
Dear jon, I have no idea about write a script. So I replace the 2nd line of the script
from Function OnClick(ByRef clickData) to Function Script But it's doesn't work
You may also need to then set the script language (VBScript or JScript) below that.
Alternatively, if you start from the .dcf file in the first example I linked then everything will be set up for you. (The first thread I linked has a .dcf file at the top of it. Download that, go into Customize mode, then drag it to your toolbar. It will create a button that is set up with the script in it, and you can then make any changes you need to the script.)
All of this is described in more detail here (both the 1st and 2nd posts):
Option Explicit
Function OnClick(ByRef clickData)
Dim cmd, selItem, re, artist, year, comment, title, tags, path, strCommand
Set cmd = clickData.func.command
cmd.deselect = false
Set re = CreateObject("VBScript.RegExp")
re.IgnoreCase = true
re.Global = false
re.Pattern = "^([0-9]*) - (.*)(\.[^\.]+)"
If clickData.func.sourcetab.selected.count > 0 Then
For Each selItem In clickData.func.sourcetab.selected
If selItem.metadata = "Audio" Then
If re.test(selItem.name) Then
artist = re.Replace(selItem.name, "$1")
year = re.Replace(selItem.name, "$2")
comment = re.Replace(selItem.name, "$3")
title = re.Replace(selItem.name, "$4")
tags = re.Replace(selItem.name, "$5")
path = selItem
strCommand = "SetAttr """ & path & """ META ""artist:" & artist & """ ""year:" & year & """ ""comment:" & comment & """ ""title:" & title & """ ""keywords:" & tags & """"
' Dopus.Output "Command : " & strCommand
cmd.RunCommand strCommand
End If
End If
Next
End If
End Function
Use the Run button in the function editor to test your script.
Any errors will appear above the button.
You can also add lines like DOpus.Output "hello world" in your script to output messages into the same place to see which parts of the script code are run, and which aren't. You can use that to debug things.
For example, if you don't have any files selected, then the script won't get far. You could add some DOpus.Output messages to the script before and after the first if statement to see if it reaches before it, and if it reaches after it.
Running that script from the CLI script editor won't do anything because nothing calls its OnClick method that way. Leo said to try running it using the Run button in the function editor.
Ok I Use the Run Button in the function editor. I Add Line like DOpus.Output "hello world" at the before and after the first if statement. and Replay was fine. But I Don't know why the button doesn't work for me?
Option Explicit
Function OnClick(ByRef clickData)
Dim cmd, selItem, re, artist, year, comment, title, tags, path, strCommand
Set cmd = clickData.func.command
cmd.deselect = false
Set re = CreateObject("VBScript.RegExp")
re.IgnoreCase = true
re.Global = false
re.Pattern = "^([0-9]*) - (.*)(\.[^\.]+)"
If clickData.func.sourcetab.selected.count > 0 Then
For Each selItem In clickData.func.sourcetab.selected
If selItem.metadata = "audio" Then
If re.test(selItem.name) Then
artist = re.Replace(selItem.name, "$1")
year = re.Replace(selItem.name, "$2")
comment = re.Replace(selItem.name, "$3")
title = re.Replace(selItem.name, "$4")
tags = re.Replace(selItem.name, "$5")
path = selItem
strCommand = "SetAttr """ & path & """ META ""artist:" & artist & """ ""year:" & year & """ ""comment:" & comment & """ ""title:" & title & """ ""keywords:" & tags & """"
' Dopus.Output "Commande : " & strCommand
cmd.RunCommand strCommand
End If
End If
Next
End If
End Function