Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5964909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:31:05+00:00 2026-05-22T19:31:05+00:00

I am working with StreamOn, a streaming audio provider to distribute my audio stream

  • 0

I am working with StreamOn, a streaming audio provider to distribute my audio stream for an online radio station. They make current “now playing” song information available on their servers (they provide me with the URL containing this information). Here is the data that is displayed when I go to that URL:

{
  "interval": {
    "id": 0,
    "starts_at": 1306738563270,
"ends_at": 1306738735270
  },
  "identifier": "Music-FS680",
  "category": "music",
  "original_category": "Music",
  "buy_link": "",
  "title": "I'm That Kind of Girl",
  "artist": "Patty Loveless",
  "album": "On Down the Line",
  "publisher": "UMG Recordings, Inc.",
  "itunes_song_id": "1290089",
  "album_art": {
    "src": "http://www.streamon.fm/player/getAlbumArt.php?u=http://a6.mzstatic.com/us/r1000/016/Features/20/41/7b/dj.twfxwryv.170x170-75.jpg",
    "width": 170,
    "height": 170,
    "alt": "On Down the Line",
    "link": ""
  },
  "next_song": "Little Bitty by Alan Jackson",
  "next_buy_link": "",
  "next_album_art": {
    "src": "http://www.streamon.fm/player/getAlbumArt.php?u=http://a5.mzstatic.com/us/r1000/025/Features/b5/cb/0b/dj.frlbluta.170x170-75.jpg",
    "width": 170,
    "height": 170,
    "alt": "Everything I Love",
    "link": ""
  },
  "banner": {
    "src": "",
    "width": 0,
    "height": 0,
    "alt": "",
    "link": ""
  }
}

I need to take that dynamic data, and cleanly display it on my homepage so that it looks like this:

Title:  I'm That Kind of Girl
Artist:  Parry Loveless
Album:  On Down the Line

I know this is text parsing, but I can’t seem to figure out what type of text parsing method I need to use.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:31:06+00:00Added an answer on May 22, 2026 at 7:31 pm

    That’s JSON. Various parsers for different languages are available at http://json.org/

    GoDaddy supports PHP as server-side language. A quick-and-dirty way to get parse the JSON response from an external server. Save the below code with a .php extension (like currently_playing.php):

    <?php
    // retrieve the contents of the URL
    $ch = curl_init('http://wtsh.streamon.fm/card');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $res = curl_exec($ch);
    curl_close($ch);
    // parses the HTTP response and checks if the title exist
    if (($json = json_decode($res)) && $json->title) {
        echo 'Title: '  . htmlspecialchars($json->title ) . '<br>';
        echo 'Artist: ' . htmlspecialchars($json->artist) . '<br>';
        echo 'Album: '  . htmlspecialchars($json->album ) . '<br>';
    } else {
        echo 'No information available, please check again later';
    }
    ?>
    

    Usually, you would do some caching of the result, updating the song information every 10 seconds should be fine.

    It appears that the response contains data on the end time of the song (in milliseconds). A better approach would then be checking if this time has passed, and if so, update the cache.

    <?php // filename: current_song.php
    $json = null;
    $cache = 'song.json';
    // if a cache exists and the time has not passed, use it
    if (file_exists($cache)) {
        $json = json_decode(file_get_contents($cache));
        if ($json->interval && $json->interval->ends_at / 1000 < time()) {
            // expired, discard json
            $json = null;
        }
    }
    // if there is no usuable cache
    if (!$json) {
        // retrieve the contents of the URL
        $ch = curl_init('http://wtsh.streamon.fm/card');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $res = curl_exec($ch);
        curl_close($ch);
        $json = json_decode($res);
        // if the title exists, assume the result to be valid
        if ($json && $json->title) {
            // cache it
            $fp = fopen('song.json', 'w');
            fwrite($fp, $res);
            fclose($fp);
        } else {
            $json = null;
        }
    }
    if ($json) {
        $info = array();
        // contains the time in milliseconds
        $info['wait_ms'] = $json->interval->ends_at - 1000 * microtime(true);
        $info['title']   = $json->title ;
        $info['artist']  = $json->artist;
        $info['album']   = $json->album ;
        $info['image']   = $json->album_art;
        // display a JSON response for the HTML page
        echo json_encode($info);
    }
    ?>
    

    To embed it in a HTML page, use:

    <img id="song_image"><br>
    Title:  <span id="song_title">-</span><br>
    Artist: <span id="song_artist">-</span><br>
    Album:  <span id="song_album">-</span>
    <script>
    (function () {
        // we need a JSON parser, if it does not exist, load it
        if (typeof JSON == "undefined") {
            var s = document.createElement("script");
            // json2.js retrieved from https://github.com/douglascrockford/JSON-js
            s.src = "json2.js";
            document.getElementsByTagName("head").appendChild(s);
        }
    })();
    var song_ends = 0;
    function update_song () {
        if ((new Date).getTime() < song_ends) {
            // use cached result as the song has not ended yet
            return;
        }
        var req = new XMLHttpRequest();
        // IE compatbility:
        var textContent = 'textContent' in document ? 'textContent' : 'innerText';
        req.onreadystatechange = function () {
            if (req.readyState == 4) {
                var song = JSON.parse(req.responseText);
                if (song.title) {
                    var img = document.getElementById("song_image");
                    img.alt = song.image.alt;
                    img.src = song.image.src;
                    img.width = song.image.width;
                    img.height = song.image.height;
                    document.getElementById("song_title")[textContent]  = song.title ;
                    document.getElementById("song_artist")[textContent] = song.artist;
                    document.getElementById("song_album")[textContent]  = song.album ;
                    // store the end date in javascript date format
                    song_ends = (new Date).getTime() + song.wait_ms;
                }
            }
        };
        req.open('get', 'current_song.php', true);
        req.send(null);
    }
    // poll for changes every second
    setInterval(update_song, 1000);
    // and update the song information
    update_song();
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on ffmpeg and trying to add a audio stream on the
Working through the classes section in the O'reilley book and they seem to be
I have a video stream that I used in an iPhone application. I'm now
Working on a bunch of forms at the moment and I'm finding that I
Working on a website that has Employee and Branch entities, using a database table
Working on a rather small, and simple layout, I decided to use Meyer's CSS
Working on an irc client in Adobe AIR in JavaScript, and thinking about logging.
Working with Linq2Sql as a driver for a Wcf Service. Lets go bottom up....
Working on a movie website and would love to find an API that I
Working on a page with multiple sections. at the very top there is a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.