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

Coldplay: "Yellow"

Aired: 2025-07-05 17:11:24
More...

S. Carey: "More I See"

Aired: 2025-07-05 16:57:15
More...

Mumford Sons: "Caroline"

Aired: 2025-07-05 16:41:16
More...

Adam Duritz (C.Crows): "Carmelita"

Aired: 2025-07-05 16:32:42
More...

Jimmy Eat World: "THE MIDDLE"

Aired: 2025-07-05 16:21:48
More...

Durand Jones the Indications: "Flower Moon"

Aired: 2025-07-05 16:12:10
More...

David Bowie: "Suffragette City"

Aired: 2025-07-05 16:02:08
More...

Foxwarren: "Listen2me"

Aired: 2025-07-05 15:52:37
More...

Faux Paws, the: "Night"

Aired: 2025-07-05 15:42:51
More...

Miya Folick (pron: MEE-yuh FOH-lik): "Felicity"

Aired: 2025-07-05 15:22:51
More...

Jesse Welles: "Horses"

Aired: 2025-07-05 15:12:10
More...

Japanese Breakfast: "Slide Tackle"

Aired: 2025-07-05 15:02:47
More...

Elvis Costello: "Allison"

Aired: 2025-07-05 14:48:46
More...

Chris Isaak: "Wrong To Love You"

Aired: 2025-07-05 14:35:12
More...

Yuno: "Blest"

Aired: 2025-07-05 14:25:34
More...

Deep Sea Diver: "What Do I Know"

Aired: 2025-07-05 14:09:30
More...

Car Seat Headrest: "Hollywood clean"

Aired: 2025-07-05 13:57:39
More...

Flying Lizards: "Money"

Aired: 2025-07-05 13:46:00
More...

Beachwood Sparks: "Sparks Fly Again"

Aired: 2025-07-05 13:35:46
More...

Vandoliers: "Life Behind Bars"

Aired: 2025-07-05 13:23:20
More...

Black Keys, the: "No Rain, No Flowers"

Aired: 2025-07-05 13:12:22
More...

Robert Plant/Alison Krauss: "High and Lonesome"

Aired: 2025-07-05 13:02:05
More...

VAN MORRISON: "SOMEONE LIKE YOU"

Aired: 2025-07-05 12:49:34
More...

Kevin Morby: "This Is a Photograph"

Aired: 2025-07-05 12:28:16
More...

Wet Leg: "Catch These Fists"

Aired: 2025-07-05 12:22:18
More...

Matt Berninger: "Bonnet of Pins"

Aired: 2025-07-05 12:10:44
More...

Wishy: "Fly"

Aired: 2025-07-05 11:51:06
More...

Queen / David Bowie: "Under Pressure"

Aired: 2025-07-05 11:47:14
More...

Trousdale (p: TROOZ-dale): "Growing Pains"

Aired: 2025-07-05 11:40:46
More...

Fixx: "Stand or Fall"

Aired: 2025-07-05 11:36:57
More...

Grace Potter Nocturnals: "Ah Mary"

Aired: 2025-07-05 11:32:19
More...

Allah-Las: "Prazer Em Te Conhecer"

Aired: 2025-07-05 11:29:15
More...

Robert Randolph: "Big Women"

Aired: 2025-07-05 11:22:45
More...

Eliza Gilkyson: "Dark Ages"

Aired: 2025-07-05 11:12:08
More...

Kathleen Edwards: "Save Your Soul"

Aired: 2025-07-05 11:06:08
More...

Parquet Courts: "Watching Strangers Smile"

Aired: 2025-07-05 11:02:44
More...

Gigi Perez: "Sailor Song"

Aired: 2025-07-05 10:51:14
More...

Red Hot Chili Peppers: "By the Way"

Aired: 2025-07-05 10:47:42
More...

David Byrne: "Everybody Laughs (f/Ghost Train Orchestra)"

Aired: 2025-07-05 10:41:53
More...

Ezra Furman: "Forever in Sunset"

Aired: 2025-07-05 10:30:57
More...

Bard the Blackbirds (NM band): "Dance Across the Desert Like Rain"

Aired: 2025-07-05 10:24:16
More...

Eurythmics: "HERE COMES THE RAIN AGAIN"

Aired: 2025-07-05 10:16:03
More...

Cat Ridgeway: "What If?"

Aired: 2025-07-05 10:12:49
More...

Michael Franti Spearhead: "I Got You"

Aired: 2025-07-05 10:06:44
More...

Norah Jones: "What Am I To You?"

Aired: 2025-07-05 10:03:19
More...

Son Volt: "Afterglow 61"

Aired: 2025-07-05 08:58:01
More...

S.G. Goodman: "Fire Sign"

Aired: 2025-07-05 08:47:15
More...

Myles Smith: "Nice to Meet You"

Aired: 2025-07-05 08:35:18
More...

Royel Otis: "Moody"

Aired: 2025-07-05 08:26:39
More...

Margaret Glaspy: "Act Natural"

Aired: 2025-07-05 08:13:26
More...

Elvis Costello: "Everyday I Write The Book"

Aired: 2025-07-05 08:00:29
More...

Bob Dylan: "Shelter From the Storm"

Aired: 2025-07-05 07:48:42
More...

Mumford Sons: "Caroline"

Aired: 2025-07-05 07:22:55
More...

Mt. Joy: "Coyote"

Aired: 2025-07-05 07:10:52
More...

First Aid Kit: "Out of My Head"

Aired: 2025-07-05 07:02:42
More...

JJ Grey Mofro: "Everything Good Is bad"

Aired: 2025-07-05 06:51:04
More...

Soul II Soul: "BACK TO LIFE"

Aired: 2025-07-05 06:42:39
More...

OMD: "Souvenir"

Aired: 2025-07-05 06:31:04
More...

Wood Brothers, the: "Witness"

Aired: 2025-07-05 06:21:51
More...

Specials: "A Message To You Rudy"

Aired: 2025-07-05 06:10:29
More...

Wednesday: "Elderberry Wine"

Aired: 2025-07-05 05:54:26
More...

Beatles: "Lady Madonna (Love)"

Aired: 2025-07-05 05:41:27
More...

Blue Cactus: "This Kind of Rain"

Aired: 2025-07-05 05:30:51
More...

Mr. Probz: "Waves"

Aired: 2025-07-05 05:21:44
More...

Galactic: "Crazyhorse Mongoose"

Aired: 2025-07-05 05:10:24
More...

Lucius: "Next to Normal"

Aired: 2025-07-05 05:01:37
More...

Olivia Wolf: "Cosmic Appalachian Radio"

Aired: 2025-07-05 04:50:00
More...

Max Gomez (local): "Run From You"

Aired: 2025-07-05 04:36:40
More...

Cake: "Sheep Go to Heaven"

Aired: 2025-07-05 04:23:40
More...

Beirut: "The Tern"

Aired: 2025-07-05 04:11:27
More...

HAIM (rhymes w/TIME): "Relationships"

Aired: 2025-07-05 03:58:46
More...

X Ambassadors: "BOOM"

Aired: 2025-07-05 03:44:57
More...

Nanci Griffith: "Listen to the Radio"

Aired: 2025-07-05 03:32:08
More...

Rolling Stones: "Paint It, Black"

Aired: 2025-07-05 03:21:33
More...

Collective Soul: "Shine"

Aired: 2025-07-05 03:08:00
More...

Beth Orton: "She Cries Your Name"

Aired: 2025-07-05 02:55:41
More...

Spoon: "Inside Out"

Aired: 2025-07-05 02:46:57
More...

My Morning Jacket: "Everyday Magic"

Aired: 2025-07-05 02:25:53
More...

Cat Ridgeway: "What If?"

Aired: 2025-07-05 02:17:12
More...

Everclear: "Wonderful"

Aired: 2025-07-05 02:05:31
More...

Daisy the Great: "Ballerina"

Aired: 2025-07-05 01:46:40
More...

Gary Clark Jr.: "This Land (full length edit)"

Aired: 2025-07-05 01:37:32
More...

Clash: "Police on My Back"

Aired: 2025-07-05 01:25:44
More...

Devendra Banhart: "Cripple Crow"

Aired: 2025-07-05 01:16:39
More...

Blackie The Radio Kings: "Stoned"

Aired: 2025-07-05 01:05:59
More...

Bishop Briggs: "River"

Aired: 2025-07-05 00:55:33
More...

Tears For Fears: "EVERYBODY WANTS TO RULE THE WORLD"

Aired: 2025-07-05 00:46:07
More...

Indigenous: "Now That Your Gone"

Aired: 2025-07-05 00:32:22
More...

KT Tunstall: "Black Horse The Cherry Tree"

Aired: 2025-07-05 00:22:28
More...

: ""

Aired: