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

Avett Brothers: "No Hard feelings"

Aired: 2018-02-24 16:56:06
More...

Church: "REPTILE"

Aired: 2018-02-24 16:51:26
More...

Olu Dara: "Harlem Country Girl"

Aired: 2018-02-24 16:43:20
More...

Band of Heathens: "Trouble Came Early"

Aired: 2018-02-24 16:37:21
More...

Calexico: "Under the Wheels"

Aired: 2018-02-24 16:33:35
More...

Sarah Vaughan (Adam Freeland: "Fever"

Aired: 2018-02-24 16:26:51
More...

Sonia Dada: "ZACHARY"

Aired: 2018-02-24 16:22:15
More...

War On Drugs: "Pain"

Aired: 2018-02-24 16:18:29
More...

Adele: "Water Under The Bridge"

Aired: 2018-02-24 16:10:59
More...

Aimee Mann: "THAT'S JUST WHAT YOU ARE"

Aired: 2018-02-24 16:07:09
More...

CHVRCHES: "Get Out"

Aired: 2018-02-24 16:02:40
More...

Marc Cohn: "SILVER THUNDERBIRD"

Aired: 2018-02-24 15:58:55
More...

Nathaniel Rateliff & Night S: "Look It Here"

Aired: 2018-02-24 15:54:32
More...

Josh Rouse: "Salton Sea"

Aired: 2018-02-24 15:51:18
More...

Police: "SYNCHRONICITY I"

Aired: 2018-02-24 15:47:26
More...

Cynthia Becker: "Abolitiion"

Aired: 2018-02-24 15:40:28
More...

Weezer: "Happy Hour"

Aired: 2018-02-24 15:36:45
More...

U2: "Love is Bigger Than Anythin"

Aired: 2018-02-24 15:33:40
More...

Peter Gabriel: "DON'T GIVE UP"

Aired: 2018-02-24 15:26:25
More...

Jason Isbell & The 400 Unit: "If We Were Vampires"

Aired: 2018-02-24 15:20:17
More...

Robert Randolph & The Family: "Thrill of It"

Aired: 2018-02-24 15:16:54
More...

Rodney Crowell: "Shake Your Money Maker"

Aired: 2018-02-24 15:10:17
More...

Paul Simon: "Father And Daughter"

Aired: 2018-02-24 15:07:46
More...

Bruce Cockburn: "If A Tree Falls"

Aired: 2018-02-24 15:03:34
More...

Al Di Meola & Paco De Lucia: "Mediteranean Sundance"

Aired: 2018-02-24 14:58:01
More...

Myles Kennedy: "Haunted by Design"

Aired: 2018-02-24 14:52:46
More...

Van Morrison: "Did Ye Get Healed?"

Aired: 2018-02-24 14:49:08
More...

Koko Taylor: "Young Fashioned Ways"

Aired: 2018-02-24 14:41:09
More...

National: "Day I Die"

Aired: 2018-02-24 14:36:20
More...

Moby: "Like a Motherless Child"

Aired: 2018-02-24 14:32:05
More...

Stephen Marley: "Hey Baby"

Aired: 2018-02-24 14:24:46
More...

Ray Lamontagne: "How Long"

Aired: 2018-02-24 14:20:51
More...

James Hunter Six: "I Got Eyes"

Aired: 2018-02-24 14:16:35
More...

Mavericks: "Come Unto Me"

Aired: 2018-02-24 14:10:16
More...

Chris Isaak: "HEART FULL OF SOUL"

Aired: 2018-02-24 14:05:55
More...

Moreland & Arbuckle: "Mount Comfort"

Aired: 2018-02-24 14:02:29
More...

Big Head Todd & Monsters: "Glow"

Aired: 2018-02-24 13:58:20
More...

Fiona Apple: "Criminal"

Aired: 2018-02-24 13:54:07
More...

Israel Nash: "Mariner's Ode"

Aired: 2018-02-24 13:49:30
More...

Ben Harper & The Innocent Cr: "Burn To Shine"

Aired: 2018-02-24 13:40:12
More...

Deep Forest: "Madazulu"

Aired: 2018-02-24 13:33:58
More...

Brett Dennen: "Already Gone"

Aired: 2018-02-24 13:27:06
More...

Morrissey: "We Hate It When R Friends.."

Aired: 2018-02-24 13:21:43
More...

St. Vincent: "Los Ageless"

Aired: 2018-02-24 13:19:03
More...

Paul Turner: "City Lights"

Aired: 2018-02-24 13:15:23
More...

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

Aired: 2018-02-24 13:10:07
More...

Grateful Dead: "Little Red Rooster"

Aired: 2018-02-24 13:06:58
More...

Finn Brothers: "ONLY TALKING SENSE"

Aired: 2018-02-24 13:02:27
More...

Decemberists: "O Valencia"

Aired: 2018-02-24 12:59:21
More...

Fruition: "There She Was"

Aired: 2018-02-24 12:51:55
More...

Brad: "Shinin'"

Aired: 2018-02-24 12:46:23
More...

Page McConnell: "Beauty Of a Broken Heart"

Aired: 2018-02-24 12:39:59
More...

Beck: "Up All Night"

Aired: 2018-02-24 12:36:10
More...

Phoenix: "Ti Amo"

Aired: 2018-02-24 12:33:01
More...

Los Lobos: "The Road to Gila Bend"

Aired: 2018-02-24 12:25:46
More...

Black Crowes: "Thorn In My Pride"

Aired: 2018-02-24 12:21:46
More...

David Byrne: "Everybody's Coming To My Ho"

Aired: 2018-02-24 12:15:39
More...

Wilco: "I Might"

Aired: 2018-02-24 12:08:41
More...

Indigo Girls: "Shame On You"

Aired: 2018-02-24 12:04:43
More...

Bruce Springsteen: "Valentine's Day"

Aired: 2018-02-24 12:01:05
More...

Buddy Guy (w/DTrucks&STedesc: "Too Many Tears"

Aired: 2018-02-24 11:55:56
More...

Squirrel Nut Zippers: "Karnival Joe (From Kokomo)"

Aired: 2018-02-24 11:51:13
More...

Alanis Morissette: "You Oughta Know"

Aired: 2018-02-24 11:47:48
More...

Guggenheim Grotto: "Her Beautiful Ideas"

Aired: 2018-02-24 11:40:57
More...

Nathaniel Rateliff & Nights: "You Worry Me"

Aired: 2018-02-24 11:36:51
More...

Curis Salgado/Alan Hager: "Morning Train"

Aired: 2018-02-24 11:33:09
More...

Jonatha Brooke: "Steady Pull"

Aired: 2018-02-24 11:25:52
More...

Jimmy Hall: "Still Want To Be Your Man"

Aired: 2018-02-24 11:17:23
More...

S. Carey: "More I See"

Aired: 2018-02-24 11:11:05
More...

Chuck Prophet: "Summertime Thing"

Aired: 2018-02-24 11:07:11
More...

Neville Brothers: "Brother Jake"

Aired: 2018-02-24 11:01:25
More...

EastMountainSouth: "You Dance"

Aired: 2018-02-24 10:56:40
More...

Ben Miller Band: "Redwing Blackbird"

Aired: 2018-02-24 10:52:59
More...

Hot Tuna: "Water Song"

Aired: 2018-02-24 10:48:48
More...

Ry Cooder: "3 Cool Cats"

Aired: 2018-02-24 10:39:18
More...

Jack Johnson: "Big Sur"

Aired: 2018-02-24 10:36:14
More...

Becca Mancari: "Long Way Down"

Aired: 2018-02-24 10:33:24
More...

Santana: "Love Devotion & Surrender"

Aired: 2018-02-24 10:27:06
More...

Van Morrison: "Sitting On Top Of The World"

Aired: 2018-02-24 10:23:33
More...

Brandi Carlile: "The Mother"

Aired: 2018-02-24 10:17:25
More...

Radiohead: "Lotus Flower"

Aired: 2018-02-24 10:10:20
More...

Dire Straits: "Single Handed Sailor"

Aired: 2018-02-24 10:05:23
More...

Patti Smith: "Because The Night"

Aired: 2018-02-24 09:00:39
More...

JD McPherson: "Under the Spell of City Lig"

Aired: 2018-02-24 08:57:13
More...

John Doe: "The Meanest Man in the Worl"

Aired: 2018-02-24 08:53:54
More...

Absofacto: "Dissolve"

Aired: 2018-02-24 08:50:07
More...

Jerry Garcia: "Rubin and Cherise"

Aired: 2018-02-24 08:46:29
More...

Decemberists: "Severed"

Aired: 2018-02-24 08:38:51
More...

Bill palmer (local): "Stich"

Aired: 2018-02-24 08:30:55
More...

Train: "Save me, San Francisco"

Aired: 2018-02-24 08:23:00
More...

Hollie Cook: "Stay Alive"

Aired: 2018-02-24 08:18:47
More...

Patty Hurst Shifter: "She's Like a Song"

Aired: 2018-02-24 08:15:09
More...

Jonathan Wilson: "Over The Midnight"

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

Lenny Kravitz: "CAN'T GET YOU OFF MY MIND"

Aired: 2018-02-24 08:04:34
More...

Melody Walker: "Dreaming"

Aired: 2018-02-24 07:59:54
More...

Laura Veirs: "Everybody Needs You"

Aired: 2018-02-24 07:55:06
More...

Javid (jah-veed): "Road to Seville"

Aired: 2018-02-24 07:52:07
More...

Middle Kids: "Mistake"

Aired: 2018-02-24 07:47:35
More...

Allman Brothers Band: "Ain't Wastin' Time No More"

Aired: 2018-02-24 07:40:47
More...

Keller Williams: "Breathe"

Aired: 2018-02-24 07:36:58
More...

Lone Bellow: "May You Be Well"

Aired: 2018-02-24 07:32:57
More...

Neil Young: "Crime In The City"

Aired: 2018-02-24 07:25:30
More...

Band of Heathens: "Trouble Came Early"

Aired: 2018-02-24 07:18:51
More...

Tracey Thorn: "Queen"

Aired: 2018-02-24 07:15:04
More...

Richard X. Heyman: "Kenyon Walls"

Aired: 2018-02-24 07:08:35
More...

Bruce Springsteen: "Devils and Dust"

Aired: 2018-02-24 07:05:17
More...

Modest Mouse: "Dashboard"

Aired: 2018-02-24 07:00:13
More...

Killers: "Run For Cover"

Aired: 2018-02-24 06:56:05
More...

Rickie Lee Jones: "Falling Up"

Aired: 2018-02-24 06:52:33
More...

Janiva Magness: "On and On feat, Rusty Young"

Aired: 2018-02-24 06:48:30
More...

U2 / Green Day: "The Saints Are Coming"

Aired: 2018-02-24 06:44:36
More...

Jason Isbell & The 400 Unit: "If We Were Vampires"

Aired: 2018-02-24 06:38:39
More...

Bonnie Raitt: "Silver Lining"

Aired: 2018-02-24 06:35:04
More...

Field Report: "Never Look Back"

Aired: 2018-02-24 06:28:51
More...

Dave Matthews Band: "If Only"

Aired: 2018-02-24 06:22:56
More...

Imagine Dragons: "Whatever It Takes"

Aired: 2018-02-24 06:18:47
More...

Grant -Lee Phillips: "Walk in Circles"

Aired: 2018-02-24 06:06:54
More...

Jack Johnson: "Better Together"

Aired: 2018-02-24 06:03:22
More...

Soul Asylum: "Black Gold"

Aired: 2018-02-24 05:59:55
More...

Santana / Everlast: "Put Your Lights On (4:10)"

Aired: 2018-02-24 05:55:53
More...

Little Axe: "Same People"

Aired: 2018-02-24 05:51:46
More...

Jessica Lea Mayfield: "Offa My hands"

Aired: 2018-02-24 05:47:54
More...

Mark Bryan: "Drinkin' You Pretty"

Aired: 2018-02-24 05:44:47
More...

Josh Smith: "The Way You Do"

Aired: 2018-02-24 05:41:47
More...

National: "Day I Die"

Aired: 2018-02-24 05:36:13
More...

Big Thief: "Shark Smile"

Aired: 2018-02-24 05:31:58
More...

Dar Williams: "As Cool As I Am"

Aired: 2018-02-24 05:26:01
More...

Delbert McClinton: "Leap Of Faith"

Aired: 2018-02-24 05:22:28
More...

Meshell Ndegeocello: "I Wonder if i Take You Home"

Aired: 2018-02-24 05:19:08
More...

Tame Impala: "Let It Happen"

Aired: 2018-02-24 05:11:20
More...

Coldplay: "Moses"

Aired: 2018-02-24 05:07:25
More...

Wilco: "Dawned On Me"

Aired: 2018-02-24 05:01:59
More...

Bruce Hornsby & The Range: "MANDOLIN RAIN"

Aired: 2018-02-24 04:58:19
More...

Koko Taylor: "Don't Go No Further"

Aired: 2018-02-24 04:53:36
More...

Crowded House: "FALL AT YOUR FEET"

Aired: 2018-02-24 04:49:57
More...

JD McPherson: "Undivided Heart & Soul"

Aired: 2018-02-24 04:46:38
More...

King Sunny Ade: "Synchro-System"

Aired: 2018-02-24 04:43:28
More...

St. Vincent: "Los Ageless"

Aired: 2018-02-24 04:36:56
More...

Tracy Chapman: "Telling Stories"

Aired: 2018-02-24 04:33:21
More...

Little Feat / Lowell George: "New Dehli Freight Train"

Aired: 2018-02-24 04:29:13
More...

Susan Tedeschi: "Alone"

Aired: 2018-02-24 04:25:29
More...

Jacobs Run: "Sleepwalking"

Aired: 2018-02-24 04:21:37
More...

Dolores O'Riordan: "Ordinary Day"

Aired: 2018-02-24 04:17:39
More...

Was (Not Was): "Somewhre in America There's"

Aired: 2018-02-24 04:14:04
More...

Joan Armatrading: "A Woman In Love"

Aired: 2018-02-24 04:10:19
More...

World Party: "PRIVATE REVOLUTION"

Aired: 2018-02-24 04:06:25
More...

The Weight Band: "World Gone Bad"

Aired: 2018-02-24 04:02:20
More...

Mark Knopfler: "Don't You Get It"

Aired: 2018-02-24 03:58:12
More...

Willie Nile: "Back Home"

Aired: 2018-02-24 03:53:02
More...

Bettye LaVette: "What Was It You Wanted"

Aired: 2018-02-24 03:46:40
More...

Bob Dylan: "Rollin' And Tumblin'"

Aired: 2018-02-24 03:41:57
More...

The Weepies: "Hideaway"

Aired: 2018-02-24 03:35:55
More...

Chris Isaak: "LET ME DOWN EASY (Single Re"

Aired: 2018-02-24 03:33:05
More...

Grateful Dead: "SUGAR MAGNOLIA"

Aired: 2018-02-24 03:23:51
More...

Jesse Malin: "Lucinda"

Aired: 2018-02-24 03:20:39
More...

The Iguanas: "Oye Isabel"

Aired: 2018-02-24 03:17:36
More...

Chemical Brothers w/The Flam: "The Golden Path"

Aired: 2018-02-24 03:13:13
More...

The Verve: "Love is Noise"

Aired: 2018-02-24 03:09:10
More...

Dan Auerbach: "Shine on Me"

Aired: 2018-02-24 03:05:08
More...

Kings of Leon: "Reverend"

Aired: 2018-02-24 03:01:50
More...

Hothouse Flowers: "THING OF BEAUTY"

Aired: 2018-02-24 02:58:01
More...

Greg Brown: "Dream City"

Aired: 2018-02-24 02:52:32
More...

Emmylou Harris: "Deeper Well"

Aired: 2018-02-24 02:48:32
More...

Khruangbin (krung-bin): "August 10"

Aired: 2018-02-24 02:44:11
More...

Lemonheads: "Kitchen"

Aired: 2018-02-24 02:39:50
More...

Talking Heads: "The Lady Don't Mind"

Aired: 2018-02-24 02:33:36
More...

Angelique Kidjo (Awn-jo-leek: "Salala"

Aired: 2018-02-24 02:29:26
More...

Green Day: "Boulevard of Broken Dreams"

Aired: 2018-02-24 02:26:06
More...

They Might Be Giants: "I Left My Body"

Aired: 2018-02-24 02:21:38
More...

Roxy Music: "Flesh and Blood"

Aired: 2018-02-24 02:18:47
More...

Grace Jones: "The Apple Stretching"

Aired: 2018-02-24 02:15:49
More...

Supreme Beings Of Leisure: "Never The Same (Radio Edit)"

Aired: 2018-02-24 02:04:43
More...

Lyle Lovett: "Gee Baby,Aint I Good To You"

Aired: 2018-02-24 02:00:59
More...

Ziggy Marley & the Melody Ma: "Beautiful Day"

Aired: 2018-02-24 01:53:06
More...

Damnwells: "Golden Days"

Aired: 2018-02-24 01:49:10
More...

Django Django: "In Your Beat"

Aired: 2018-02-24 01:44:50
More...

Cowboy Junkies: "A COMMON DISASTER"

Aired: 2018-02-24 01:41:26
More...

Jamie Cullum: "GET YOUR WAY"

Aired: 2018-02-24 01:37:52
More...

JJ Cale: "Gypsy Man"

Aired: 2018-02-24 01:33:43
More...

Calexico: "End of the World With You"

Aired: 2018-02-24 01:30:56
More...

David Gray: "The One I Love"

Aired: 2018-02-24 01:27:45
More...

Carbon Leaf: "Life Less Ordinary"

Aired: 2018-02-24 01:24:24
More...

Robert Cray: "PLAYING IN THE DIRT"

Aired: 2018-02-24 01:20:38
More...

The Blue Nile: "Tinseltown in the Rain"

Aired: 2018-02-24 01:17:01
More...

Cantinero: "Astronaut"

Aired: 2018-02-24 01:08:52
More...

Cake: "Sick of You"

Aired: 2018-02-24 01:04:29
More...

Peter Tosh / Mick Jagger: "(You Got To Walk And) DON'T"

Aired: 2018-02-24 01:01:18
More...

Roadkill Ghost Choir: "Beggars Guild"

Aired: 2018-02-24 00:56:02
More...

Bruce Springsteen: "Cadillac Ranch"

Aired: 2018-02-24 00:51:09
More...

S. Carey: "More I See"

Aired: 2018-02-24 00:48:01
More...

Cayucas: "Cayucos"

Aired: 2018-02-24 00:43:59
More...

War On Drugs: "Pain"

Aired: 2018-02-24 00:41:03
More...

Beth Orton: "She Cries Your Name"

Aired: 2018-02-24 00:37:07
More...

Sun Airway: "Black noise"

Aired: 2018-02-24 00:32:33
More...

Shawn Colvin: "Sunny Came Home"

Aired: 2018-02-24 00:28:20
More...

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

Aired: 2018-02-24 00:24:00
More...

Liz Phair: "What Makes You Happy"

Aired: 2018-02-24 00:20:40
More...

Smithereens: "House We Used To Live In"

Aired: 2018-02-24 00:17:05
More...

Van Morrison: "That's Entrainment"

Aired: 2018-02-24 00:10:29
More...

Neil Young: "Four Strong Winds"

Aired: 2018-02-24 00:06:57
More...

Clash: "Armagideon Time"

Aired: 2018-02-24 00:02:46
More...

: ""

Aired: