Quantcast
Channel: Video Cloud Overview Recent
Viewing all articles
Browse latest Browse all 2356

Using the Media API to Create an iTunes Feed

$
0
0
0

In this topic you will learn how to use PHP, custom fields and the Video Cloud Media API to create a feed for iTunes.

Before you begin

Using the approach in this sample requires:

  • Your account must be a Video Cloud Pro or Enterprise edition account.
  • You need a Media API Read token with URL access; if you don't already have this token, read about how to get it. For more information, read Accessing Video Content with the Media API.
  • You must have either a Progressive Download account or a Streaming account with universal delivery enabled. Read about setting video delivery options. Due to current restrictions in iTunes, this will only work with content delivered via HTTP.
  • Your videos must use H.264 (MPEG-4) encoding; this will not work with FLVs.
  • You need to create custom video metadata fields in your account and set values for these metadata fields in your videos.

Setting up custom video metadata fields

You need to create custom video metadata fields in your account. Set up the following three fields:

Field Internal NameType
itunesartisttext
itunessizetext
itunestagstext

For information about how to do this, read Setting Up Custom Metadata and Creating Custom Metadata Fields.

Setting up variables for your account

You need to modify some variables in the PHP script with the appropriate values for your account.

Variable NameDescription
$titleThe title of the podcast itself
$linkA link to where the podcast can be found
$descriptionA description of this iTunes Feed
$langThe language you display for this podcast, for example, en-us
$copyrightThe copyright information. For example, "℗ & © 2012 Carl & Brightcove Inc".       
$subtitleA subtitle for the podcast
$authorThe author's name
$summaryA summary for the podcast
$ownernameThe name of the podcast's owner
$owneremailThe email address of the podcast's owner
$imageurlA URL of the thumbnail image for the podcast
$categoryThe podcast's category, for example, "TV & Film"
$explicitA yes or no boolean to indicate if the podcast has explicit content
$tokenYour Media API Read token with FLV access
$playlistidThe ID of the playlist you want to publish

Displaying the Feed

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 );

Sample PHP Script

Here's the PHP script to generate the feed for content in a Progressive Download account:

<?
// Welcome to Carl's sample Video Cloud 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 Video Cloud 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 Video Cloud Studio Home page:
//            1) itunesartist      (text)
//            2) itunessize        (text)
//            3) itunestags        (text)
//
//    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 = "Video Cloud 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 Video Cloud iTunes Test Feed";
// This is a description of this iTunes Feed.
$lang = "en-us";
// This is the language you display for this podcast.
$copyright = "&#x2117; &amp; &#xA9; 2009 Carl &amp; Brightcove Inc";
// This is the copyright information.
$subtitle = "iTunes Test XML FEED via the Video Cloud 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 Video Cloud.";
// 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 &amp; 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>');

?>

Streaming accounts

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.


Viewing all articles
Browse latest Browse all 2356

Trending Articles