Pretty quick and inefficient scrpt to enqueue tracks from an album, sorted by popularity on Last.FM
dim xmlhttp, mlq, dict1,scrapedtitles dim regEx, regEx2, regEx3, WidthMatch, Match, Matches, Matches2, WidthMatches ' Create variable. Function RegExpAdd(patrn, strng) Set regEx = New RegExp ' Create a regular expression. Set regEx2 = New RegExp ' Create a regular expression. Set regEx3 = New RegExp ' Create a regular expression. regEx.Pattern = patrn ' Set pattern. regEx.IgnoreCase = True ' Set case insensitivity. regEx.Global = True ' Set global applicability. regEx3.Pattern = "<div class=.*bar.*width.*>" regEx3.IgnoreCase = True ' Set case insensitivity. regEx3.Global = True ' Set global applicability. Set Matches = regEx.Execute(strng) ' Execute search. Set WidthMatches = regEx3.Execute(strng) ' Execute search. songnum = 0 For Each Match in Matches ' Iterate Matches collection. 'Find song title within URL regEx2.Pattern = ">.*<" regEx2.IgnoreCase = True ' Set case insensitivity. Set Matches2 = regEx2.Execute(Match.Value) songtitle = Matches2(0).Value songtitle = Right(songtitle, Len(songtitle) - 1) songtitle = Left(songtitle, Len(songtitle) - 1) songtitle = Trim(songtitle) 'Find popularity % within div block regEx2.Pattern = ":.*%" regEx2.IgnoreCase = True ' Set case insensitivity. Set WidthMatch = WidthMatches(songnum) Set Matches2 = regEx2.Execute(WidthMatch.Value) widthval = Matches2(0).Value widthval = Right(widthval, Len(widthval) - 1) widthval = Left(widthval, Len(widthval) - 1) scrapedtitles(ucase(songtitle)) = widthval songnum = songnum + 1 Next End Function x = playlist.getselection if ubound(x) > 0 then Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP.4.0") xmlhttp.Open "GET", "http://www.last.fm/music/" + x(1).artist + "/" + x(1).album, false 'msgbox ("http://www.last.fm/" + x(1).artist + "/" + x(1).album) xmlhttp.Send res = xmlhttp.responsetext Set scrapedtitles = CreateObject("Scripting.dictionary") RegExpAdd "/music/.*/_/.*>.*</a", res mlq = MediaLibrary.RunQueryArray("artist = """ & x(1).artist & """ and album = """ & x(1).album + """") Set Dict1 = CreateObject("Scripting.dictionary") i = 1 For each song in mlq dict1(ucase(song.title)) = i i = i + 1 Next 'Loop through each item, grabbing the max popularity item each time for each popu1 in scrapedtitles popumax1 = -1 minkey = "" for each popu in scrapedtitles if (CInt(scrapedtitles(popu)) >= popumax1) then popumax1 = CInt(scrapedtitles(popu)) minkey = popu end if next if dict1.exists(minkey) then mlq(dict1(minkey)).enqueue end if if (scrapedtitles.exists(minkey)) then scrapedtitles.remove minkey end if next end if Quit