Skip to content

Instantly share code, notes, and snippets.

@rornor rornor/shout.vbs Secret
Created Dec 29, 2012

Embed
What would you like to do?
foobar2000, Biography View script with initial idea for identifying SHOUTcast track artist/title, then it evolved to general track info, when such info may be desired and unknown, like while listening streams
DisplayBio = 1
DisplayAlbumTracks = 1
DownloadCover = 0 ' if true, will download current track's album cover in %tmp%\stream.jpg
Set ARG = WScript.Arguments
If ARG.Count <> 2 Then
WScript.Echo "Usage: cscript //nologo shout.vbs ""%artist%"" ""%title%"""
WScript.Quit()
Else
If Arg(0) <> "?" And Arg(1) <> "?" Then
If DownloadCover Then CleanTmp
LfmInfo ARG(0), ARG(1)
ENd If
End If
Function LfmInfo(artist, track)
Set XML = CreateObject("MSXML2.DOMDocument.6.0")
ws = "http://ws.audioscrobbler.com/2.0/?method="
api = StrReverse("9c8f955632698c23323d4b2c7a77030") & Chr(100) : q = Chr(34)
XML.loadXML(Request(ws & "track.getinfo&api_key=" &_
api & "&artist=" & artist & "&track=" & track))
Set X = XML.selectSingleNode("lfm/track/album/title")
If Not X Is Nothing Then album = X.text : rel = " from " & q & album & q & vbCrLf End If
Set X = XML.selectSingleNode("lfm/track/mbid")
If Not X Is Nothing Then track_mbid = X.text End If
Set X = XML.selectSingleNode("lfm/track/artist/mbid")
If Not X Is Nothing Then artist_mbid = X.text End If
If DisplayBio Then
au = ws & "artist.getinfo&api_key=" & api & "&artist=" & artist
If artist_mbid <> "" Then au = au & "&mbid=" & artist_mbid
XML.loadXML(Request(au))
Set X = XML.selectSingleNode("lfm/artist/bio/summary")
If Not X Is Nothing Then
If X.text <> "" Then bio = "SHORT BIO:" & vbCrLf & DropHtml(X.text) & vbCrLf End If
End If
End If
If album <> "" Then
XML.loadXML(Request(ws & "album.getinfo&api_key=" &_
api & "&artist=" & artist & "&album=" & album))
Set X = XML.selectSingleNode("lfm/album/mbid")
If Not X Is Nothing Then album_mbid = X.text End If
Set X = XML.selectSingleNode("lfm/album/releasedate")
If Not X Is Nothing Then
If X.text <> "" Then
rel = Left(rel, Len(rel)-2) & ", released on " & Mid(X.text, 1, InStr(X.text, ",")-1) & vbCrLf
End If
End If
Set X = XML.selectSingleNode("lfm/album/wiki/summary")
If Not X Is Nothing Then
If X.text <> "" Then rel = rel & vbCrLf & "SHORT REVIEW:" & vbCrLf & DropHtml(X.text) & vbCrLf End If
End If
If DownloadCover Then
Set X = XML.selectSingleNode("lfm/album/image[@size='extralarge']")
If Not X Is Nothing Then
Set fso = WScript.CreateObject("Scripting.Filesystemobject")
tmp = fso.GetSpecialFolder(2) & "\stream"
imgType = Mid(X.text, InStrRev(X.text,"."), Len(X.text))
ADODump X.Text, tmp & imgType
End If
End If
End If
If DisplayAlbumTracks Then
Set X = XML.selectNodes("lfm/album/tracks/track")
If Not X Is Nothing Then
For Each t In X
If LCase(track) = LCase(t.selectSingleNode("name").text) Then p = "* " Else p = " " End If
trklst = trklst & p & Space(Len(t.getAttribute("rank")) mod 2) & t.getAttribute("rank") & ". " &_
t.selectSingleNode("name").text & vbCrLf
Next
If trklst <> "" Then trklst = "ALBUM TRACKLIST: " & vbCrLf & trklst End If
End If
End If
If DisplayBio Then rel = rel & vbCrLf & bio End If
If DisplayAlbumTracks Then rel = rel & vbCrLf & trklst End If
WScript.Echo "NOW PLAYING: " & q & track & q & " by " & q & artist & q & vbCrLf & rel
End Function
Sub ADODump(url, fn)
Set ADO = CreateObject("Adodb.Stream")
dat = Request(url)
ADO.Type = 1 ' 1 = binary
ADO.Open
ADO.Write dat
ADO.SaveToFile fn, 2 ' 2 = overwrite
End Sub
Sub CleanTmp()
Set fso = CreateObject("Scripting.Filesystemobject")
tmp = fso.GetSpecialFolder(2) & "\stream"
Dim tmps(4)
tmps(0) = tmp & ".jpg" : tmps(1) = tmp & ".jpeg" : tmps(2) = tmp & ".png" : tmps(3) = tmp & ".gif"
For Each f in tmps
If fso.FileExists(f) Then fso.DeleteFile f
Next
End Sub
Function DropHtml(s)
Set HTML = CreateObject("HtmlFile")
HTML.write s
DropHtml = HTML.body.innerText
End Function
Function Request(url)
Set HTTP = CreateObject("MSXML2.XMLHTTP")
HTTP.open "GET", url, 0
HTTP.send ""
If Err.number <> 0 then
WScript.Echo "Error: " & HTTP.parseError.url & vbCrLf & HTTP.parseError.Reason
WScript.Quit()
End If
If InStr(url, "userserve-ak.last.fm") > 0 Then
Request = HTTP.responseBody
Else
Request = HTTP.responseText
End If
End Function
@rornor

This comment has been minimized.

Copy link
Owner Author

commented Dec 29, 2012

Thread: link

Example Biography View command:

cscript //nologo shout.vbs "%artist%" "%title%"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.