Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Set ARGS = WScript.Arguments
- If ARGS.Count < 2 Then
- WScript.Echo "Usage: cscript //Nologo scripts\foo_allmusic.vbs ""%album artist%"" ""%album%"" [bio]"
- WScript.Quit()
- Else
- ARTIST = ARGS.Item(0)
- ALBUM = ARGS.Item(1)
- If ARGS.Count = 3 Then
- If LCase(ARGS.Item(2)) = "bio" Then
- WScript.Echo Biography(ARTIST, ALBUM)
- End If
- Else
- WScript.Echo Review(ARTIST, ALBUM)
- End If
- End If
- Set ARGS = Nothing
- Function Review(ARTIST, ALBUM)
- URL = "http://allmusic.com/search/album/" & LCase(Replace(ALBUM, " ", "+"))
- Set RE = New RegExp
- RE.Pattern = "title=""(100|9.)%""[\s\S]*?<td><a href=""(.*?)"">(.*?)<[\s\S]*?<td>(.*?)</td>"
- RE.Global = True
- Set Matches = RE.Execute(Request(URL))
- If Matches.Count > 0 Then
- For Each match in Matches
- If match.SubMatches.Count > 1 Then
- If LCase(match.SubMatches(3)) = LCase(ARTIST) Then
- URL = match.SubMatches(1) & "/review"
- Raw = Request(URL)
- Set REr = New RegExp
- REr.Pattern = "<div id=""review"">[\s\S]*?author"">([\S ]+)</p>[\s\S]*?text"">(.+?)</p>"
- If REr.Test(Raw) = True Then
- Set R = REr.Execute(Raw)
- If match.SubMatches(0) < 100 Then
- WScript.Echo match.SubMatches(3) & vbCrLf & match.SubMatches(2) & vbCrLf & "(Relevance: " & match.SubMatches(0) & "%)" & vbCrLf
- End If
- Review = ClnStr(R(0).SubMatches(1), "<[^>]*>") & vbCrLf & vbCrLf & "Review " & R(0).SubMatches(0)
- Set R = Nothing
- Set REr = Nothing
- Exit For
- End If
- End If
- End If
- Next
- Else
- WScript.Echo "No Matches for: """ & ALBUM & """ by " & ARTIST
- End If
- Set Matches = Nothing
- Set RE = Nothing
- End Function
- Function Biography(ARTIST, ALBUM)
- URL = "http://allmusic.com/search/artist/" & LCase(Replace(ARTIST, " ", "+")) & "/exact:0/order:relevance"
- Set RE = New RegExp
- RE.Pattern = "relevance text[\s\S]*?<td><a href=""(\S+)"">(.*?)<"
- RE.Global = True
- Set Matches = RE.Execute(Request(URL))
- If Matches.Count > 0 Then
- For Each match in Matches
- If match.SubMatches.Count > 1 Then
- If LCase(match.SubMatches(1)) = LCase(ARTIST) Then
- URL = match.SubMatches(0)
- If ChkRls(URL, ALBUM) = True Then
- Raw = Request(URL & "/biography")
- Set REr = New RegExp
- REr.Pattern = "bio"">[\s\S]*?author"">(.*?)</p>[\s\S]*?text"">([\s\S]+)</p>"
- If REr.Test(Raw) = True Then
- Set R = REr.Execute(Raw)
- Biography = ClnStr(R(0).SubMatches(1), "<[^>]*>") & vbCrLf & vbCrLf & "Biography " & R(0).SubMatches(0)
- Set R = Nothing
- Set REr = Nothing
- Exit For
- End If
- Set REr = Nothing
- End If
- End If
- End If
- Next
- Else
- WScript.Echo "No Matches for: " & ARTIST
- End If
- Set Matches = Nothing
- Set RE = Nothing
- End Function
- Function Request(URL)
- Set HTTP = CreateObject("Microsoft.XMLHTTP")
- HTTP.open "GET", URL, False
- 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"
- HTTP.send ""
- If Err.number <> 0 then
- WScript.Echo "Error: " & HTTP.parseError.URL & vbCrLf & HTTP.parseError.Reason
- End If
- Request = HTTP.responseText
- Set HTTP = Nothing
- End Function
- Function ChkRls(URL, ALBUM)
- Set REc = New RegExp
- REc.Pattern = "<td class=""cell""><a.*?>(.*?)</a></td>"
- REc.Global = True
- Set Matches = REc.Execute(Request(URL & "/discography"))
- For Each match in Matches
- If InStr(ClnStr(match.SubMatches(0), "[\W]"), ClnStr(ALBUM, "[\W]")) > 0 Then
- ChkRls = True
- End If
- Next
- Set REc = Nothing
- End Function
- Function ClnStr(strText, strPat)
- Set REt = New RegExp
- REt.Pattern = strPat
- REt.Global = True
- ClnStr = REt.Replace(strText, "")
- Set REt = Nothing
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement