Hi,
I created a script to delete all existing metadata from a video file and replace it with just the title and year from the file name. The problem I have is that it seems to randomly not work due to "error setting mettadata" and im sometimes just left with two .TMP files of the video. Also, it sometimes removes the file.metadata of the type of file it is in the first place (i.e. video), instead, making it a doc file.
Here is one of the errors when I ran the script on this file (only happened a few times and not consistently):
-
Is the "Error setting metadata" sometimes occurring because the two SetAttr META commands (First to remove all meta and second to set them from the file name) are right next to each other? And since it takes time for the first one to resave a big file (creating a .TMP file temporarily) the second command cannot find the original file. If that is the case, what's the best way, if any, to make the second SetAttr wait for the file to resave before working on the second one?
-
Since the "SetAttr META *" removed the identifier that a file is a video file, is there some metadata parameter I can set at the end that will say it's a video file again? Still confused why this also only happens sometimes to the same file.
Option Explicit
Function OnClick(ByRef clickData)
Dim file, files, countFiles, regex0, regex1
Set files = clickData.func.sourcetab.selected_files
countFiles = 0
Set regex0 = new RegExp
regex0.Pattern = "^(.*)\_\((\d{4})\).*" 'Search for Name and 4 digit year
regex0.IgnoreCase = True
Set regex1 = new RegExp
regex1.Pattern = "_" 'Search for underscore
regex1.Global=True
regex1.IgnoreCase = True
For Each file in files
Dim fileName, fileType, metaTitle, metaYear
fileName = file.name
fileType = file.metadata
metaTitle = Empty
metaYear = Empty
countFiles = countFiles + 1
If (file.metadata = "video") Then
If (regex0.Test(fileName)) Then
metaTitle = regex0.Replace (fileName,"$1") 'Set Title to the text before year in filename
DOpus.Output countFiles & ") Full title: " & metaTitle
metaYear = regex0.Replace (fileName,"$2") 'Set Year to 4 digits inside parentheses
DOpus.Output countFiles & ") Full year: " & metaYear
metaTitle = regex1.Replace (metaTitle," ") 'Replace all underscores in title to spaces.
DOpus.Output countFiles & ") Title without underscores: " & metaTitle
If (clickData.func.qualifiers = "shift") Then
clickData.func.command.ClearFiles
clickData.func.command.AddFile file
clickData.func.command.RunCommand "SetAttr META *"
clickData.func.command.RunCommand "SetAttr META " & """title:" & metaTitle & """" & " " & """year:" & metaYear & """"
End If
Else
DOpus.Output countFiles & ") " & fileName & " does not meet regex0 criteria: " & fileType
End If
Else
DOpus.Output countFiles & ") " & fileName & " is NOT a Video File: " & fileType
End if
Next
End Function
Thanks!