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

Blazers: "Cumbia Del Sol"

Aired: 2017-09-22 12:34:23
More...

St. Vincent: "Los Ageless"

Aired: 2017-09-22 12:30:46
More...

Chris Isaak: "Heart Shaped World"

Aired: 2017-09-22 12:23:52
More...

Grizzly Bear: "Mourning Sound"

Aired: 2017-09-22 12:19:24
More...

Gizmodrome (Stewart Copeland: "Summer's Coming"

Aired: 2017-09-22 12:16:00
More...

Surf By Southwest (local): "La Bajada"

Aired: 2017-09-22 12:08:11
More...

Rolling Stones: "Stray Cat Blues"

Aired: 2017-09-22 12:03:39
More...

Allman Brothers Band: "Melissa"

Aired: 2017-09-22 11:59:47
More...

Bill Palmer's TV Killers (lo: "Bears"

Aired: 2017-09-22 11:56:21
More...

John Doe: "The Golden State"

Aired: 2017-09-22 11:53:23
More...

Alvvays: "Dreams Tonite"

Aired: 2017-09-22 11:50:04
More...

Bruce Springsteen: "The Rising"

Aired: 2017-09-22 11:45:22
More...

National: "Day I Die"

Aired: 2017-09-22 11:36:44
More...

Byrds: "Ballad of Easy Rider"

Aired: 2017-09-22 11:34:34
More...

Jim Lauderdale: "I Love You More"

Aired: 2017-09-22 11:30:58
More...

Mr. Probz: "Waves"

Aired: 2017-09-22 11:24:16
More...

Deer Tick: "Jumpstarting"

Aired: 2017-09-22 11:20:40
More...

Jerry Harrison: "Rev It Up"

Aired: 2017-09-22 11:16:34
More...

Pigment: "Wicked Sister"

Aired: 2017-09-22 11:03:41
More...

Jack Johnson: "Better Together"

Aired: 2017-09-22 11:00:19
More...

Lorde: "Perfect Places"

Aired: 2017-09-22 10:56:45
More...

Beachwood Sparks: "Forget The Song"

Aired: 2017-09-22 10:53:09
More...

Peter Bradley Adams: "I'll Forget You"

Aired: 2017-09-22 10:49:29
More...

Joe West (local): "In The Boxcar (Madrid, NM)"

Aired: 2017-09-22 10:45:19
More...

Eilen Jewell: "It's Your Voodoo Working"

Aired: 2017-09-22 10:42:24
More...

War On Drugs: "Holding On"

Aired: 2017-09-22 10:34:32
More...

Beatles: "And I Love Her"

Aired: 2017-09-22 10:32:06
More...

St. Vincent: "New York"

Aired: 2017-09-22 10:29:32
More...

Pains of Being Pure at Heart: "Anymore"

Aired: 2017-09-22 10:23:19
More...

Shins: "Bait and Switch"

Aired: 2017-09-22 10:20:03
More...

Spoon: "Inside Out"

Aired: 2017-09-22 10:16:34
More...

Mad Dukes: "Folk Festival"

Aired: 2017-09-22 09:56:09
More...

Dawes: "When The Tequila Runs Out"

Aired: 2017-09-22 09:52:07
More...

My Morning Jacket: "Big Decisions"

Aired: 2017-09-22 09:48:25
More...

Blind Boys of Alabama: "Pray For Peace"

Aired: 2017-09-22 09:43:50
More...

Ariel Pink: "Feels Like Heaven"

Aired: 2017-09-22 09:40:31
More...

Ziggy Marley: "Dragonfly"

Aired: 2017-09-22 09:36:28
More...

Alvvays: "Dreams Tonite"

Aired: 2017-09-22 09:29:51
More...

Handsome Furs: "Repatriated"

Aired: 2017-09-22 09:25:50
More...

Annie Lennox: "Walking On Broken Glass"

Aired: 2017-09-22 09:21:56
More...

Tori Amos: "Up The Creek"

Aired: 2017-09-22 09:03:17
More...

James: "Laid"

Aired: 2017-09-22 09:00:41
More...

LP: "No Witness"

Aired: 2017-09-22 08:57:09
More...

Lee Harvey Osmond: "Loser Without Your Love"

Aired: 2017-09-22 08:50:18
More...

JD McPherson: "Crying's Just a Thing You D"

Aired: 2017-09-22 08:47:00
More...

Nada Surf: "See These Bones"

Aired: 2017-09-22 08:41:54
More...

Ted Leo: "Can't Go Back"

Aired: 2017-09-22 08:38:35
More...

Sarah Jaffe: "No Worries"

Aired: 2017-09-22 08:35:00
More...

Jakob Dylan: "Truth For a Truth"

Aired: 2017-09-22 08:31:30
More...

Beck: "Up All Night"

Aired: 2017-09-22 08:26:41
More...

Buddy & Julie Miller: "Gasoline and Matches"

Aired: 2017-09-22 08:23:28
More...

Little Steven: "Soulfire"

Aired: 2017-09-22 08:16:48
More...

Knox Hamilton: "Work It Out"

Aired: 2017-09-22 08:13:17
More...

Mynabirds: "Shouting at the Dark"

Aired: 2017-09-22 08:09:08
More...

Mary Chapin Carpenter: "I Feel Lucky"

Aired: 2017-09-22 08:02:31
More...

Bob Marley & The Wailers: "Stir It Up"

Aired: 2017-09-22 07:57:02
More...

Ventures: "Apache"

Aired: 2017-09-22 07:53:50
More...

National: "Day I Die"

Aired: 2017-09-22 07:49:38
More...

Fantastic Negrito: "The Shadows"

Aired: 2017-09-22 07:45:59
More...

Anthony Leon & The Chain (lo: "Brand New Model"

Aired: 2017-09-22 07:43:09
More...

Rickie Lee Jones: "Rebel Rebel"

Aired: 2017-09-22 07:38:43
More...

U2: "You're the Best Thing About"

Aired: 2017-09-22 07:35:02
More...

Scott Fisher: "Jumpin' at Shadows"

Aired: 2017-09-22 07:29:09
More...

John Mellencamp: "Your Life Is Now"

Aired: 2017-09-22 07:25:00
More...

Chelsea Williams: "Lonely Girl"

Aired: 2017-09-22 07:21:27
More...

Givers: "Saw You First"

Aired: 2017-09-22 07:15:00
More...

Leriche: "River Runs"

Aired: 2017-09-22 07:11:39
More...

Van William: "Revolution (feat. First Aid"

Aired: 2017-09-22 07:04:13
More...

Clash: "TRAIN IN VAIN (Album Versio"

Aired: 2017-09-22 07:01:18
More...

Spin Doctors: "Jimmy Olsen's Blues"

Aired: 2017-09-22 06:56:48
More...

Son Volt: "No Expectations"

Aired: 2017-09-22 06:52:15
More...

John Hiatt: "HAVE A LITTLE FAITH IN ME"

Aired: 2017-09-22 06:48:22
More...

Cold War Kids: "So Tied Up"

Aired: 2017-09-22 06:45:15
More...

Jean Beauvoir (boo vee ay): "Rockin' In The Street"

Aired: 2017-09-22 06:37:24
More...

Jack Johnson: "My Mind is for Sale"

Aired: 2017-09-22 06:33:30
More...

Midge Ure: "Dear God"

Aired: 2017-09-22 06:28:24
More...

Joe Fox: "What's the Word"

Aired: 2017-09-22 06:22:18
More...

Madeline Peyroux (B.Holly s: "Changing All Those Changes"

Aired: 2017-09-22 06:19:01
More...

Gizmodrome (Stewert Copela: "I Know Too Much"

Aired: 2017-09-22 06:15:17
More...

Cassandra Wilson: "Red Guitar"

Aired: 2017-09-22 06:07:30
More...

Bruce Springsteen: "Tougher Than The Rest"

Aired: 2017-09-22 06:03:02
More...

Portishead: "Sour Times (Nobody Loves Me"

Aired: 2017-09-22 05:58:46
More...

Portugal The Man: "So Young"

Aired: 2017-09-22 05:54:39
More...

The War on Drugs: "Your Love is Calling My Nam"

Aired: 2017-09-22 05:48:47
More...

KILLERS: "THE MAN"

Aired: 2017-09-22 05:41:30
More...

Prince: "Sign 'O' The Times"

Aired: 2017-09-22 05:36:34
More...

Zoro: "Jabulani"

Aired: 2017-09-22 05:31:01
More...

Jewel: "Who Will Save Your Soul"

Aired: 2017-09-22 05:27:19
More...

Vance Joy: "Lay It On Me"

Aired: 2017-09-22 05:19:41
More...

David Grisman Quintet: "EMD"

Aired: 2017-09-22 05:16:47
More...

Camper Van Beethoven: "Take The Skinheads Bowling"

Aired: 2017-09-22 05:14:21
More...

Jim James (My Morning Jacket: "Turn Your Lights Down Low"

Aired: 2017-09-22 05:05:52
More...

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

Aired: 2017-09-22 05:01:44
More...

Chris Isaak: "BABY DID A BAD BAD THING"

Aired: 2017-09-22 04:58:48
More...

Fleet Foxes: "Naiads, Cassadies"

Aired: 2017-09-22 04:55:25
More...

Pink Floyd: "KEEP TALKING (Album Version"

Aired: 2017-09-22 04:49:23
More...

Foy Vance: "Upbeat Feel Good"

Aired: 2017-09-22 04:46:06
More...

JD Mcpherson: "Lucky Penny"

Aired: 2017-09-22 04:42:30
More...

Robert Cray: "Forecast Calls For Pain"

Aired: 2017-09-22 04:38:41
More...

Dead Can Dance: "Snake and The Moon"

Aired: 2017-09-22 04:32:20
More...

Steve Earle: "Feel Alright"

Aired: 2017-09-22 04:29:11
More...

Thomas Wynn & The Believers: "Wade Waist Deep"

Aired: 2017-09-22 04:25:46
More...

Better Than Ezra: "AT THE STARS"

Aired: 2017-09-22 04:22:00
More...

Peter Murphy: "Indigo Eyes"

Aired: 2017-09-22 04:16:12
More...

Lyle Lovett: "Cryin Shame"

Aired: 2017-09-22 04:13:36
More...

Georgia Satellites: "KEEP YOUR HANDS TO YOURSELF"

Aired: 2017-09-22 04:10:14
More...

Surf Lords (local): "Old Mexico"

Aired: 2017-09-22 04:05:37
More...

David Gray: "Fugitive"

Aired: 2017-09-22 04:01:56
More...

Eddie Vedder: "Longing to Belong"

Aired: 2017-09-22 03:59:15
More...

Warren Zevon: "Knockin' On Heaven's Door"

Aired: 2017-09-22 03:55:15
More...

Ewert & The Two Dragons: "Good Man Down"

Aired: 2017-09-22 03:51:30
More...

Dave Matthews Band: "Jimi Thing"

Aired: 2017-09-22 03:45:44
More...

Bill Palmer's TV Killers (l: "Desire"

Aired: 2017-09-22 03:42:28
More...

Dolly Varden (this is a band: "Saskatchewan to Chicago"

Aired: 2017-09-22 03:38:15
More...

National: "Day I Die"

Aired: 2017-09-22 03:34:00
More...

Bruce Cockburn: "A DREAM LIKE MINE"

Aired: 2017-09-22 03:30:19
More...

Laurie Anderson: "Language is a Virus"

Aired: 2017-09-22 03:25:47
More...

Cure: "Lullaby"

Aired: 2017-09-22 03:21:41
More...

Barr Brothers: "It Came to Me"

Aired: 2017-09-22 03:17:45
More...

Gillian Welch: "Scarlet Town"

Aired: 2017-09-22 03:13:56
More...

Sugar (Bob Mould): "Can't Help You Anymore"

Aired: 2017-09-22 03:10:28
More...

The Republic Tigers: "Buildings and Mountains"

Aired: 2017-09-22 03:05:02
More...

Marc Cohn: "Walking In Memphis"

Aired: 2017-09-22 03:00:51
More...

XTC: "Earn Enough For Us"

Aired: 2017-09-22 02:57:54
More...

Jessica Lea Mayfield: "Sorry is Gone"

Aired: 2017-09-22 02:54:23
More...

Bob Marley & The Wailers: "Could You Be Loved"

Aired: 2017-09-22 02:50:34
More...

Robert Palmer: "Sneakin' Sally Through The"

Aired: 2017-09-22 02:46:13
More...

Dan Auerbach: "Stand By My Girl"

Aired: 2017-09-22 02:42:17
More...

World Party: "Ship Of Fools"

Aired: 2017-09-22 02:37:58
More...

Nathan Moore: "Lost and Found"

Aired: 2017-09-22 02:34:01
More...

Michael Franti & Spearhead: "Life is Better With You"

Aired: 2017-09-22 02:30:36
More...

Washed Out: "Hard To Say Goodbye"

Aired: 2017-09-22 02:26:27
More...

Shawn Colvin: "GET OUT OF THIS HOUSE"

Aired: 2017-09-22 02:22:17
More...

Steve Poltz: "SILVER LINING"

Aired: 2017-09-22 02:18:04
More...

Joe Jackson: "Cha Cha Loco"

Aired: 2017-09-22 02:13:09
More...

Black Box Revelation: "High on a Wire"

Aired: 2017-09-22 02:10:02
More...

Patty Griffin: "Long Ride Home"

Aired: 2017-09-22 02:04:55
More...

Nouvelle Vague: "I Wanna Be Sedated"

Aired: 2017-09-22 02:01:28
More...

The Head & The Heart: "Lost In My Mind"

Aired: 2017-09-22 01:57:08
More...

Soul Asylum: "Runaway Train"

Aired: 2017-09-22 01:52:53
More...

Waterboys: "Still a Freak"

Aired: 2017-09-22 01:48:56
More...

Live: "Selling The Drama"

Aired: 2017-09-22 01:45:31
More...

Robert Plant: "Bones of Saints"

Aired: 2017-09-22 01:42:10
More...

Cocteau Twins: "A Kissed Out Red Floatboat"

Aired: 2017-09-22 01:38:06
More...

War On Drugs: "Holding On"

Aired: 2017-09-22 01:33:49
More...

Bruce Springsteen: "Trapped"

Aired: 2017-09-22 01:28:48
More...

Badly Drawn Boy: "Something To Talk About"

Aired: 2017-09-22 01:25:00
More...

U2: "Stay (Faraway, So Close)"

Aired: 2017-09-22 01:20:02
More...

Mystic Journey (local): "Midnight in Bamako"

Aired: 2017-09-22 01:14:20
More...

David Byrne/Brian Eno: "Life is Long"

Aired: 2017-09-22 01:10:33
More...

Depeche Mode: "Strangelove (3:41 Intro Edi"

Aired: 2017-09-22 01:06:52
More...

Phoenix: "Lasso"

Aired: 2017-09-22 01:04:04
More...

Allman Brothers Band: "Stand Back"

Aired: 2017-09-22 01:00:39
More...

St. Vincent: "Los Ageless"

Aired: 2017-09-22 00:56:56
More...

Dada: "Dizz Knee Land"

Aired: 2017-09-22 00:52:51
More...

Martini Ranch: "Reach"

Aired: 2017-09-22 00:48:27
More...

Fleet Foxes: "On Another Ocean"

Aired: 2017-09-22 00:43:54
More...

Counting Crows: "ROUND HERE"

Aired: 2017-09-22 00:38:43
More...

Rosanne Cash: "Radio Operator"

Aired: 2017-09-22 00:35:12
More...

Brad: "The Day Brings"

Aired: 2017-09-22 00:31:26
More...

JD McPherson: "Undivided Heart & Soul"

Aired: 2017-09-22 00:28:14
More...

Beck: "Tropicalia"

Aired: 2017-09-22 00:24:45
More...

Eden Miner (local artist): "To Fly"

Aired: 2017-09-22 00:19:50
More...

Shawn Mullins: "Lullaby"

Aired: 2017-09-22 00:15:11
More...

Imperial Teen: "Yoo Hoo"

Aired: 2017-09-22 00:11:43
More...

Jam: "Thats Entertainment"

Aired: 2017-09-22 00:06:08
More...

Decemberists: "I4U & U4 Me (Home Demo)"

Aired: 2017-09-22 00:02:35
More...

: ""

Aired: