'This script should be easy to adapt to plug right into your AudioVault automation system 'Expected input format: 'CurrentEvent:CutID=E6072a Type=BMU ArtistName=Basement Jaxx SongTitle=Where's Your Head At Duration=00:04:41.757 'CurrentEvent:CutID=E5572a Type=COM ArtistName=Commercial SongTitle=MyWay Insurance Duration=00:01:00.345 '####################################################################################### '## Custom Param Processing '####################################################################################### Function ProcessParams(Params, ParamCount) Dim tmpType Dim songType If ParamCount <> 5 Then Log("ParamCount expected to be 5, but " & ParamCount & " params returned. Aborting.") Exit Function End If 'ONLY categories of BMU, XMS and COM will trigger updates in this script songType = "J" tmpType = Params(1) If tmpType = "BMU" Then songType = "S" ElseIf tmpType = "XMS" Then songType = "S" ElseIf tmpType = "COM" Then songType = "A" Else Log("Not a valid category. Skip completely.") Exit Function End If SongInfo.Value("ID") = Params(0) SongInfo.Value("songtype") = songType SongInfo.Value("artist") = Params(2) SongInfo.Value("title") = Params(3) SongInfo.Value("duration") = TimeStrToDuration(Params(4)) SongInfo.DoSongChange 'Triggers the metadata update in SAM Cast End Function 'NOTE: Taken from vb.library.txt and adapted slightly 'Split line into Params if the expected format is a Key=Value format 'Example input format: 'CurrentEvent:CutID=E6072a Type=2MS ArtistName=Basement Jaxx SongTitle=Where's Your Head At Duration=00:04:41.757 Function ExtractParams(sLine, ByRef Params, ByRef ParamCount) 'Add a dummy string to the end so we can use it for an ending match sLine = Trim(sLine) & " Dummy=" 'Check if the event is valid If Mid(sLine,1,12) <> "CurrentEvent" Then Log("Not current event. Aborting processing.") Exit Function End If ParamCount = 0 '#0# Cut ID Data = Trim(ExtractTagValue(sLine,"CutID=","Type=")) AddParam Data, Params, ParamCount '#1# Type Data = Trim(ExtractTagValue(sLine,"Type=","ArtistName=")) AddParam Data, Params, ParamCount '#2# Artist Data = Trim(ExtractTagValue(sLine,"ArtistName=","SongTitle=")) AddParam Data, Params, ParamCount '#3# Title Data = Trim(ExtractTagValue(sLine,"SongTitle=","Duration=")) AddParam Data, Params, ParamCount '#4# Duration Data = Trim(ExtractTagValue(sLine,"Duration=","Dummy=")) AddParam Data, Params, ParamCount End Function '####################################################################################### '## ALL of the functions below were taken from the vb.library.txt code snipped file '## This file contains all the code snippets you need for most metadata handling. '####################################################################################### 'Data events are separated with CR and/or LF characters 'This handler can handle cases where both or either of these characters are present Function HandleLine(sLine) Dim P Dim Data Dim Params(20) Dim ParamCount Dim RecordEnd1 Dim RecordEnd2 RecordEnd1 = Chr(13) RecordEnd2 = Chr(10) P = InStr(sLine, RecordEnd1) If P <= 0 Then P = InStr(sLine, RecordEnd2) End If While (P > 0) Data = Mid(sLine,1,P-1) Data = TrimLineFeed(Data) 'Remove NewLine and LineFeed special characters if they STILL exist sLine = Mid(sLine,P+1,Len(sLine)) If Data <> "" Then ExtractParams Data, Params, ParamCount ProcessParams Params, ParamCount End If P = InStr(sLine, RecordEnd1) If P <= 0 Then P = InStr(sLine, RecordEnd2) End If Wend 'If any portion of the line is left over 'return it so we can append more data to it HandleLine = sLine If sLine <> "" Then Log("Line-out: " & sLine) End If End Function 'Extract the data between two string values 'Usage: data = ExtractTagValue(sLine,"","") 'sLine is: data 'Usage: data = ExtractTagValue(sLine,"artist=","&") 'sLine is: &title=Test&artist=Test& Function ExtractTagValue(sLine, tagStart, tagClose) Dim P1,P2 Dim Data Data = "" P1 = InStr(sLine, tagStart) + Len(tagStart) If (P1>0) Then Data = Mid(sLine, P1, Len(sLine)) P2 = InStr(Data, tagClose) If (P2>0) Then Data = Mid(Data, 1, P2-1) End If End If ExtractTagValue = Data End Function 'Converts time string into milliseconds 'Expected formats: ' hh:mm:ss ' h:mm:ss ' mm:ss ' m:ss ' ss ' s ' mm:ss.mls 'Usage examples: ' duration = TimeStrToDuration("0:03:56") ' duration = TimeStrToDuration("03:56") ' duration = TimeStrToDuration("3:56") ' duration = TimeStrToDuration("56") ' duration = TimeStrToDuration("03:56.123") NOTE: Milliseconds are simply ignored in this case Function TimeStrToDuration(timeStr) const SepChar = ":" Dim P Dim Duration Dim Params(20) Dim ParamCount 'Firstly lets clean up the string. Make sure there are no spaces or other white space 'Also add one more SepChar to the end (Just makes our while loop simpler) timeStr = Trim(timeStr) & SepChar 'Split out each value ParamCount = 0 P = InStr(timeStr, SepChar) While (P > 0) Params(ParamCount) = Mid(timeStr,1,P-1) ParamCount = ParamCount + 1 timeStr = Mid(timeStr,P+1,Len(timeStr)) P = InStr(timeStr, SepChar) Wend 'Calculate duration If ParamCount = 1 Then Duration = int(Params(0))*1000 'seconds only ElseIf ParamCount = 2 Then Duration = (((int(Params(0))*60) + (int(Params(1))))*1000) 'minutes and seconds ElseIf ParamCount = 3 Then Duration = (((int(Params(0))*60*60) + (int(Params(1))*60) + (int(Params(2))))*1000) 'hours, minutes and seconds Else SongInfo.Log("Unexpected time format.") Duration = -1 End If TimeStrToDuration = Duration End Function 'Remove the EOL and LF characters from a string 'Usage: cleanLine = TrimLineFeed(sourceLine) Function TrimLineFeed(sLine) sLine = Replace(sLine,Chr(13),"") sLine = Replace(sLine,Chr(10),"") TrimLineFeed = sLine End Function 'Add a new parameter value and increase the counter 'NOTE: White space is removed from Data Function AddParam(Data, ByRef Params, ByRef ParamCount) Data = Trim(Data) SongInfo.Log("Param" & ParamCount & ": " & Data) Params(ParamCount) = Data ParamCount = ParamCount + 1 End Function 'Simple function that wraps the logging method so you have to do less typing Function Log(Msg) SongInfo.Log(Msg) End Function