How To Send Artist and Title Data to TuneIn API

471 Views Asked by At

I am trying to use this script to send artist and title data to TuneIn Radio per their API, where I am getting lost is at this point:

Dim o
Set o = CreateObject("MSXML2.XMLHTTP")
o.open "GET", "http://air.radiotime.com/Playing.ashx?partnerId=<ID>&partnerKey=<key>&id=<station>&title=blank&artist=blank", False
o.send

The problem I run into is with pre-created variables in place as such

Function HandleLine(sLine)
  divisao = (sline)
  divisao = split(divisao,"-")

  SongInfo.Value("artist") = (Trim(divisao(0)))
  SongInfo.Value("title") = (Trim(divisao(1)))
  SongInfo.Value("songtype") = "S"

  SongInfo.DoSongChange
End Function

I want to be able to take these variables and use them in the URL Send string above to send to the API...Does anyone know how to make this possible?

If not, the file is originally read as a text file on a remote PC, and if variables could be created off that I could go there too.

1

There are 1 best solutions below

7
Ansgar Wiechers On

Your question still isn't very clear to me, but assuming that you want to fill the URL parameters title and artist with the values from your SongInfo object you could do the following:

url = "http://air.radiotime.com/Playing.ashx" & _
      "?partnerId=<ID>&partnerKey=<key>&id=<station>" & _
      "&title=" & Replace(SongInfo.Value("title"), " ", "+") & _
      "&artist=" & Replace(SongInfo.Value("artist"), " ", "+")

Set o = CreateObject("MSXML2.XMLHTTP")
o.open "GET", url, False
o.send

Depending on what characters the values for artist and title contain you may need to encode them first:

Function Encode(ByVal str)
  Set re = New RegExp
  re.Pattern = "[^a-zA-Z0-9_.~-]"

  enc = ""
  For i = 1 To Len(str)
    c = Mid(str, i, 1)
    If re.Test(c) Then c = "%" & Right("0" & Hex(Asc(c)), 2)
    enc = enc & c
  Next

  Encode = enc
End Function