Skip to content

Instantly share code, notes, and snippets.

@rornor
Created December 29, 2012 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rornor/eac964ab791a4b2f7dfb to your computer and use it in GitHub Desktop.
Save rornor/eac964ab791a4b2f7dfb to your computer and use it in GitHub Desktop.
foobar2000, Biography View script to list playing artist discography according MusicBrainz
Set ARGS = WScript.Arguments
Set XML = CreateObject("Microsoft.XMLDOM")
XML.async = false
If ARGS.Count < 1 Then
WScript.Echo "Usage: cscript //nologo mb_discography.vbs [""%artist%""|%MUSICBRAINZ_ARTISTID%]"
WScript.Quit()
Else
If Len(ARGS.Item(0)) = 36 And UBound(Split(ARGS.Item(0), "-")) = 4 Then
id = ARGS.Item(0)
Else
id = getMBid(Trim(ARGS.Item(0)))
End If
If id <> "" Then
OutputNET(getReleases(id))
Else
WScript.Echo("No matches")
End If
Set XML = Nothing
End If
Function getMBid(artist)
XML.load("http://www.musicbrainz.org/ws/2/artist/?query=artist:" & LCase(Replace(artist, " ", "+")))
Set NODES = XML.getElementsByTagName("metadata/artist-list/artist[@ext:score='100']")
id = ""
For Each node In NODES
If LCase(artist) = LCase(node.firstChild.text) Then
id = node.selectSingleNode("@id").text
Exit For
End If
Next
Set NODES = Nothing
getMBid = id
End Function
Function getReleases(id)
XML.load("http://www.musicbrainz.org/ws/2/release-group?artist=" & id)
cnt = XML.selectSingleNode("metadata/release-group-list/@count").text
Dim arr()
ReDim arr(Int(cnt/100), 100)
For j = 0 To Int(cnt/100)
XML.load("http://www.musicbrainz.org/ws/2/release-group?artist=" & id & "&limit=100&offset=" & 100*j)
Set NODES = XML.getElementsByTagName("metadata/release-group-list/release-group[@type='Album' or @type='EP' or @type='Single']")
i = 0
For Each node In NODES
Set D = CreateObject("Scripting.Dictionary")
D.Add "type", node.selectSingleNode("@type").text
D.Add "rgid", node.selectSingleNode("@id").text
For Each nod In node.childNodes
D.Add nod.nodeName, nod.text
Next
Set arr(j, i) = D
Set D = Nothing
i = i + 1
Next
Next
Set NODES = Nothing
getReleases = arr
End Function
Function Output(r)
For k = 0 To Ubound(r, 1)
For l = 0 To Ubound(r, 2)
If Not IsEmpty(r(k, l)) Then
WScript.Echo(Left(r(k, l).Item("first-release-date"), 4) & Space(4) & UCase(Left(r(k, l).Item("type"), 1)) & Space(4) & r(k, l).Item("title"))
End If
Next
Next
End Function
Function OutputNET(r)
Set AL = CreateObject("System.Collections.ArrayList")
For k = 0 To Ubound(r, 1)
For l = 0 To Ubound(r, 2)
If Not IsEmpty(r(k, l)) Then
AL.Add Left(r(k, l).Item("first-release-date"), 4) & Space(4) & UCase(Left(r(k, l).Item("type"), 1)) & Space(4) & r(k, l).Item("title")
End If
Next
Next
AL.Sort()
AL.Reverse()
For Each line in AL
WScript.Echo(line)
Next
Set AL = Nothing
End Function
@rornor
Copy link
Author

rornor commented Dec 29, 2012

Thread: link

Example Biography View command:

cscript //nologo mb_discography.vbs "%artist%"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment