Advertisement
Guest User

foo_allmusic

a guest
Dec 1st, 2011
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '~ On Error Resume Next
  2. Set ARGS = WScript.Arguments
  3.  
  4. If ARGS.Count < 2 Then
  5.  
  6.     WScript.Echo "Usage: cscript //Nologo scripts\foo_allmusic.vbs ""%album artist%"" ""%album%"""
  7.     WScript.Quit()
  8.  
  9. Else
  10.  
  11.     ARTIST = ARGS.Item(0)
  12.     ALBUM = ARGS.Item(1)
  13.  
  14.     URL = "http://allmusic.com/search/album/" & LCase(Replace(ALBUM, " ", "+"))
  15.  
  16.     Set RE = New RegExp
  17.  
  18.     RE.Pattern = "title=""100%""[\s\S]*?<td><a href=""(\S+)""[\s\S]*?<td>([\S ]+)</td>"
  19.     RE.Global = True
  20.  
  21.     Set Matches = RE.Execute(Request(URL))
  22.  
  23.     If Matches.Count > 0 Then
  24.         For Each match in Matches
  25.             If match.SubMatches.Count > 1 Then
  26.                 If LCase(match.SubMatches(1)) = LCase(ARTIST) Then
  27.  
  28.                     URL = match.SubMatches(0) & "/review"
  29.                     Raw = Request(URL)
  30.  
  31.                     Set REr = New RegExp
  32.                     REr.Pattern = "<div id=""review"">[\s\S]*?author"">([\S ]+)</p>[\s\S]*?text"">([\s\S ]+?)</p>"
  33.  
  34.                     If REr.Test(Raw) = True Then
  35.                         Set R = REr.Execute(Raw)
  36.  
  37.                         WScript.Echo RemTag(R(0).SubMatches(1)) & vbCrLf & vbCrLf & "Review " & R(0).SubMatches(0)
  38.  
  39.                         Set R = Nothing
  40.                         Set REr = Nothing
  41.                         Exit For
  42.                     End If
  43.  
  44.                 End If
  45.             End If
  46.         Next
  47.     Else
  48.         WScript.Echo "No Matches for: """ & ALBUM & """ by " & ARTIST
  49.     End If
  50.  
  51.     Set Matches = Nothing
  52.     Set RE = Nothing
  53. End If
  54.  
  55. Set ARGS = Nothing
  56.  
  57. Function Request(URL)
  58.     Set HTTP = CreateObject("MSXML2.ServerXMLHTTP")
  59.  
  60.     HTTP.open "GET", URL, False
  61.     HTTP.setRequestHeader "User-Agent","Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3"
  62.     HTTP.send ""
  63.     If Err.number <> 0 then
  64.         WScript.Echo "Error: " & HTTP.parseError.URL & vbCrLf & HTTP.parseError.Reason
  65.     End If
  66.  
  67.     Request = HTTP.responseText
  68.     Set HTTP = Nothing
  69. End Function
  70.  
  71. Function RemTag(strText)
  72.     Set REt = New RegExp
  73.  
  74.     REt.Pattern = "<[^>]*>"
  75.     REt.Global = True
  76.  
  77.     RemTag = REt.Replace(strText, "")
  78.     Set REt = Nothing
  79. End Function
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement