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

Ryan Adams: "Burning Photographs"

Aired: 2018-11-20 11:35:26
More...

Phantastic Ferniture: "Bad Timing"

Aired: 2018-11-20 11:31:14
More...

Shawn Mullins: "Up All Night"

Aired: 2018-11-20 11:23:19
More...

Keb'Mo w/Rosanne Cash: "Put a Woman in Charge"

Aired: 2018-11-20 11:19:18
More...

Trevor Powers: "Clad in Skin"

Aired: 2018-11-20 11:15:17
More...

Peter Himmelman: "Good Idea"

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

Duncan Sheik: "Barely Breathing"

Aired: 2018-11-20 11:04:44
More...

Lucie Silvas: "Kite"

Aired: 2018-11-20 11:00:26
More...

Elle King: "Shame"

Aired: 2018-11-20 10:57:10
More...

Keane: "Is It Any Wonder?"

Aired: 2018-11-20 10:54:27
More...

Great lake Swimmers: "Alone But Not Alone"

Aired: 2018-11-20 10:51:21
More...

G.Love & Special Sauce: "City Livin'"

Aired: 2018-11-20 10:47:54
More...

Houndmouth: "Golden Age"

Aired: 2018-11-20 10:43:57
More...

XTC: "Green Man"

Aired: 2018-11-20 10:39:54
More...

Wild Nothing: "Letting Go"

Aired: 2018-11-20 10:29:57
More...

Bombay Bicycle Club: "Lights Out, Words Gone"

Aired: 2018-11-20 10:26:22
More...

Jim James: "No Secrets"

Aired: 2018-11-20 10:18:07
More...

St. Vincent: "Teenage Talk"

Aired: 2018-11-20 10:13:28
More...

Sharon Van Etten: "Comeback Kid"

Aired: 2018-11-20 10:06:16
More...

Lucius: "Born Again Teen"

Aired: 2018-11-20 10:03:26
More...

Modest Mouse: "Missed The Boat"

Aired: 2018-11-20 10:00:08
More...

Cake: "Rock and Roll Lifestyle"

Aired: 2018-11-20 09:55:42
More...

Record Company: "Make It Happen"

Aired: 2018-11-20 09:51:20
More...

Maggie Rogers: "Light On"

Aired: 2018-11-20 09:47:44
More...

Bob Dylan: "I Want You"

Aired: 2018-11-20 09:43:49
More...

Ludwig Goransson feat. Baaba: "Wakanda (DJ Dahi Remix)"

Aired: 2018-11-20 09:35:45
More...

Luciano: "Police and Thieves"

Aired: 2018-11-20 09:33:06
More...

Lucinda Williams: "Well Well Well"

Aired: 2018-11-20 09:27:06
More...

Elvis Costello & Attractions: "Unwanted Number"

Aired: 2018-11-20 09:19:05
More...

Jesse Malin: "Lucinda"

Aired: 2018-11-20 09:15:37
More...

William Topley: "BACK TO BELIEVING"

Aired: 2018-11-20 09:00:19
More...

Shawn Colvin: "Whole New You"

Aired: 2018-11-20 08:56:53
More...

Joan Armatrading: "All The Way From America"

Aired: 2018-11-20 08:52:49
More...

Peter Gabriel: "GAMES WITHOUT FRONTIERS"

Aired: 2018-11-20 08:48:09
More...

William Fitzsimmons: "Angela"

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

PRETENDERS: "Mystery Achievement"

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

Leon Bridges: "Coming Home"

Aired: 2018-11-20 08:29:36
More...

Lake Street Dive: "Shame, Shame, Shame"

Aired: 2018-11-20 08:22:29
More...

Wall Of Voodoo: "MEXICAN RADIO"

Aired: 2018-11-20 08:18:21
More...

Death Cab For Cutie: "Northern Lights"

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

Lou Reed: "Busload of Faith"

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

Dire Straits: "ROMEO AND JULIET"

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

Portugal The Man: "Tidal Wave"

Aired: 2018-11-20 07:54:29
More...

Alana Davis: "Crazy"

Aired: 2018-11-20 07:50:53
More...

KT Tunstall: "The River"

Aired: 2018-11-20 07:45:52
More...

Bright Light Social Hour: "Dreamlove"

Aired: 2018-11-20 07:38:33
More...

Morrissey: "Suedehead"

Aired: 2018-11-20 07:33:34
More...

Nick Drake: "River Man"

Aired: 2018-11-20 07:29:54
More...

Brick Hovey: "Soda Pop Girl"

Aired: 2018-11-20 07:20:55
More...

Grip Weeds: "After The Sun Rise"

Aired: 2018-11-20 07:17:07
More...

Paul McCartney: "Caesar Rock"

Aired: 2018-11-20 07:09:06
More...

Blur: "There's No Other Way"

Aired: 2018-11-20 07:05:42
More...

Kevin Gordon / Lucinda Willi: "Down To The Well"

Aired: 2018-11-20 07:02:14
More...

Neko Case: "Last Lion of Albion"

Aired: 2018-11-20 06:58:09
More...

Peter Himmelman: "Save a Little Honey"

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

John Mellencamp: "I'M NOT RUNNING ANYMORE (Al"

Aired: 2018-11-20 06:50:59
More...

Lou Reed: "Sally Can't Dance"

Aired: 2018-11-20 06:43:25
More...

Phantastic Ferniture: "Dark Corner Dance Floor"

Aired: 2018-11-20 06:40:41
More...

St. Vincent: "Digital Witness"

Aired: 2018-11-20 06:37:19
More...

Erin Costello: "All In Your Head"

Aired: 2018-11-20 06:30:12
More...

Oliver Mtukudzi: "Ndakuvara"

Aired: 2018-11-20 06:26:11
More...

Hozier feat. Mavis Staples: "Nina Cried Power"

Aired: 2018-11-20 06:21:21
More...

Carl Broemel: "Rain Check"

Aired: 2018-11-20 06:13:30
More...

Van Morrison / Junior Wells: "Help Me"

Aired: 2018-11-20 06:09:42
More...

Stevie Ray Vaughan: "Dirty Pool"

Aired: 2018-11-20 06:03:15
More...

Kenyatta "Culture" Hill: "Camp Yard"

Aired: 2018-11-20 05:58:22
More...

Adia Victoria: "Dope Queen Blues"

Aired: 2018-11-20 05:54:03
More...

Freddy Jones Band: "IN A DAYDREAM (Intro Edit)"

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

Mary Chapin Carpenter: "I Feel Lucky"

Aired: 2018-11-20 05:42:23
More...

Tom Petty & The Heartbreaker: "Rockin' Around With You"

Aired: 2018-11-20 05:38:41
More...

Pressing Strings: "The Madness"

Aired: 2018-11-20 05:36:17
More...

Natalie Merchant: "Break Your Heart"

Aired: 2018-11-20 05:30:14
More...

Eurythmics: "For The Love of Big Brother"

Aired: 2018-11-20 05:25:36
More...

David Bowie: "Queen Bitch"

Aired: 2018-11-20 05:20:28
More...

Dead Can Dance: "Nierika"

Aired: 2018-11-20 05:17:14
More...

k.d. lang: "Sexuality"

Aired: 2018-11-20 05:07:56
More...

Lumineers: "Ophelia"

Aired: 2018-11-20 05:04:39
More...

Chuck Prophet: "Summertime Thing"

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

Ben Folds 5: "Battle Of Who Could Care Le"

Aired: 2018-11-20 04:56:55
More...

Robbie Robertson: "Skinwalker"

Aired: 2018-11-20 04:53:44
More...

Everlast: "It Ain't Easy"

Aired: 2018-11-20 04:47:50
More...

Tragically Hip: "Poets"

Aired: 2018-11-20 04:44:43
More...

Keb'Mo w/Rosanne Cash: "Put a Woman in Charge"

Aired: 2018-11-20 04:40:35
More...

Modest Mouse: "Dashboard"

Aired: 2018-11-20 04:36:34
More...

Greg Brown: "Joy Tears"

Aired: 2018-11-20 04:32:12
More...

Neil Young: "Out On The Weekend"

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

Villagers: "Fool"

Aired: 2018-11-20 04:22:48
More...

Jerry Harrison: "Rev It Up"

Aired: 2018-11-20 04:19:19
More...

Alex Maryol (local): "Down The Road"

Aired: 2018-11-20 04:15:11
More...

Chrissie Hynde: "Sweet Nuthin'"

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

Everything: "Hooch (4:02)"

Aired: 2018-11-20 04:05:31
More...

Elle King: "Shame"

Aired: 2018-11-20 04:01:33
More...

Sonia Dada: "Planes And Satellites"

Aired: 2018-11-20 03:58:52
More...

Smithereens: "One After 909 (clean edit)"

Aired: 2018-11-20 03:54:48
More...

Phish: "Down With Disease"

Aired: 2018-11-20 03:51:20
More...

Santa Fe All Stars: "Billy in the Lowground"

Aired: 2018-11-20 03:47:17
More...

Death Cab For Cutie: "Near/Far"

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

Thomas Dolby: "I SCARE MYSELF"

Aired: 2018-11-20 03:40:38
More...

Marc Cohn: "Perfect Love"

Aired: 2018-11-20 03:34:56
More...

Trampled By Turtles: "Alone"

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

Toro Y Moi (toro ee mwah): "Freelance"

Aired: 2018-11-20 03:26:11
More...

Santana: "EVERYBODY'S EVERYTHING"

Aired: 2018-11-20 03:22:18
More...

Jason Spooner: "Mirror This Morning"

Aired: 2018-11-20 03:18:51
More...

Bruce Springsteen: "Radio Nowhere"

Aired: 2018-11-20 03:15:11
More...

Fatboy Slim: "Weapon Of Choice (Attack Ha"

Aired: 2018-11-20 03:11:55
More...

Sun-60: "Landslide"

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

Robert Plant: "You Can't Buy My Love"

Aired: 2018-11-20 03:03:37
More...

Primitive Radio Gods: "Blood From a Beating Heart"

Aired: 2018-11-20 03:00:24
More...

Jimi Hendrix: "Rainy Day, Dream Away"

Aired: 2018-11-20 02:57:20
More...

David Crosby: "Other Half Rule"

Aired: 2018-11-20 02:53:32
More...

Diiv: "Under The Sun"

Aired: 2018-11-20 02:49:00
More...

Record Company: "Make It Happen"

Aired: 2018-11-20 02:45:25
More...

Meiko: "Boys With Girlfriends"

Aired: 2018-11-20 02:41:49
More...

Alejandro Escovedo: "Sometimes"

Aired: 2018-11-20 02:37:33
More...

R.E.M.: "Pilgrimage"

Aired: 2018-11-20 02:31:11
More...

Wild Nothing: "Letting Go"

Aired: 2018-11-20 02:26:51
More...

Codetalkers w/Col. Bruce Ham: "Lima"

Aired: 2018-11-20 02:23:06
More...

Tricky: "Evolution Revoltion Love"

Aired: 2018-11-20 02:17:07
More...

Winter Pills: "Open Your Eyes"

Aired: 2018-11-20 02:11:25
More...

Elvis Costello: "ANGELS WANNA WEAR MY RED SH"

Aired: 2018-11-20 02:07:27
More...

Coldplay: "Moses"

Aired: 2018-11-20 02:04:37
More...

Footnotes: "Tormented"

Aired: 2018-11-20 01:59:06
More...

Ozomatli: "(Who Discovered) America?"

Aired: 2018-11-20 01:55:25
More...

Angelique Kidjo & Joss Stone: "Gimmie Shelter"

Aired: 2018-11-20 01:50:53
More...

Echo & The Bunnymen: "The Somnabulist"

Aired: 2018-11-20 01:47:15
More...

Neville Brothers: "Aint No Sunshine"

Aired: 2018-11-20 01:43:59
More...

Lee Rocker: "Gone"

Aired: 2018-11-20 01:40:10
More...

Dave Matthews Band: "Why I Am"

Aired: 2018-11-20 01:36:04
More...

Deer Tick: "Hey! Yeah!"

Aired: 2018-11-20 01:32:19
More...

Joe Jackson: "YOU CAN'T GET WHAT YOU WANT"

Aired: 2018-11-20 01:28:06
More...

Francis Dunnery: "Homegrown"

Aired: 2018-11-20 01:23:10
More...

Snow Patrol: "Take Back The City"

Aired: 2018-11-20 01:18:38
More...

Trance Groove: "Dschang Thang"

Aired: 2018-11-20 01:14:25
More...

Replacements: "Alex Chilton"

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

Kings of Leon: "Reverend"

Aired: 2018-11-20 01:05:32
More...

Ticklah: "Pork Eater (feat. Rob Symeo"

Aired: 2018-11-20 01:01:34
More...

Grace Potter & Nocturnals: "Ah Mary"

Aired: 2018-11-20 00:58:04
More...

Beirut: "Gallipoli"

Aired: 2018-11-20 00:53:20
More...

The Martino Conspiracy: "Moat Around Your Heart"

Aired: 2018-11-20 00:49:18
More...

Paul McCartney: "Caesar Rock"

Aired: 2018-11-20 00:44:34
More...

Gomez: "How We Operate"

Aired: 2018-11-20 00:41:10
More...

Jill Sobule: "I Kissed A Girl"

Aired: 2018-11-20 00:35:39
More...

4 Non Blondes: "What's Up"

Aired: 2018-11-20 00:32:29
More...

Dispatch: "Letter to Lady J"

Aired: 2018-11-20 00:27:37
More...

Thomas Dolby: "Hyperactive"

Aired: 2018-11-20 00:23:20
More...

Richard Ashcroft: "Check The Meaning"

Aired: 2018-11-20 00:19:37
More...

Jessica Lea Mayfield: "Offa My hands"

Aired: 2018-11-20 00:11:46
More...

Beck: "Where It's At"

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

Hozier feat. Mavis Staples: "Nina Cried Power"

Aired: 2018-11-20 00:03:17
More...

: ""

Aired: