Add metadata from filename

It's possible to add tag from filename ?

I have this : 02 - Lmfao - Party rock anthem (2011).mp3
And i want to add tag: Track - Artist - Title (Year)

:question:

Setting the meta attributes should be fairly straight forward, IMO the problem would be extracting the desired information from the file name. So my guess is it would take a VB script to do this.

I think about a regexp to catch info from filename...

Setattr regexp "([^0-9]) - (.) - (.) (([^0-9]))" META="track:/1" "artist:/2" "title:/3" "year:/4"

What do you think about that ?

The RegEx can extract the different parts of the file name easily enough, however I'm not aware of a way to apply the RegEx to the metadata.

If Opus cannot handle this, and your aim is to work on mp3 files, then you could try something like Tagscanner.

The Ultimate TagScanner

It has a tag processor that will do just what you want.

Take the %filename% and process:

%track% - %artist% - %title% (%year%)

I do this all the time.

I have thought of getting Opus to work with Tagscanner, but can't even work out how to pass a selection of files from Opus to Tagscanner. (It insists on launching multiple instances.) Maybe I'll give it another whirl.

Thanks but i use a freeware to do this too and I'm sure that DOpus can do that... in future...

I make a request...

So, it's possible to add tags from filename with vbscript but i have problem to extract year in parenthesis with regexp.

file : 08 - artist - title (2011).mp3
regexp : ([0-9]) - (.) - (.) ([0-9])(.mp3)
\1 : 08
\2 : artist
\3 : title (2011)
\4 : nothing :frowning:
\5 : .mp3

Can somebody help ?

You need to match the actual brackets in the filename.

Use ( and ) to match them, like this:

([0-9]) - (.) - (.) (([0-9]))(.mp3)

Yes, thanks Leo...

So you can find script to add metadata from filename...

Example : 08 - lmfao - party rock anthem (2011)

@nodeselect
Rename FILEINFO TO="{mp3track}%{mp3artist}%{mp3title}%{mp3year}"
@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, string
    Set re = new RegExp
    re.Pattern = "([0-9]*) - (.*) - (.*) \(([0-9]*)\)(\.mp3)"
    string = """track:" & re.Replace(strFileName, "$1") & """ ""title:" & re.Replace(strFileName, "$3") & """ ""artist:" & re.Replace(strFileName, "$2") & """ ""year:" & re.Replace(strFileName, "$4") & """"
    strCommand = """" & DOpusRTPath & """ /cmd SetAttr META " & string
    Shell.Run strCommand,0,false
    strNewName = ""
End Function

I have a problem when i try to use this button with many files selected... Metadata are not set to the good file :frowning:

@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
    Set re = new RegExp
    re.Pattern = "^([0-9]*) - (.*)(\.mp3)"
    track = re.Replace(strFileName, "$1")
    titre = re.Replace(strFileName, "$2")
    strCommand = """" & DOpusRTPath & """ /cmd SetAttr META ""track:" & track & """ ""title:" & titre & """"
    Shell.Run strCommand,0,false
    Dopus.OutputString  "Commande : " & strCommand
    strNewName = ""
End Function

What's happen ?

Shouldn't you pass the filepath to the SetAttr command (FILE argument) so that it only tries to set the data for the file that the rename function is handling?

Right now that script looks like it is going to try and set all the selected files to use the metadata of each file in turn (so the last file might win, and the commands will probably get in each others way).

ok, it's work now. thanks again...

@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 want to add my version for this fantastic script by AlbatorV.

My version will set tags Artist and Title from filename like Artist - Track name.mp3

@nodeselect
Rename FILEINFO TO="{mp3artist}%{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, artist, titre, path
    Set re = new RegExp
    re.Pattern = "^(.*) - (.*)(\.mp3)"
    artist = re.Replace(strFileName, "$1")
    titre = re.Replace(strFileName, "$2")
    path = strFilePath & "\" & strFileName
    strCommand = """" & DOpusRTPath & """ /cmd SetAttr """ & path & """ META ""artist:" & artist & """ ""title:" & titre & """"
    Shell.Run strCommand,0,false
    Dopus.OutputString  "Commande : " & strCommand
    strNewName = ""
End Function

I do not understand anything in scripting. Can you help me with setting metadata to mp4 files with filenames like Artist [YYYYMMDD] (Comment - Title) [Tags].mp4?

I need to set Artist, Year, Comment, Title and Tags metadata.

This should work : Tags Mp4.dcf (2.9 KB)

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 = "^(.*) \[(\d{4}).*\((.*) - (.*)\) \[(.*)\].*$"

	If clickData.func.sourcetab.selected.count > 0 Then
		For Each selItem In clickData.func.sourcetab.selected
			If selItem.metadata = "video" 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