Popular Searches:
Uploading, APIs, Creating Players, BEML
This sample uses PHP, custom video metadata, and the Brightcove Media API to create a feed for iTunes.
Using the approach in this sample requires:
You need to create custom video metadata fields in your account. Set up the following three fields:
| Field Name | Type |
|---|---|
| itunesartist | string |
| itunessize | string |
| itunestags | string |
For information about how to do this, read Setting Up Custom Metadata and Creating Custom Metadata Fields.
You need to modify some variables in the PHP script with the appropriate values for your account.
| Variable Name | Description |
|---|---|
| $title | The title of the podcast itself. |
| $link | A link to where the podcast can be found. |
| $description | A description of this iTunes Feed. |
| $lang | The language you display for this podcast. For example, en-us. |
| $copyright | The copyright information. For example, "℗ & © 2009 Carl & Brightcove Inc". |
| $subtitle | A subtitle for the podcast. |
| $author | The author's name. |
| $summary | A summary for the podcast. |
| $ownername | The name of the podcast's owner. |
| $owneremail | The email address of the podcast's owner. |
| $imageurl | A URL of the thumbnail image for the podcast. |
| $category | The podcast's category. For example, "TV & Film". |
| $explicit | A yes or no boolean to indicate if the podcast has explicit content. |
| $token | Your Media API Read token with FLV access. |
| $playlistid | The ID of the playlist you want to publish. |
The PHP script for the feed uses the iTunes podcast DTD and sets your variables. It also uses the Media API find_playlist_by_id method to retrieve the playlist with the ID you set in the script.
This method is for a Progressive Download account:
curl_setopt ($ch, CURLOPT_URL, 'http://api.brightcove.com/services/library
?command=find_playlist_by_id&playlist_id='. $playlistid .'&fields=videos,
id,name,publishedDate,length,shortDescription,longDescription,FLVURL
&custom_fields=itunesartist,itunessize,itunestags&token='. $token );
Here's the PHP script to generate the feed for content in a Progressive Download account:
<?
// Welcome to Carl's sample Brightcove iTunes feed
// Please use this at your own risk.
// This is just a sample to get you started. You can customize further as your requirements
// grow.
// The following is a list of requirements and conditions in order for this podcast feed
// to function properly;
// 1) You must have a Pro or Enterprise level Brightcove Account.
// 2) You will need to contact Brightcove Support to request an API READ Token with FLV
// access, if you don't have one already.
// 3) Due to iTunes current restrictions, you must have a Progressive Download account;
// this will not work with Streaming accounts.
// 4) You must be uploading your content in H.264 with or without transcoding and
// renditions. FLVs will not function with this feed.
// 5) You need to create the following custom fields. They are in your Account Settings:
// Video Fields page on the Brightcove Studio Home page:
// 1) itunesartist (string)
// 2) itunessize (string)
// 3) itunestags (string)
//
// 6) You will have to manually or programmatically set the custom metadata values when you
// upload content.
// 7) You will need to publish this PHP file on a PHP 5 server.
// Please customize the variables below:
$title = "Brightcove Test Feed";
// This is the title of the podcast itself.
$link = "http://www.blacktreeproductions.com/testfeed.php5";
// This is a link to where the podcast can be found.
$description = "Description of the Brightcove iTunes Test Feed";
// This is a description of this iTunes Feed.
$lang = "en-us";
// This is the language you display for this podcast.
$copyright = "℗ & © 2009 Carl & Brightcove Inc";
// This is the copyright information.
$subtitle = "iTunes Test XML FEED via the Brightcove Media APIs";
// This is the subtitle of the podcast.
$author = "Carl Rutman";
// This is the author's name.
$summary = "This is a sample iTunes XML generated from Brightcove.";
// This is the summary for the podcast.
$ownername = "Carl Rutman";
// This is the owner's name.
$owneremail = "Carl.Rutman@example.com";
// This is the owner's email address.
$imageurl = "http://www.blacktreeproductions.com/itunesfeed.jpg";
// This is the podcast thumbnail image url.
$category = "TV & Film";
// This is the podcast category.
$explicit = "no";
// This is a yes or no boolean if the podcast is explicit.
$token = "RZgn8jNSCWktx2gnrBq9y67dtPv58JBeTSZzVwmHhoW-mRlfETQxCQ..";
// This is your Media API READ token with FLV Access.
$playlistid = "28193902001";
// The ID of the playlist you wish to publish.
// Please DO NOT alter the code below;
print('<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">');
print('<channel>');
print('<ttl>60</ttl>');
print('<title>'. $title . '</title>');
print('<link>'. $link . '</link>');
print('<description><![CDATA['. $description . ']]></description>');
print('<language>'. $lang . '</language>');
print('<copyright>'. $copyright . '</copyright>');
print('<itunes:subtitle>'. $subtitle .'</itunes:subtitle>');
print('<itunes:author>'. $author .'</itunes:author>');
print('<itunes:summary>'. $summary .'</itunes:summary>');
print('<itunes:owner>');
print('<itunes:name>'. $ownername .'</itunes:name>');
print('<itunes:email>'. $owneremail .'</itunes:email>');
print('</itunes:owner>');
print('<itunes:image href="'. $imageurl .'" />');
print('<itunes:category text="'. $category .'"></itunes:category>');
print('<itunes:explicit>'. $explicit .'</itunes:explicit>');
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL,
'http://api.brightcove.com/services/library?command=find_playlist_by_id
&playlist_id='. $playlistid .'&fields=videos,id,name,publishedDate,length,
shortDescription,longDescription,FLVURL
&custom_fields=itunesartist,itunessize,itunestags&token='. $token );
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
$returndata = json_decode($file_contents);
foreach($returndata->videos as $items)
{
print('<item>');
print('<title>');
print_r($items->{"name"});
print('</title>');
print('<itunes:author>');
print_r($items->customFields->{"itunesartist"});
print('</itunes:author>');
print('<itunes:subtitle>');
print_r($items->{"shortDescription"});
print('</itunes:subtitle>');
print('<itunes:summary>');
print_r($items->{"longDescription"});
print('</itunes:summary>');
print('<enclosure url="');
$newurl = preg_split("/\?/", $items->{"FLVURL"}, -1, PREG_SPLIT_NO_EMPTY);
print_r($newurl[0]);
print('" length="');
print_r($items->customFields->{"itunessize"});
print('" type="video/mp4" />');
print('<guid>');
print_r($newurl[0]);
print('</guid>');
print('<pubDate>');
print_r(date(DATE_RFC2822,(($items->{"publishedDate"})/1000)));
print('</pubDate>');
print('<itunes:duration>');
print_r(floor(($items->{"length"})/1000));
print('</itunes:duration>');
print('<itunes:keywords>');
print_r($items->customFields->{"itunestags"});
print('</itunes:keywords>');
print('</item>');
}
print('</channel></rss>');
?>
Content can also be accessed via http in a Streaming account if Universal Delivery is enabled. This requires an additional query parameter, media_delivery=http.
The method to display the feed for these accounts would be:
curl_setopt ($ch, CURLOPT_URL, 'http://api.brightcove.com/services/library
?command=find_playlist_by_id&playlist_id='. $playlistid .'&fields=videos,
id,name,publishedDate,length,shortDescription,longDescription,FLVURL
&custom_fields=itunesartist,itunessize,itunestags&media_delivery=http&token='. $token );
?>
In order to generate a feed using the PHP script above, you must be using a token and playlist from your own Streaming account with universal delivery enabled. The token and playlist from the PHP example is from a Progressive Download account.