'Expected input format:
'
'
'#######################################################################################
'## Custom Param Processing
'#######################################################################################
Function ProcessParams(Params, ParamCount)
Dim tmpType
If ParamCount <> 4 Then
Log("ParamCount expected to be 4, but " & ParamCount & " params returned. Aborting.")
Exit Function
End If
tmpType = Params(2)
If tmpType = "SONG" Then
tmpType = "S"
ElseIf tmpType = "SPOT" Then
tmpType = "A"
Else
tmpType = "J"
End If
SongInfo.Value("title") = Params(0)
SongInfo.Value("artist") = Params(1)
SongInfo.Value("songtype") = tmpType
SongInfo.Value("duration") = TimeStrToDuration(Params(3))
SongInfo.DoSongChange 'Triggers the metadata update in SAM Cast
End Function
'NOTE: Taken from vb.library.txt and adapted slightly
'Extract line into Params from XML string
'Example input:
'
Function ExtractParams(sLine, ByRef Params, ByRef ParamCount)
Dim Data
ParamCount = 0
'#0# Song title
Data = ExtractTagValue(sLine, "
","")
AddParam Data, Params, ParamCount
'#1# Artist name
Data = ExtractTagValue(sLine, "","")
AddParam Data, Params, ParamCount
'#2# Category
Data = ExtractTagValue(sLine, "", "")
AddParam Data, Params, ParamCount
'#3# Duration
Data = ExtractTagValue(sLine, "", "")
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