View Single Post
Old 2nd October 2004, 03:17   #107
shaneh
Major Dude
 
Join Date: Jan 2004
Location: Brisbane, Australia
Posts: 1,193
example script

To demonstrate a lengthy web service type script and the multi-threading support, heres a neat little script. It will query Audioscrobbler for the top songs by a song selected in your playlist and attempt to enqueue them.

Prob got a few bugs, but you get the idea.


-------playlist_enqueue artists top songs as.vbs---------

dim xmlhttp, art, dict1, mlq

x = playlist.getselection

if ubound(x) > 0 then

Set Dict1 = CreateObject("Scripting.dictionary")
Dict1.CompareMode = 1
art = x(1).artist
mlq = medialibrary.runqueryarray("artist = """ & art & """")

i = 1
for each song in mlq
dict1(song.title) = i
i = i + 1
next

set xmlhttp = CreateObject("Msxml2.XMLHTTP.4.0")
set xmlDoc = CreateObject("Msxml2.DOMDocument.4.0")

xmlhttp.Open "GET", "http://www.audioscrobbler.com/music/" + art, false
xmlhttp.Send

res = xmlhttp.responsetext
xmldoc.validateonparse = false
xmldoc.resolveexternals = false

ns = "xmlns:asx='http://www.w3.org/1999/xhtml'"
xmldoc.setProperty "SelectionNamespaces", ns

xmldoc.loadxml replace(res, "&", " ")

If (xmlDoc.parseError.errorCode <> 0) Then
Dim myErr
Set myErr = xmlDoc.parseError
MsgBox(myerr.reason + " " + myErr.srctext)
quit
end if

set nl = xmldoc.documentelement.selectSingleNode("asx:body/asx:div[@id='main']/asx:div[@class='content']/asx:table[@class='topn']")
set tl = nl.selectNodes("asx:tr")

for each song in tl
idx = dict1(song.selectSingleNode("asx:td/asx:a").text)
if (idx > 0) then
mlq(idx).enqueue
end if

next

end if
quit
shaneh is offline   Reply With Quote