Want Help for Edit .flac Tag from file name

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.

Rename REGEXP TO="{mp3title}"  TYPE=files FILEINFO CASE=allwords IGNOREEXT 

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.

Almost there. Try this:

Rename PATTERN="*" TO="{mp3title}" TYPE=files CASE=allwords IGNOREEXT

I removed REGEXP as there's no need for regular expressions here.

Also removed FILEINFO as it isn't needed in Opus 12.

Added PATTERN="*" so the command knows you want to replace the whole existing filename.

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.

You can put as many tags as you want in.

#11 here has an example: Various simple rename presets

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?

Rename is for renaming files.

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

The regexp you have is fine, at least as long as the filename has .mp3 on the end:

But aren't you trying to tag .flac files, not .mp3 files? You need to change the extension in the regexp if that is the case.

Or use a regexp that works with any/all extensions:

    re.Pattern = "^([0-9]*) - (.*)(\.[^\.]+)"


But it also looks like you are trying to both rename the files based on their tags and modify the tags based on the filenames at the same time.

That doesn't make sense. You can only do one or the other, not both at once. Why is this a rename script now?

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.
2019-09-17_16-26-11

You need to set the function type to Script.

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

If you're pasting script code from the forum into a new button, you need to set this:

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):

Ok now I Select Function: Script Function, Now After I click on This button nothing happened. I am Steel try with a Flac File.

The Button Script Code is

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.

I click on the Run Button but nothing happened


But when I try to run with this code, it's run fine.

DOpus.Output "hello world"

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?

The tested Button Code is here:

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

This is my flac file I want to tag

Please anybody Help me