Daniel Crichton
10/3/2007 12:14:00 PM
scott wrote on Tue, 2 Oct 2007 11:20:56 -0500:
> I assume that "g:\temp\test.smil" should be my playlist path. What does
> the path in the below line represent?
> Set oSeq = oDOM.selectSingleNode("/smil/body/seq")
The above line will set the object variable oSeq to point to the first node
that matches in the structure
<smil>
<body>
<seq>
the following line then loops through the childNodes (which will be all the
<media> nodes)
Dan
> "Anthony Jones" <Ant@yadayadayada.com> wrote in message news:ebqyjFOBIHA.1212@TK2MSFTNGP05.phx.gbl...
>> "scott" <sbailey@mileslumber.com> wrote in message
>> news:eXFedyDBIHA.1356@TK2MSFTNGP03.phx.gbl...
>>> From looking at the xml structure, it looks like sorting the src
>>> attribute would be about the only thing that I could sort by. If I
>>> could sort that, then at least the artists would be in order within
>>> the playlist.
>> I'm not sure where ASP fits into all this however here is a VBScript
>> that will do the sort based on the src attribute:-
>> Dim oDOM
>> Dim oSeq
>> Dim arrMedia
>> Dim i
>> Set oDOM = CreateObject("MSXML2.DOMDocument.3.0")
>> oDOM.load "g:\temp\test.smil"
>> Set oSeq = oDOM.selectSingleNode("/smil/body/seq")
>> ReDim arrMedia(oSeq.childNodes.length - 1)
>> For i = 0 To UBound(arrMedia)
>> Set arrMedia(i) = oSeq.childNodes(i)
>> Next
>> ShellSortObj arrMedia, GetRef("Comparator")
>> For i = 0 To UBound(arrMedia)
>> oSeq.appendChild arrMedia(i)
>> Next
>> oDOM.save "g:\temp\test2.smil"
>> Function Comparator(roLeft, roRight)
>> Comparator = roLeft.getAttribute("src") > roRight.getAttribute("src")
>> End Function
>> Sub ShellSortObj(rarr, fnCompare)
>> Dim i, j
>> Dim distance
>> Dim tmpValue
>> Dim lCount
>> lCount = UBound(rarr) + 1
>> distance = 0
>> Do distance = distance * 3 + 1
>> Loop Until distance > lCount
>> Do distance = distance \ 3
>> For i = distance To lCount - 1
>> If fnCompare(rarr(i - distance), rarr(i)) Then j = i
>> Set tmpValue = rarr(j)
>> Do
>> Set rarr(j) = rarr(j - distance)
>> j = j - distance
>> If j + 1 <= distance Then Exit Do
>> Loop While fnCompare(rarr(j - distance), tmpValue)
>> ' move the data back in the array
>> Set rarr(j) = tmpValue
>> End If
>> Next
>> Loop Until distance <= 1
>> End Sub
>> Note the at its the comparator function that defines the basis for
>> sort.
>> So with a few utlity functions:-
>> Function GetFolder(FilePath)
>> Dim lLastSlash
>> lLastSlash = InStrRev(FilePath, "\")
>> If lLastSlash > 0 Then
>> GetFolder = Left(FilePath, lLastSlash - 1)
>> End If
>> End Function
>> Function GetTrackNo(FileName)
>> Dim lLastSlash
>> Dim lLastDot
>> Dim sFileTitle
>> lLastSlash = InStrRev(FileName, "\")
>> lLastDot = InStrRev(FileName, ".")
>> sFileTitle = Mid(FileName, lLastSlash + 1, lLastDot - lLastSlash - 1)
>> GetTrackNo = CInt(Right(sFileTitle, 2))
>> End Function
>> We can change the comparator to:-
>> Function Comparator(roLeft, roRight)
>> Dim sLeftFolder
>> Dim sRightFolder
>> Dim sLeftTrackNo
>> Dim sRightTrackNo
>> sLeftFolder = GetFolder(roLeft.getAttribute("src"))
>> sRightFolder = GetFolder(roRight.getAttribute("src"))
>> If sLeftFolder = sRightFolder Then sLeftTrackNo =
>> GetTrackNo(roLeft.getAttribute("src"))
>> sRightTrackNo = GetTrackNo(roRight.getAttribute("src"))
>> Comparator = sLeftTrackNo > sRightTrackNo
>> Else
>> Comparator = sLeftFolder > sRightFolder
>> End If
>> End Function
>> Now it will sort by folder then by track number. Hence a sensible
>> folder structure which has a folder per artist in which there is a
>> folder per album will sort quite nicely.
>> You (or other readers) might be tempted to optimize the code (sort
>> oriented questions tends to bring that desire out of people) but
>> don't in the real world the performance of thsi code is perfectly
>> adequate.
>> --
>> Anthony Jones - MVP ASP/ASP.NET