PHP Classes

PHP Hulu Video: Generate HTML to embed Hulu videos in Web pages

Recommend this page to a friend!
  Info   View files Example   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 154 This week: 1All time: 9,033 This week: 571Up
Version License PHP version Categories
hulu 1.1GNU General Publi...5HTML, PHP 5, Searching, Web services, V...
Description 

Author

This class can generate HTML to embed Hulu videos in Web pages.

It can take a given Hulu video identifier and sends a request to the Hulu site using the oEmbed protocol to retrieve the HTML to embed a player for the specified video in another Web page.

The class can also retrieve information from the Hulu site about the specified video.

It can also download and access Hulu's public sitemap files to search for Hulu public content.

Innovation Award
PHP Programming Innovation award nominee
June 2015
Number 5
Hulu is a popular video site. It does not provide an API but it provides means to generate HTML to embed Hulu videos on other sites.

The class uses the Hulu embed support to extract details from Hulu videos that otherwise could have been provided by a real API.

It can also extract the list of site maps with the URLs of all videos that the site provides, thus helping to build the foundation of a search API for Hulu videos.

Manuel Lemos
Picture of Dave Smith
  Performance   Level  
Name: Dave Smith is available for providing paid consulting. Contact Dave Smith .
Classes: 51 packages by
Country: United States United States
Age: 58
All time rank: 618 in United States United States
Week rank: 20 Up2 in United States United States Up
Innovation award
Innovation award
Nominee: 32x

Winner: 7x

Example

<?PHP
error_reporting
(E_ALL ^ E_NOTICE);

//display the properties containing video information? true or false
$displayProperties = true;

//include video information scraped from hulu's video page? true or false
$includePage = true;

//include video information from hulu's public site maps? true or false
//Warning, only set this to true if the public site maps have been downloaded into the video data folder
//otherwise the script will fail.
$includeHulu = true;

//manage form submission for browser history
if( !empty($_REQUEST['formSubmitted']) ){
   
header('location: example.php?videoID='.$_REQUEST['videoID']);
}

include(
'hulu.class.php');
$hulu = new hulu;

$hulu->videoID = ( empty($_REQUEST['videoID']) ) ? '' : $_REQUEST['videoID'];

if( !empty(
$hulu->videoID) ){
    if( empty(
$hulu->setData($_REQUEST['videoID'],$includePage,$includeHulu)) ){
       
$error = 'There was a problem processing your request, script reported:<br>'.$hulu->error;
    }
}

?>
<html>
    <head>
        <title>Hulu Embed Example</title>
        <style>
            a {
                color: black;
                text-decoration: none;
            }
            a:hover {
                color: red;
            }
        </style>
    </head>
    <body>
        <form method="post">
            <div>
                Video ID: <input type="text" name="videoID" value="<?PHP echo (!empty($_REQUEST['videoID'])) ? $_REQUEST['videoID'] : '';?>"><br>
                <em>(https://www.hulu.com/watch/<span style="color:red;">142476</span>)</em>
            </div>
            <div style="margin-top:10px;"><input type="hidden" name="formSubmitted" value="1"><input type="submit" value="Get Video"> [<a href="example.php">Start Over</a>]</div>
        </form>
<?PHP
if( !empty($error) ){
?>
<div style="margin-top:10px; padding:10px; border: solid thin black; color:red;"><?PHP echo $error;?></div>
<?PHP
}
if( empty(
$error) AND !empty($hulu->videoID) ){
?>
<div><?PHP echo $hulu->embedData['html'];?></div>
<?PHP
if( !empty($hulu->videoData) ){
?>
<div style="margin-top:10px;">
            <?PHP echo ( empty($hulu->videoData['season_number']) ) ? '' : 'Season: '.$hulu->videoData['season_number'].'&nbsp;';?>
<?PHP echo ( empty($hulu->videoData['episode_number']) ) ? '' : 'Episode: '.$hulu->videoData['episode_number'].'&nbsp;';?>
<?PHP echo ( empty($hulu->videoData['original_premiere_date']) ) ? '' : 'Premiered: '.$hulu->showDate($hulu->videoData['original_premiere_date']).'&nbsp;';?>
<?PHP echo $hulu->videoData['title'];?> - Video Rated: <?PHP echo $hulu->videoData['content_rating'];?><?PHP echo ( empty($hulu->videoData['content_rating_reason']) ) ? '' : ' ('.$hulu->videoData['content_rating_reason'].')';?>
</div>
        <div style="margin-top:10px; padding:10px; border: solid thin black;"><?PHP echo $hulu->videoData['description'];?></div>
<?PHP
}
if( !empty(
$hulu->videoData['video_game']) ){
?>
<div style="margin-top:10px;">
            <img src="<?PHP echo $hulu->videoData['video_game']['key_art_url'];?>" alt="<?PHP echo $hulu->videoData['video_game']['title'];?>" width="400"><br>
            Game Rated: <?PHP echo $hulu->videoData['video_game']['rating'];?> - <?PHP echo $hulu->videoData['video_game']['content_descriptor'];?>
</div>
        <div style="margin-top:10px; padding:10px; border: solid thin black;"><?PHP echo $hulu->videoData['video_game']['description'];?></div>
<?PHP
}
?>
<div style="margin-top:10px;">
<?PHP
   
if( !empty($hulu->videoData['poster_url']) ){
?>
<img src="<?PHP echo $hulu->videoData['poster_url'];?>" alt="<?PHP echo $hulu->videoData['title'];?>">
<?PHP
   
}
    if( !empty(
$hulu->videoData['company']['key_art_url']) ){
?>
<img src="<?PHP echo $hulu->videoData['company']['key_art_url'];?>" alt="<?PHP echo $hulu->videoData['company']['name'];?>" width="400">
<?PHP
   
}
?>
</div>
<?PHP
   
if( !empty($displayProperties) ){
?>
<hr>
        embedData[]<br>
        <?PHP var_dump($hulu->embedData);?>
<hr>
        videoData[]<br>
        <?PHP var_dump($hulu->videoData);?>
<hr>
        huluResult[]<br>
        <?PHP var_dump($hulu->huluResult);?>
<?PHP
   
}
}
?>
</body>
</html>


  Files folder image Files  
File Role Description
Files folder imagevideo_data (1 file)
Accessible without login Plain text file example.php Example Example
Accessible without login Plain text file fetch_data.php Example Retrieve Hulu public sitemaps
Plain text file hulu.class.php Class Main Class
Accessible without login Plain text file license.txt Lic. License
Accessible without login Plain text file manual.txt Doc. Documentation
Accessible without login Plain text file search.php Example Search example

  Files folder image Files  /  video_data  
File Role Description
  Accessible without login Plain text file lastid.json Data Public sitemap index file

 Version Control Unique User Downloads Download Rankings  
 0%
Total:154
This week:1
All time:9,033
This week:571Up