Advertisement
mire777

Foobar Allmusic Album Reveiw (Romor Script)

Jun 5th, 2014
780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.86 KB | None | 0 0
  1. Cache = 1 ' set to 0 to turn caching off
  2.  
  3. Set Arg = WScript.Arguments
  4. If Cache Then Set oXml = CreateObject("MSXML2.DOMDocument.6.0")
  5.  
  6. If Arg.Count <> 3 Then
  7. WScript.Echo "Usage: cscript //nologo allmusic.vbs ""%album artist%"" ""%album%"" review|bio"
  8. WScript.Quit()
  9. Else
  10. If Arg(0) <> "?" And Arg(1) <> "?" Then
  11. id = md5(Arg(0) & Arg(1))
  12. If Not CacheCheck Then
  13. If Arg(2) = "skip" Then
  14. CacheUpdate("")
  15. Else
  16. Dim albumLink, artistLink
  17. If Len(Arg(1)) < 3 Then query = Arg(1) & " " & Arg(0) : Else query = Arg(1) End If
  18. content = search(arg(2))
  19. If content <> "" Then
  20. WScript.Echo content
  21. If Cache Then CacheUpdate content
  22. End If
  23. End If
  24. End If
  25. End If
  26. End If
  27.  
  28. Function search(result)
  29. Set html = CreateObject("HtmlFile")
  30. html.write Request("http://www.allmusic.com/search/albums/" & Escape(query))
  31. For Each row In html.getElementsByTagName("h4")
  32. Set album_search = row.nextSibling
  33. albumLink = album_search.firstChild.getAttribute("href")
  34. If Match(album_search.innerText, Arg(1)) Then
  35. If Match(album_search.nextSibling.innerText, Arg(0)) Then
  36. With CreateObject("HtmlFile")
  37. .write Request(albumLink)
  38. Set div = .getElementsByTagName("p")(1).parentNode
  39. review = div.innerText
  40. reviewAuthor = div.previousSibling.innerText
  41. artistLink = .getElementsByTagName("h3")(0).firstChild.getAttribute("href")
  42. End With
  43. If result = "bio" Then
  44. With CreateObject("HtmlFile")
  45. .write Request(artistLink & "\biography")
  46. Set div = .getElementsByTagName("p")(2).parentNode
  47. biography = div.innerText
  48. biographyAuthor = div.previousSibling.innerText
  49. search = biography & vbCrLf & vbCrLf & biographyAuthor
  50. End With
  51. Else
  52. search = review & vbCrLf & vbCrLf & reviewAuthor
  53. End If
  54. Exit For
  55. End If
  56. End If
  57. Next
  58. End Function
  59.  
  60. Function CacheCheck
  61. If Cache Then
  62. Set oFS = CreateObject("Scripting.FileSystemObject")
  63. If Not oFS.FileExists("foo_allmusic.xml") Then
  64. oXml.loadXML "<?xml version='1.0' encoding='UTF-8'?><Items></Items>"
  65. oXml.save "foo_allmusic.xml"
  66. Else
  67. oXml.load "foo_allmusic.xml"
  68. Set nod = oXml.selectSingleNode("Items/Item[@Id='" & id & "']/" & Arg(2))
  69. If Not nod Is Nothing Then
  70. If Arg(2) <> "skip" Then WScript.Echo nod.text
  71. CacheCheck = True
  72. Else
  73. Set nod = oXml.selectSingleNode("Items/Item[@Id='" & id & "']/skip")
  74. If Not nod Is Nothing Then CacheCheck = True
  75. End If
  76. End If
  77. End If
  78. End Function
  79.  
  80. Sub CacheUpdate(t)
  81. oXml.load "foo_allmusic.xml"
  82. Set root = oXml.selectSingleNode("Items")
  83. Set item = oXml.selectSingleNode("Items/Item[@Id='" & id & "']")
  84. If item Is Nothing Then
  85. Set item = oXml.createElement("Item")
  86. item.setAttribute "Id", id
  87. ArtistId = "mn0000000000" : AlbumId = "mw0000000000"
  88. If TypeName(artistLink) = "String" Then ArtistId = Split(artistLink, "-")(UBound(Split(artistLink, "-")))
  89. If TypeName(albumLink) = "String" Then AlbumId = Split(albumLink, "-")(UBound(Split(albumLink, "-")))
  90. item.setAttribute "ArtistId", ArtistId
  91. item.setAttribute "AlbumId", AlbumId
  92. Set comment = oXml.createComment(Arg(0) & " // " & Arg(1))
  93. item.appendChild comment
  94. root.appendChild item
  95. End If
  96. Set data = oXml.createElement(Arg(2))
  97. data.Text = t
  98. item.appendChild data
  99. oXml.save "foo_allmusic.xml"
  100. End Sub
  101.  
  102. Function Request(URL)
  103. Set HTTP = CreateObject("MSXML2.XMLHTTP")
  104. On Error Resume Next
  105. HTTP.open "GET", URL, False
  106. HTTP.send ""
  107. If Not CBool(Err.Number) Then resp = HTTP.responseText
  108. On Error Goto 0
  109. Request = resp
  110. End Function
  111.  
  112. Function Match(s1, s2)
  113. If InStr(LCase(Replace(s1, " ", "")), LCase(Replace(s2, " ", ""))) > 0 Or _
  114. InStr(LCase(Replace(s2, " ", "")), LCase(Replace(s1, " ", ""))) > 0 Then
  115. Match = True
  116. Else Match = False End If
  117. End Function
  118.  
  119. Function md5(s)
  120. Set MDC = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")
  121. Set UTF = CreateObject("System.Text.UTF8Encoding")
  122. hash = MDC.ComputeHash_2((UTF.GetBytes_4(s)))
  123. For i = 1 To Lenb(hash)
  124. md5 = md5 & LCase(Right("0" & Hex(Ascb(Midb(hash, i, 1))), 2))
  125. Next
  126. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement