Skip to content

Instantly share code, notes, and snippets.

@rornor rornor/soundcloud.vbs Secret
Last active Sep 29, 2018

Embed
What would you like to do?
foobar2000, Biography View / foo_run script that allows querying SoundCloud then retrieving playlist automatically and at the same time displaying SoundCloud info in Biography View panel
waveform = False
folder = ""
cid = "75995580b5ff7caffb6b328410d590bb"
toc = "624fb4ec20075165db2a4303b51e9862"
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objXml = CreateObject("Microsoft.XMLDOM")
objXml.async = 0
If WScript.Arguments.Count > 0 Then
arg = WScript.Arguments.Item(0)
If Left(arg, 25) = "http://api.soundcloud.com" Then
objXml.load(Left(arg, InStr(Right(arg, Len(arg)-40), "/")+39) & "?client_id=" & cid)
head = Split("Track information, Statistics, Resource information", ", ")
tags = Array(Split("title duration id track-type created-at label-name release genre tag-list"),_
Split("playback-count download-count favoritings-count comment-count"),_
Split("uri permalink-url artwork-url waveform-url stream-url sharing licence"))
For Each tag In tags
WScript.Echo vbCrLf & UCase(head(i)) : i = i + 1
For Each t In tag : Info(t) : Next
Next
If waveform Then DownloadWaveform(objXml.selectSingleNode("track/waveform-url").text)
Set objNode = objXml.selectSingleNode("track/description")
If Not objNode Is Nothing Then
If objNode.text <> "" Then WScript.Echo vbCrLf & "DESCRIPTION" & vbCrLf &_
" " & Replace(objNode.text, vbLf, vbLf & " ")
End If
End If
Else
help = "Advanced queries:" & vbTab & "Examples:" & vbCrLf & vbCrLf & _
"• user=user name" & vbTab & "• user=neosignal" & vbCrLf & _
"• group=group name" & vbTab & "• group=error broadcast" & vbCrLf & _
"• set=set (playlist) name" & vbTab & "• set=ec set dubtep 01" & vbCrLf & _
"• tags=tag(s)" & vbTab & vbTab & "• tags=demoscene,8bit" & vbCrLf & vbCrLf & vbCrLf
q = Trim(InputBox(help & "Enter search term (or SoundCloud URL):", "SoundCloud search", ""))
If q <> "" Then
uri = "http://api.soundcloud.com/tracks?format=streamable&q=" & Replace(q, " ", "+") & "&"
If InStr("https://soundcloud.com", Left(q, 20)) Or InStr("http://soundcloud.com", Left(q, 20)) Then
uri = "http://api.soundcloud.com/resolve.xml?url=" & q & "&"
objXml.load(uri & "client_id=" & cid)
If objXml.xml <> "" Then
If InStr("user=group=", objXml.selectSingleNode("*[0]").nodeName) Then _
uri = "http://api.soundcloud.com/" & objXml.selectSingleNode("*[0]").nodeName & "s/" &_
objXml.selectSingleNode("//id").text & "/tracks.xml?"
Else
uri = "http://api.soundcloud.com/tracks?format=streamable&q=" & Replace(Split(q, "soundcloud.com")(1), "/", "+") & "&"
End If
ElseIf InStr(q, "=") Then
advQuery = Split(q, "=")
If InStr("user=group=tags=set=", advQuery(0)) Then
Select Case advQuery(0)
Case "user"
url = "http://api.soundcloud.com/users?format=streamable&q=" & Replace(specEscape(advQuery(1)), " ", "-") & "&order=hotness&"
name = "username"
Case "group"
url = "http://api.soundcloud.com/groups?format=streamable&q=" & Replace(specEscape(advQuery(1)), " ", "-") & "&order=hotness&"
name = "name"
Case "set" uri = "http://api.soundcloud.com/playlists?format=streamable&q=" & Replace(specEscape(advQuery(1)), " ", "-") & "&"
Case "tags" uri = "http://api.soundcloud.com/tracks?format=streamable&tags=" & advQuery(1) & "&"
Case Else MsgBox "Wrong arguments"
End Select
'~ If InStr("user=group=", advQuery(0)) Then
If InStr("user=group=", advQuery(0)) Then
objXml.load(url & "&client_id=" & cid)
On Error Resume Next
If objXml.selectSingleNode(advQuery(0) & "s/" & advQuery(0) & "[0]/" & name).text = advQuery(1) Then
uid = objXml.selectSingleNode(advQuery(0) & "s/" & advQuery(0) & "[0]/id").text
uri = "http://api.soundcloud.com/" & advQuery(0) & "s/" & uid & "/tracks.xml?"
End If
On Error GoTo 0
End If
End If
End If
End If
If uri <> "" Then
Set objShell = CreateObject("WScript.Shell")
if len(folder) = 0 Then folder = objFSO.GetSpecialFolder(2)
On Error Resume Next
objXml.load(uri & "client_id=" & cid)
If Err.number = 0 Then
On Error Goto 0
Set objTracks = objXml.getElementsByTagName("track")
If objTracks.length > 0 Then
pls = "[Playlist]" & vbCrLf & "NumberOfEntries=" & objTracks.length & vbCrLf
For track = 0 To objTracks.length-1
i = track+1 & "="
If CBool(objTracks.item(track).selectSingleNode("streamable").text) Then
pls = pls & "File" & i & objTracks.item(track).selectSingleNode("stream-url").text & _
"?client_id=" & cid & "&secret_token=" & toc & vbCrLf
pls = pls & "Title" & i & objTracks.item(track).selectSingleNode("title").text & vbCrLf
pls = pls & "Length" & i & "-1" & vbCrLf
End If
Next
With CreateObject("ADODB.Stream")
.Open
.CharSet = "utf-8"
.WriteText pls
plsFile = folder & "\soundcloud.pls"
If objFSO.FileExists(plsFile) Then objFSO.DeleteFile plsFile
If objFSO.FolderExists(folder) Then .SaveToFile plsFile
End With
e = objShell.Run(plsFile)
Else
WScript.Echo "No results!"
End If
Else
WScript.Echo "Error in: " & Err.Source & vbCrLf & Err.Description
End If
ElseIf q <> "" Then
WScript.Echo "The " & advQuery(0) & ": """ & advQuery(1) & """ not found!"
End If
End If
Sub Info(n)
Set objNode = objXml.selectSingleNode("track/" & n)
If Not objNode Is Nothing Then
If objNode.text <> "" Then WScript.Echo " " & Format(objNode.nodeName) & ": " & objNode.text
End If
End Sub
Function Format(k)
Format = Replace(UCase(Left(k,1)) & Right(k, Len(k)-1), "-", " ")
End Function
Function specEscape(s)
specString = Split("\ /")
For Each specChar in specString
s = Replace(s, specChar, "")
Next
specEscape = s
End Function
Function Request(url)
With CreateObject("MSXML2.XMLHTTP")
.open "GET", url, 0
.send ""
Request = .responseBody
End With
End Function
Sub DownloadWaveform(wf_url)
On Error Resume Next
dat = Request(wf_url)
If Err.number = 0 Then
On Error Goto 0
imgFile = folder & "\waveform.png"
If objFSO.Fileexists(imgFile) Then objFSO.DeleteFile imgFile
With CreateObject("ADODB.Stream")
.Type = 1
.Open
.Write dat
If objFSO.FolderExists(folder) Then
.SaveToFile imgFile, 2
Else
.SaveToFile "waveform.png", 2
End If
End With
End If
End Sub
@rornor

This comment has been minimized.

Copy link
Owner Author

commented Dec 28, 2012

Thread: link

Example:

foo_run action:
wscript soundcloud.vbs

Biography View command:
cscript //nologo soundcloud.vbs "%path%"

@S-ed

This comment has been minimized.

Copy link

commented Jul 30, 2016

Just to be clear. This script doesn't work anymore.
Since Soundcloud dropped XML back in 2014, now only JSON supported (VBS has no native JSON support).
Also CID and PID used in script probably deprecated and it is better to make own.

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.