-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.movietrailer.php
53 lines (50 loc) · 1.22 KB
/
class.movietrailer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* @package MovieTrailer
* Fetch movie trailer from YouTube
*
* @author Nitesh Apte
* @copyright 2010
* @version 1.0
* @access public
* @License GPL
*/
class MovieTrailer
{
/**
* Private variables for website interaction
*/
private $movieName;
private $movieYear;
private $page;
private $embed;
private $matches;
/**
* __construct()
* Fetch movie trailer from YouTube
*
* @param $movie Movie Name
* @param $year Movie Year
* @return none
*/
public function __construct($movie, $year)
{
$movie = str_replace('&', 'and', $movie);
$this->movieName = str_replace(' ', '+', $movie);
$this->movieYear = $year;
$this->page = file_get_contents('http://www.youtube.com/results?search_query='.$this->movieName.'+'.$this->movieYear.'+trailer&aq=1&hl=en');
if($this->page)
{
if(preg_match('~<a .*?href="/watch\?v=(.*?)".*?</div>~s', $this->page, $this->matches))
{
$this->embed = '<embed src="http://www.youtube.com/v/'.$this->matches[1].'" type="application/x-shockwave-flash" wmode="transparent" allowfullscreen="true" width="446" height="289"></embed>';
echo $this->embed;
}
}
else
{
echo "<b>check internet connection.....</b>";
}
}
}
?>