Adding title metadata to video from filename

After browsing the forum and modifying some scripts, I'm trying to adding a title: metadata fromm the filename, but I couldn't get it to work.

I'd prefer to to name the title metadata everything after the first symbol "-", however, my current script is written for everything after the first 6 symbols, which should suffice.

Either way, I can't get this script to work either.


Option Explicit
Function OnClick(ByRef clickData)
Dim cmd, selItem, re, title, path, strCommand
	Set cmd = clickData.func.command
	cmd.deselect = false

    Set re = CreateObject("VBScript.RegExp")
	re.IgnoreCase = true
	re.Global = false
	re.Pattern = "......(.+)"

	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
				    title = re.Replace(selItem.name, "$1")
				    path = selItem
					'strCommand = "SetAttr """ & path & """ META ""artist:" & artist & """ ""year:" & year & """ ""comment:" & comment & """ ""title:" & title & """ ""keywords:" & tags & """"
					strCommand = "SetAttr """ & path & "title:" & title
					cmd.RunCommand strCommand
				End If
			End If
		Next
	End If
End Function

Try

re.Pattern = ".*?-(.*)"

and

strCommand = "SetAttr """ & path & """ META ""title:" & title & """"

Please you share the solved full script with us.

In the script, look for the line that starts with re.Pattern and replace that line with the fist line lxp wrote.

The strCommand line that lxp wrote replaces the only line that starts with strCommand in the script. Ignore the 'strCommand (starts with a single quote character) as that single quote means it is a comment. You can even delete it, if you wish.

1 Like
Option Explicit
Function OnClick(ByRef clickData)
Dim cmd, selItem, re, title, path, strCommand
	Set cmd = clickData.func.command
	cmd.deselect = false

    Set re = CreateObject("VBScript.RegExp")
	re.IgnoreCase = true
	re.Global = false
	re.Pattern = ".*?-(.*)"

	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
				    title = re.Replace(selItem.name, "$1")
				    path = selItem
					strCommand = "SetAttr """ & path & """ META ""title:" & title & """"
					cmd.RunCommand strCommand
				End If
			End If
		Next
	End If
End Function

1 Like

I use this command to copy a filename to the Title field:
image

If there is already something in the Title field and I want to append the filename to the existing Title, can that be done?

Adding + before {file|noext} does not work as it does if I am copying the filename to the Tags field.

I believe you need a script for adding before or after the existing title

Thank you, but my knowledge is limited (but increasing). I don't know what I would need to include in such a script.

In that case we have to wait until some one write the script or maybe Opus developer can add a default function in future update about this issue