Advertisement
Guest User

foo_allmusic.vbs

a guest
Dec 1st, 2011
237
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.                         WScript.Echo RemTag(R(0).SubMatches(1)) & vbCrLf & vbCrLf & "Review " & R(0).SubMatches(0)
  37.                         Set R = Nothing
  38.                     Else
  39.                         Crawl = 1
  40.                     End If
  41.  
  42.                     Set REr = Nothing
  43.  
  44.                     If Not Crawl = 1 Then
  45.                         Exit For
  46.                     End If
  47.  
  48.                 End If
  49.             End If
  50.         Next
  51.     Else
  52.         WScript.Echo "No Matches for: """ & ALBUM & """ by " & ARTIST
  53.     End If
  54.  
  55.     Set Matches = Nothing
  56.     Set RE = Nothing
  57. End If
  58.  
  59. Set ARGS = Nothing
  60.  
  61. Function Request(URL)
  62.     Set HTTP = CreateObject("MSXML2.ServerXMLHTTP")
  63.  
  64.     HTTP.open "GET", URL, False
  65.     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"
  66.     HTTP.send ""
  67.     If Err.number <> 0 then
  68.         WScript.Echo "Error: " & HTTP.parseError.URL & vbCrLf & HTTP.parseError.Reason
  69.     End If
  70.  
  71.     Request = HTTP.responseText
  72.     Set HTTP = Nothing
  73. End Function
  74.  
  75. Function RemTag(strText)
  76.     Set REt = New RegExp
  77.  
  78.     REt.Pattern = "<[^>]*>"
  79.     REt.Global = True
  80.  
  81.     RemTag = REt.Replace(strText, "")
  82.     Set REt = Nothing
  83. End Function
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement