Using the BRI RESTful playlist API

Below is some example code to help get you started using the API. There are two files shown below, example.php, and itunes.php. You'll see that the PHP code in example.php interacts with the BRI playlist API, which produces the song title, artist name, date / time stamp, and a URL to query the iTunes API for additional info like cover art, and a link to buy the song on iTunes. While itunes.php interacts with the iTunes API directly.

Just put the files in the same directory (you can rename example.php to anything without changing the code) and make sure that your host allows the http wrapper for "file_get_contents". If this is disabled, you'll have to use another method to call the API, such as cURL or fopen / fread. Brownrice allows http wrapper for file_get_content by default on all our servers.


example.php

<html>
<head>
<style>
.playlist_item{
width:520px;
height:50px;
background:#ececec;
border:1px solid #cecece;
border-radius:3px;
box-shadow:1px 1px 3px #cccccc;
margin:5px;
padding:10px;
font-family: Helvetica, Arial, Sans-Serif;
}
h1{
font-size:18px;
margin:2px;
padding:2px;
}
h2{
font-size:16px;
margin:2px;
padding:2px;
}
span{
font-size:12px;
margin:2px;
padding:2px;
}

</style>
<script src="jquery-1.10.2.js"></script>
</head>
<body>
<?php

/* Call up the API with a station name, and a date stamp. */
$xmldata=file_get_contents("http://live1.brownrice.com/api/kbac/20141224");

/* Use the simplexml_load_string function to parse the XML returned by the API.
   The XML has now been converted to a PHP array. */
$xml=simplexml_load_string($xmldata) or die("Error: Cannot create object");

/* Loop through the array */
foreach ($xml as $item){

    /* Print out some HTML containers... */
    print('<div id="pl_'.$item->id.'" class="playlist_item">');
    /* Loading iTunes data for an entire 24 hour playlist gets pretty slow, but here's one way you can negate that effect.
       Use the jQuery load function to call up iTunes info on click. Send the itunesapiurl to itunes.php encoded in base64 for safety. */
    print('<div style="float:right;"><span style="cursor:pointer;" onclick="$(this.parentNode).load(\'itunes.php?url='.base64_encode($item->itunesapiurl).'\');">More...</span></div>');

    /* Just print the artist, title, and timestamp for the playlist. */
    print('<h1>'.$item->artist.': "'.$item->title.'"</h1>');
    print('<span>Aired: '.$item->starttime.'</span><br>');
    print('</div>');
}

?>
</body>
</html>

itunes.php


<?php

    /* iTunes ONLY exports JSON, they don't do XML. So we'll json_decode the data returned by getting the base64 decoded itunesapiurl passed to this script. */
    $itunesresults=json_decode(file_get_contents(base64_decode($_GET['url'])), true);

    /* Pull specific bits of data from that returned by the iTunes API. */
    $results=$itunesresults['results'];
    $firstresult=$results[0];
    $buynowlink='<a href="'.$firstresult['trackViewUrl'].'" target="iTunes">>>> Buy on iTunes <<<</a>';
    $price=$firstresult['trackPrice'];
    $image=$firstresult['artworkUrl100'];

    print('<img src="'.$image.'" style="height:50px;float:left;margin-right:10px;">');
    print($buynowlink.'<br>$'.$price);

 ?>


Reformatting date / time stamp to a human readable format


$date_time_stamp = strtotime($item->starttime);

$human_readable=date("l, F d g:i A", $date_time_stamp);

echo $human_readable;

This will return something like:

Thursday, January 01 11:57 PM

You can manipulate the first argument to the date() function to change this formatting in a number of ways.
See the links below for more information:

http://php.net/manual/en/function.date.php
http://php.net/manual/en/function.strtotime.php


More...

Noah Kahan w/ Hozier: "Northern Attitude"

Aired: 2026-03-19 18:30:02
More...

Black Keys: "Poor Boy a Long Way from Home"

Aired: 2026-03-19 18:16:06
More...

Tedeschi Trucks Band: "I Got You"

Aired: 2026-03-19 18:05:35
More...

Blessing Jolie: "20teens"

Aired: 2026-03-19 17:55:10
More...

New Pornographers, the: "Votive"

Aired: 2026-03-19 17:43:07
More...

Willie Nelson: "Energy Follows Thought"

Aired: 2026-03-19 17:30:55
More...

Saint Motel: "My Type"

Aired: 2026-03-19 17:17:33
More...

Beths, the: "Metal"

Aired: 2026-03-19 17:01:55
More...

Danny Gatton: "Sky King"

Aired: 2026-03-19 16:55:22
More...

Bonnie Raitt: "Thing Called Love"

Aired: 2026-03-19 16:47:25
More...

Ziggy Marley: "Racism Is a Killa"

Aired: 2026-03-19 16:35:56
More...

Phish: "BOUNCING AROUND THE ROOM"

Aired: 2026-03-19 16:24:50
More...

Everything But the Girl: "Missing"

Aired: 2026-03-19 16:00:58
More...

Father John Misty: "The Old Law"

Aired: 2026-03-19 15:52:50
More...

Mister Kali x BoomRoots: "Guns of Brixton"

Aired: 2026-03-19 15:23:22
More...

BoomRoots (SF band): "Zimma Zam (pron: ZOM)"

Aired: 2026-03-19 15:14:13
More...

Calexico: "Quatro(World Drifts In)"

Aired: 2026-03-19 14:56:09
More...

Pixies: "Catfish Kate"

Aired: 2026-03-19 14:28:06
More...

April March: "Surfing Castafiore"

Aired: 2026-03-19 14:16:55
More...

Noah Kahan (pron: kahn): "the Great Divide"

Aired: 2026-03-19 14:05:19
More...

Low Cut Connie: "Livin in the USA"

Aired: 2026-03-19 13:51:41
More...

Jean Dawson: "Prize Fighter"

Aired: 2026-03-19 13:41:38
More...

Fishbone: "Party at Ground Zero"

Aired: 2026-03-19 13:31:43
More...

Ben Harper: "Burn One Down"

Aired: 2026-03-19 13:18:20
More...

Cranberries: "Dreams"

Aired: 2026-03-19 13:14:03
More...

Marcus King: "The Well"

Aired: 2026-03-19 13:00:18
More...

Kim Gordon: "Not Today"

Aired: 2026-03-19 12:52:11
More...

Beths, the: "Til My Heart Stops"

Aired: 2026-03-19 12:41:52
More...

My Morning Jacket: "Love Love Love"

Aired: 2026-03-19 12:30:20
More...

King Khan The Shrines: "Born to Die"

Aired: 2026-03-19 12:13:28
More...

Paul Simon: "HEARTS AND BONES"

Aired: 2026-03-19 12:02:03
More...

Red Hot Chili Peppers: "Soul to Squeeze"

Aired: 2026-03-19 11:49:38
More...

Aretha Franklin: "Rock Steady"

Aired: 2026-03-19 11:37:41
More...

Joanne Shaw Taylor: "Hell or High Water"

Aired: 2026-03-19 11:23:28
More...

Lettuce: "Rising to the Top"

Aired: 2026-03-19 11:10:31
More...

Mavis Staples: "Worthy"

Aired: 2026-03-19 11:00:29
More...

Lukas Nelson Promise of the Real: "Find Yourself"

Aired: 2026-03-19 10:50:41
More...

Warren Zevon: "WEREWOLVES OF LONDON"

Aired: 2026-03-19 10:38:06
More...

Widowspeak: "the Good Ones"

Aired: 2026-03-19 10:23:03
More...

Jesus and Mary Chain, the: "Sometimes Always (ft. Hope Sandoval)"

Aired: 2026-03-19 10:08:21
More...

Magnetic Fields: "Andrew in Drag"

Aired: 2026-03-19 09:57:39
More...

Breeders: "Wait in the Car"

Aired: 2026-03-19 09:44:47
More...

Local Natives: "When Am I Gonna Lose You"

Aired: 2026-03-19 09:30:50
More...

Say She She: "Cut Rewind"

Aired: 2026-03-19 09:19:14
More...

Arlo Parks: "2SIDED"

Aired: 2026-03-19 08:51:48
More...

Arcade Fire: "The Suburbs"

Aired: 2026-03-19 08:39:59
More...

Alison Brown Steve Martin: "Michael"

Aired: 2026-03-19 08:33:09
More...

Talking Heads: "The Big Country"

Aired: 2026-03-19 08:27:41
More...

Emmylou Harris: "Boulder to Birmingham"

Aired: 2026-03-19 08:24:13
More...

Dandy Warhols: "Bohemian Like You"

Aired: 2026-03-19 08:11:01
More...

R.E.M.: "PRETTY PERSUASION"

Aired: 2026-03-19 07:56:13
More...

Interpol: "No "I" in Threesome"

Aired: 2026-03-19 07:45:10
More...

Devon Gilfillian: "Love You Anyway"

Aired: 2026-03-19 07:37:53
More...

Dylan Leblanc: "Cautionary Tale"

Aired: 2026-03-19 07:27:45
More...

Hataalii (p: hah-toth-lee): "Brown Fool Eyes"

Aired: 2026-03-19 07:10:27
More...

Andy Frasco the U.N.: "You Do You"

Aired: 2026-03-19 07:01:44
More...

Pete Yorn: "Calm Down"

Aired: 2026-03-19 06:33:41
More...

Black Crowes, the: "Pharmacy Chronicles"

Aired: 2026-03-19 06:11:39
More...

Slightly Stoopid: "Top of the World"

Aired: 2026-03-19 05:57:44
More...

Tom Waits: "Hang on St. Christopher"

Aired: 2026-03-19 05:43:01
More...

Pink Floyd: "ON THE TURNING AWAY"

Aired: 2026-03-19 05:32:23
More...

Cigarettes After Sex: "Apocalypse"

Aired: 2026-03-19 05:20:39
More...

Joe Henry: "Civilians"

Aired: 2026-03-19 05:09:05
More...

Ziggy Marley: "Racism Is a Killa"

Aired: 2026-03-19 04:57:48
More...

Felicia Ford: "Hurricane"

Aired: 2026-03-19 04:46:44
More...

Garbage: "Special"

Aired: 2026-03-19 04:36:24
More...

Milky Chance: "Colorado"

Aired: 2026-03-19 04:26:46
More...

Lettuce: "Rising to the Top"

Aired: 2026-03-19 04:17:31
More...

Mark Knopfler: "Sailing To Philadelphia"

Aired: 2026-03-19 04:03:10
More...

Courtney Marie Andrews: "Keeper"

Aired: 2026-03-19 03:51:52
More...

Durand Jones the Indications: "Young Americans"

Aired: 2026-03-19 03:42:07
More...

Fantastic Cat: "Donnie Takes the Bus"

Aired: 2026-03-19 03:32:24
More...

Joe Jackson: "Look Sharp!"

Aired: 2026-03-19 03:19:12
More...

Georgia Satellites: "KEEP YOUR HANDS TO YOURSELF"

Aired: 2026-03-19 03:04:45
More...

Phantastic Ferniture: "Bad Timing"

Aired: 2026-03-19 02:52:50
More...

Counting Crows: "Hanginaround"

Aired: 2026-03-19 02:38:16
More...

Passenger: "Anywhere"

Aired: 2026-03-19 02:23:30
More...

Arlo Parks: "2SIDED"

Aired: 2026-03-19 02:13:15
More...

Cannons: "Starlight"

Aired: 2026-03-19 01:49:04
More...

Kim Gordon: "Not Today"

Aired: 2026-03-19 01:35:18
More...

Foo Fighters: "Shame Shame"

Aired: 2026-03-19 01:25:57
More...

Clover County: "Paradise Rd."

Aired: 2026-03-19 01:15:11
More...

Whiskey Flower: "Stop Stereo"

Aired: 2026-03-19 01:05:05
More...

Eleni Mandell: "Girls"

Aired: 2026-03-19 00:56:43
More...

Black Pumas: "Mrs. Postman"

Aired: 2026-03-19 00:46:03
More...

David Bowie: "Suffragette City"

Aired: 2026-03-19 00:35:37
More...

Beths, the: "Til My Heart Stops"

Aired: 2026-03-19 00:27:55
More...

Strand of Oaks: "Radio Kids"

Aired: 2026-03-19 00:17:10
More...

Glorieta Pines (NM band): "Truck Fump"

Aired: 2026-03-19 00:06:44
More...

: ""

Aired: