Advertisement
Guest User

foo_allmusic.vbs

a guest
Dec 5th, 2011
699
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  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%"" [bio]"
  7.     WScript.Quit()
  8.  
  9. Else
  10.  
  11.     ARTIST = ARGS.Item(0)
  12.     ALBUM = ARGS.Item(1)
  13.  
  14.     If ARGS.Count = 3 Then
  15.         If LCase(ARGS.Item(2)) = "bio" Then
  16.             WScript.Echo Biography(ARTIST, ALBUM)
  17.         End If
  18.     Else
  19.         WScript.Echo Review(ARTIST, ALBUM)
  20.     End If
  21.  
  22. End If
  23.  
  24. Set ARGS = Nothing
  25.  
  26.  
  27. Function Review(ARTIST, ALBUM)
  28.  
  29.     URL = "http://allmusic.com/search/album/" & LCase(Replace(ALBUM, " ", "+"))
  30.  
  31.     Set RE = New RegExp
  32.  
  33.     RE.Pattern = "title=""(100|9.)%""[\s\S]*?<td><a href=""(.*?)"">(.*?)<[\s\S]*?<td>(.*?)</td>"
  34.     RE.Global = True
  35.  
  36.     Set Matches = RE.Execute(Request(URL))
  37.  
  38.     If Matches.Count > 0 Then
  39.         For Each match in Matches
  40.             If match.SubMatches.Count > 1 Then
  41.                 If LCase(match.SubMatches(3)) = LCase(ARTIST) Then
  42.  
  43.                     URL = match.SubMatches(1) & "/review"
  44.                     Raw = Request(URL)
  45.  
  46.                     Set REr = New RegExp
  47.                     REr.Pattern = "<div id=""review"">[\s\S]*?author"">([\S ]+)</p>[\s\S]*?text"">(.+?)</p>"
  48.  
  49.                     If REr.Test(Raw) = True Then
  50.                         Set R = REr.Execute(Raw)
  51.  
  52.                         If match.SubMatches(0) < 100 Then
  53.                             WScript.Echo match.SubMatches(3) & vbCrLf & match.SubMatches(2) & vbCrLf & "(Relevance: " & match.SubMatches(0) & "%)" & vbCrLf
  54.                         End If
  55.  
  56.                         Review = ClnStr(R(0).SubMatches(1), "<[^>]*>") & vbCrLf & vbCrLf & "Review " & R(0).SubMatches(0)
  57.  
  58.                         Set R = Nothing
  59.                         Set REr = Nothing
  60.                         Exit For
  61.                     End If
  62.  
  63.                 End If
  64.             End If
  65.         Next
  66.     Else
  67.         WScript.Echo "No Matches for: """ & ALBUM & """ by " & ARTIST
  68.     End If
  69.  
  70.     Set Matches = Nothing
  71.     Set RE = Nothing
  72. End Function
  73.  
  74.  
  75. Function Biography(ARTIST, ALBUM)
  76.  
  77.     URL = "http://allmusic.com/search/artist/" & LCase(Replace(ARTIST, " ", "+")) & "/exact:0/order:relevance"
  78.  
  79.     Set RE = New RegExp
  80.  
  81.     RE.Pattern = "relevance text[\s\S]*?<td><a href=""(\S+)"">(.*?)<"
  82.     RE.Global = True
  83.  
  84.     Set Matches = RE.Execute(Request(URL))
  85.  
  86.     If Matches.Count > 0 Then
  87.         For Each match in Matches
  88.             If match.SubMatches.Count > 1 Then
  89.                 If LCase(match.SubMatches(1)) = LCase(ARTIST) Then
  90.  
  91.                     URL = match.SubMatches(0)
  92.  
  93.                     If ChkRls(URL, ALBUM) = True Then
  94.  
  95.                         Raw = Request(URL & "/biography")
  96.  
  97.                         Set REr = New RegExp
  98.                         REr.Pattern = "bio"">[\s\S]*?author"">(.*?)</p>[\s\S]*?text"">([\s\S]+)</p>"
  99.  
  100.                         If REr.Test(Raw) = True Then
  101.                             Set R = REr.Execute(Raw)
  102.  
  103.                             Biography = ClnStr(R(0).SubMatches(1), "<[^>]*>") & vbCrLf & vbCrLf & "Biography " & R(0).SubMatches(0)
  104.  
  105.                             Set R = Nothing
  106.                             Set REr = Nothing
  107.                             Exit For
  108.                         End If
  109.  
  110.                     Set REr = Nothing
  111.                     End If
  112.                 End If
  113.             End If
  114.         Next
  115.     Else
  116.         WScript.Echo "No Matches for: " & ARTIST
  117.     End If
  118.  
  119.     Set Matches = Nothing
  120.     Set RE = Nothing
  121. End Function
  122.  
  123.  
  124. Function Request(URL)
  125.     Set HTTP = CreateObject("Microsoft.XMLHTTP")
  126.  
  127.     HTTP.open "GET", URL, False
  128.     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"
  129.     HTTP.send ""
  130.     If Err.number <> 0 then
  131.         WScript.Echo "Error: " & HTTP.parseError.URL & vbCrLf & HTTP.parseError.Reason
  132.     End If
  133.  
  134.     Request = HTTP.responseText
  135.     Set HTTP = Nothing
  136. End Function
  137.  
  138.  
  139. Function ChkRls(URL, ALBUM)
  140.     Set REc = New RegExp
  141.  
  142.     REc.Pattern = "<td class=""cell""><a.*?>(.*?)</a></td>"
  143.     REc.Global = True
  144.  
  145.     Set Matches = REc.Execute(Request(URL & "/discography"))
  146.  
  147.     For Each match in Matches
  148.         If InStr(ClnStr(match.SubMatches(0), "[\W]"), ClnStr(ALBUM, "[\W]")) > 0 Then
  149.             ChkRls = True
  150.         End If
  151.     Next
  152.  
  153.     Set REc = Nothing
  154. End Function
  155.  
  156.  
  157. Function ClnStr(strText, strPat)
  158.     Set REt = New RegExp
  159.  
  160.     REt.Pattern = strPat
  161.     REt.Global = True
  162.  
  163.     ClnStr = REt.Replace(strText, "")
  164.     Set REt = Nothing
  165. End Function
  166.  
  167.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement