0

I have a url and port... mysite.com:8000

When approached by HTTP this returns XML, of which I need to extract and transform <title> under the tree <source mount="/live">

There are other nodes, but the hierachy looks like this

<icestats>
   <source mount="/live">
      <title>Michael Jackson - Beat IT - Thriller</title>
   </source>
</icestats>

I need to extract the value of <title> using Pascal, then explode it using the first hyphen.

So if the XML had value of "Michael Jackson - Beat IT - Thriller" I need to output...

Artist=Michael Jackson song=Beat IT - Thriller

These need to be extracted as variables to be included in a separate part of the script.

I apologize that I haven't got an attempt here already. I'm a station programmer learning to code. If someone could give me a head start I can probably flesh it out.

I am compiling this in PAL, which is based on Pascal/Delphi and is run in SAM Broadcaster.

Ken White
  • 123,280
  • 14
  • 225
  • 444
square_eyes
  • 1,269
  • 3
  • 22
  • 52
  • 1
    Please don't put tag information in your title. The tagging system here is very good at classifying things, and doesn't need help. :-) Please see [Should questions include "tags" in their titles?](http://meta.stackexchange.com/q/19190/172661). Thanks. – Ken White Jun 20 '13 at 10:59
  • 1
    Fair point although I'm not allowed to add SAM or PAL as they aren't predefined tags and I have under 1500 street cred. I guess they are buried in the body though. Hopefully it will draw the right crowd. – square_eyes Jun 20 '13 at 11:03
  • Basically you want to parse icecast/shoutcast output, right? If so, then the output depends on how the server is configured: http://wiert.me/2010/11/22/streaming-your-mp3-collection-through-an-icecast-server-using-ezstream/ – Jeroen Wiert Pluimers Jun 20 '13 at 13:11
  • 1
    Correct. I can configure it. But prefer my script to handle the default Win32 Icecast Stats XML page. I could supply a test Icecast server instance if that helps. – square_eyes Jun 20 '13 at 13:33
  • Please do. I'll try to write some sample code after the weekend. Ping me at skype. I'll publish the results here when they work in Delphi. It should give you a starting point to get PAL under SAM working. – Jeroen Wiert Pluimers Jun 20 '13 at 18:39

2 Answers2

1

I'm not sure what SAM or PAL are, and if they can use all the underlying technologies available from Delphi.

So I'll answer this from a Delphi perspective.

There are two parts of your question:

  1. downloading the XML content over HTTP
  2. translating the XML into Delphi objects

For the second part, use the XML data binding wizard. A nice video demonstrating this is here. It depends on the MSXML DOM. If you don't have that, you will have to find yourself an XML library or do the XML parsing yourself (which can be very tricky).

For the first part, I'd use an Indy TIdHttp component, for instance in the way asked here: How can I download a huge file via TIdHTTP?

If the XML is about interpreting Icecast/Shoutcast song information, then the format highly depends on how the streaming server is configured (see http://wiert.me/2010/11/22/streaming-your-mp3-collection-through-an-icecast-server-using-ezstream/ ).

The cool thing about icecast and shoutcast is that you can stream to it, and the icecast server will determine how the song information is being represented so your actual device providing the stream to the stream server does not have to worry about that (I've been on the streaming side of things).

Community
  • 1
  • 1
Jeroen Wiert Pluimers
  • 23,965
  • 9
  • 74
  • 154
  • 1
    You are right. I'm looking at grabbing Icecast Metadata to use in my script. I might have to parse it myself as PAL is a closed system. As far as I know you can't grab a library. I've been told it can be done (via PAL/Delphi alone). But I don't have the chops to script it. I will check your reference material though. Thanks for that. SAM is SAM Broadcaster, radio station automation software. PAL is Playlist Automation Language. A shell inside of SAM that uses Pascal/Dephi to do just about anything. http://support.spacialaudio.com/wiki/PAL_Quick_Start – square_eyes Jun 20 '13 at 13:42
  • Thanks for the clarification. Is there a trial version of SAM/PAL available? If so, I could try to help you. I should have an icecast VM here somewhere. – Jeroen Wiert Pluimers Jun 20 '13 at 18:37
  • Yes I believe you get 30 days with the trial. Thanks so much for looking at this. – square_eyes Jun 20 '13 at 21:11
0

I was able to solve this quite simply in the end. First I groomed the raw XML output by adding a custom XSLT file to the the server, in this case it is an Icecast server. It's a simple matter of dropping it in the web folder, but you do need access to that.

The below is what I used to extract the three tags I needed. Note it's the full example and not from the simplified one above.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="text"/>
    <xsl:template match="/">
        <xsl:value-of select="/icestats/source[@mount='/live']/title" />
      <xsl:text>
</xsl:text>
      <xsl:value-of select="/icestats/source[@mount='/live']/genre" />
      <xsl:text>
</xsl:text>
        <xsl:value-of select="/icestats/source[@mount='/live']/server_name" />
    </xsl:template>
</xsl:stylesheet>

<!-- Do not change the formatting or spacing in this document. It will affect the output and could break processes down the chain -->

Then I simply used delphi (PAL Script, the delphi based shell in SAM broadcaster) WebtoFile to create a local text file and TStringList to store and parse the text file through to variables as I needed them.

The explode by " - " was achieved by a combination of pos and delete commands.

The full working script contains a lot of error handling and is too big to paste here. That, and discussion (further context) can be found here

square_eyes
  • 1,269
  • 3
  • 22
  • 52