-
-
Save rornor/8d2854646688dbd13036 to your computer and use it in GitHub Desktop.
Use SoundCloud script with your own keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
waveform = False | |
folder = "" | |
cid = "Enter your Client ID code" | |
toc = "Enter your Client Secret code" | |
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") | |
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 | |
.SaveToFile objShell.CurrentDirectory & "\soundcloud.pls", 2 | |
End With | |
e = objShell.Run(Chr(34) & objShell.CurrentDirectory & "\soundcloud.pls""") | |
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) | |
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject") | |
On Error Resume Next | |
dat = Request(wf_url) | |
If Err.number = 0 Then | |
On Error Goto 0 | |
With CreateObject("ADODB.Stream") | |
.Type = 1 | |
.Open | |
.Write dat | |
If folder <> "" And objFSO.FolderExists(folder) Then | |
.SaveToFile folder & "\waveform.png", 2 | |
Else | |
.SaveToFile "waveform.png", 2 | |
End If | |
End With | |
End If | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment