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...

Mo'Kalamity and the Wizards: "Vision"

Aired: 2018-08-20 08:39:40
More...

Record Company: "Life to Fix"

Aired: 2018-08-20 08:36:24
More...

Delbert McClinton: "Heartbreak Radio"

Aired: 2018-08-20 08:33:09
More...

Ingrid Michaelson: "Everybody"

Aired: 2018-08-20 08:26:02
More...

MGMT: "Me and Michael"

Aired: 2018-08-20 08:22:38
More...

Josh Joplin Group: "I'VE CHANGED"

Aired: 2018-08-20 08:12:27
More...

Steve Winwood: "SPANISH DANCER"

Aired: 2018-08-20 08:08:12
More...

Buddy Guy: "FEELS LIKE RAIN"

Aired: 2018-08-20 08:02:12
More...

Decemberists: "Suckers Prayer"

Aired: 2018-08-20 07:57:37
More...

Old Crow Medicine Show: "Child of the Mississippi"

Aired: 2018-08-20 07:53:57
More...

Ky-Mani Marley: "Soul Shake Down Party"

Aired: 2018-08-20 07:49:07
More...

Los Lobos: "Don't Worry Baby"

Aired: 2018-08-20 07:46:16
More...

Gang of Youths: "The Heart is a Muscle"

Aired: 2018-08-20 07:43:36
More...

Jealous of the Birds: "Plastic Skeletons"

Aired: 2018-08-20 07:35:18
More...

Neil Young: "LONG MAY YOU RUN"

Aired: 2018-08-20 07:31:54
More...

Blackberry Smoke: "Let Me Down Easy"

Aired: 2018-08-20 07:26:40
More...

Annie Lennox: "I Put a Spell On You"

Aired: 2018-08-20 07:19:44
More...

Field Report: "Blind Spot"

Aired: 2018-08-20 07:16:21
More...

Rachael Sage: "Alive"

Aired: 2018-08-20 07:09:15
More...

Rachael Sage: "Alive"

Aired: 2018-08-20 07:08:54
More...

Widespread Panic: "Little Lilly"

Aired: 2018-08-20 07:05:31
More...

Van Morrison: "Baby Please Don't Go"

Aired: 2018-08-20 07:00:43
More...

Revivalists: "All My Friends"

Aired: 2018-08-20 06:57:58
More...

Dada: "DORINA"

Aired: 2018-08-20 06:54:11
More...

Devil Makes 3: "Bad Idea"

Aired: 2018-08-20 06:48:06
More...

John Hiatt: "Slow Turning"

Aired: 2018-08-20 06:41:39
More...

Death Cab For Cutie: "Gold Rush"

Aired: 2018-08-20 06:38:20
More...

Susan Tedeschi: "Don't Think Twice, It's All"

Aired: 2018-08-20 06:34:11
More...

Phosphorescent: "New Birth in New England"

Aired: 2018-08-20 06:25:32
More...

Sheryl Crow: "Summer Song"

Aired: 2018-08-20 06:20:23
More...

Verbs: "Simple Kinda Girl"

Aired: 2018-08-20 06:16:31
More...

Magnetic Fields: "Your Girlfriend's Face"

Aired: 2018-08-20 06:07:50
More...

Concrete Blonde: "CAROLINE"

Aired: 2018-08-20 06:05:40
More...

FFS (Franz Ferdinand + Spark: "Call Girl"

Aired: 2018-08-20 06:00:14
More...

Smiths: "Shoplifters of the World Un"

Aired: 2018-08-20 05:57:01
More...

Mt. Joy: "Jenny Jenkins"

Aired: 2018-08-20 05:54:01
More...

JJ Cale: "Down To Memphis"

Aired: 2018-08-20 05:50:57
More...

David Bowie: "Zeroes"

Aired: 2018-08-20 05:44:20
More...

World Party: "PUT THE MESSAGE IN THE BOX"

Aired: 2018-08-20 05:40:11
More...

Indigenous: "Things We Do"

Aired: 2018-08-20 05:35:47
More...

Police: "EVERY BREATH YOU TAKE"

Aired: 2018-08-20 05:32:06
More...

Moon Taxi: "Good as Gold"

Aired: 2018-08-20 05:25:23
More...

Skatalites: "Eastern Standard Time"

Aired: 2018-08-20 05:21:54
More...

Devo: "Whip It"

Aired: 2018-08-20 05:16:22
More...

Hiss Golden Messenger: "Heart Like a Levee"

Aired: 2018-08-20 05:10:03
More...

Pearl Jam: "Daughter"

Aired: 2018-08-20 05:06:17
More...

Shemekia Copeland: "Ain't Got Time For Hate"

Aired: 2018-08-20 05:02:49
More...

Peter Gabriel: "RED RAIN"

Aired: 2018-08-20 04:58:28
More...

Steve Earle: "The Low Highway"

Aired: 2018-08-20 04:53:00
More...

Dennis Lloyd: "Nevermind"

Aired: 2018-08-20 04:48:38
More...

Bodeans: "GOOD THINGS"

Aired: 2018-08-20 04:46:02
More...

Beth Hart: "Bang Bang Boom Boom"

Aired: 2018-08-20 04:41:50
More...

Blues Brothers: "SWEET HOME CHICAGO"

Aired: 2018-08-20 04:38:04
More...

Blues Traveler: "Accelerated Nation"

Aired: 2018-08-20 04:30:11
More...

U2: "Stay (Faraway, So Close)"

Aired: 2018-08-20 04:27:01
More...

Shawn Colvin: "Viva Las Vegas"

Aired: 2018-08-20 04:22:07
More...

Chris Isaak: "Go Walkin' Down There"

Aired: 2018-08-20 04:17:32
More...

Avalanches: "FRONTIER PSYCHIATRIST (Radi"

Aired: 2018-08-20 04:14:41
More...

JD McPherson: "Under the Spell of City Lig"

Aired: 2018-08-20 04:08:31
More...

George Ezra: "Blame It On Me"

Aired: 2018-08-20 04:05:10
More...

Red Hot Chili Peppers: "Tell Me Baby"

Aired: 2018-08-20 04:01:49
More...

Eliza Gilkyson: "Is It Like Today?"

Aired: 2018-08-20 03:57:47
More...

Suzanne Vega/DNA: "Tom's Diner"

Aired: 2018-08-20 03:52:12
More...

Bird Streets: "Betting on the Sun"

Aired: 2018-08-20 03:48:22
More...

Peter Himmelman: "WOMAN WITH THE STRENGTH OF"

Aired: 2018-08-20 03:44:09
More...

Tom Petty & Heartbreakers: "Keep a Little Soul ('82 out"

Aired: 2018-08-20 03:39:11
More...

Ozomatli: "Love And Hope (remix)"

Aired: 2018-08-20 03:36:18
More...

Beth Orton: "Conceived"

Aired: 2018-08-20 03:31:50
More...

PRETENDERS: "BACK ON THE CHAIN GANG (Sin"

Aired: 2018-08-20 03:28:30
More...

Phantastic Ferniture: "Bad Timing"

Aired: 2018-08-20 03:24:30
More...

Robert Palmer: "Sneakin' Sally Through The"

Aired: 2018-08-20 03:20:32
More...

Gary Moore: "Still Got The Blues"

Aired: 2018-08-20 03:16:08
More...

Arcade Fire: "Keep The Car Running"

Aired: 2018-08-20 03:07:46
More...

Indigo Girls: "Secure Yourself"

Aired: 2018-08-20 03:04:17
More...

B.B. King / Bonnie Raitt: "BABY I LOVE YOU"

Aired: 2018-08-20 03:00:39
More...

Daughn Gibson: "Shatter You Through"

Aired: 2018-08-20 02:56:49
More...

Luluc: "Kids"

Aired: 2018-08-20 02:52:14
More...

Bruce Cockburn: "LOVERS IN A DANGEROUS TIME"

Aired: 2018-08-20 02:47:42
More...

Sarazino: "Es La Vida"

Aired: 2018-08-20 02:43:36
More...

JOE COCKER: "You Can Leave Your Hat On"

Aired: 2018-08-20 02:39:15
More...

Elvis Costello & Attractions: "Unwanted Number"

Aired: 2018-08-20 02:35:06
More...

Talk Talk: "TALK TALK"

Aired: 2018-08-20 02:31:27
More...

Future Islands: "Swept Inside"

Aired: 2018-08-20 02:28:13
More...

Jeff Buckley: "Everybody Here Wants You"

Aired: 2018-08-20 02:23:28
More...

Castlebed: "Silent Flights"

Aired: 2018-08-20 02:18:44
More...

James: "SAY SOMETHING"

Aired: 2018-08-20 02:09:47
More...

Boy & Bear: "Three Headed Woman"

Aired: 2018-08-20 02:06:31
More...

Keb' Mo': "If You Loved Me Like That"

Aired: 2018-08-20 02:02:44
More...

R.E.M.: "Life and How To Live It"

Aired: 2018-08-20 01:59:03
More...

Magnetic Fields: "God Wants Us To Wait"

Aired: 2018-08-20 01:54:58
More...

Depeche Mode: "POLICY OF TRUTH (4:01)"

Aired: 2018-08-20 01:52:51
More...

Florence + The Machine: "Hunger"

Aired: 2018-08-20 01:48:45
More...

Kito Peters: "Troubadour"

Aired: 2018-08-20 01:45:21
More...

Neko Case: "Last Lion of Albion"

Aired: 2018-08-20 01:42:00
More...

Jackson Browne: "FOUNTAIN OF SORROW"

Aired: 2018-08-20 01:38:21
More...

Hundred Year Flood: "Come On"

Aired: 2018-08-20 01:31:39
More...

Neil Young: "THE NEEDLE AND THE DAMAGE D"

Aired: 2018-08-20 01:27:56
More...

Janelle Monae: "Make Me Feel"

Aired: 2018-08-20 01:25:41
More...

Majek Fashek: "Man of Sorrow"

Aired: 2018-08-20 01:22:17
More...

Lionrock: "Scatter and Swing"

Aired: 2018-08-20 01:14:56
More...

Animal Collective: "My Girls"

Aired: 2018-08-20 01:10:22
More...

Joe Jackson: "Look Sharp!"

Aired: 2018-08-20 01:04:46
More...

Death Cab For Cutie: "Gold Rush"

Aired: 2018-08-20 01:01:20
More...

Lyle Lovett: "IF I HAD A BOAT"

Aired: 2018-08-20 00:57:29
More...

Ray Lamontagne: "Such a Simple Thing"

Aired: 2018-08-20 00:54:08
More...

Jet: "Look What You've Done"

Aired: 2018-08-20 00:49:12
More...

Wilco: "Should've Been in Love"

Aired: 2018-08-20 00:45:28
More...

Israel Nash: "Rolling On"

Aired: 2018-08-20 00:41:49
More...

Jimmy Cliff: "The Harder They Come"

Aired: 2018-08-20 00:37:36
More...

Kwame Bedlako: "Steppin' Into Zion"

Aired: 2018-08-20 00:34:26
More...

Santana / Los Lonely Boys: "I Don't Want To Lose Your L"

Aired: 2018-08-20 00:30:32
More...

Reuben & The Dark: "Dreaming"

Aired: 2018-08-20 00:26:44
More...

Nirvana: "Come As You Are"

Aired: 2018-08-20 00:23:30
More...

Bob Schneider: "Tarantula"

Aired: 2018-08-20 00:19:46
More...

Ben Harper: "Get It Like You Like It"

Aired: 2018-08-20 00:15:37
More...

Mocean Worker: "Julius, Irving, berlin"

Aired: 2018-08-20 00:12:46
More...

Rodrigo y Gabriela: "Hanuman"

Aired: 2018-08-20 00:07:22
More...

Junip (Jose Gonzales' new ba: "Always"

Aired: 2018-08-20 00:03:41
More...

: ""

Aired: