sanırım böyle bi' şey arıyordunuz?
yazılan betiğin yaptığı işlev; YouTube'de arama yapar. Dönen sonucu YouTube embed koduyla oynatır. Video bittiğinde yeniden başlar.
* dipnot; betiği kullanabilmek için Zend_Gdata gereklidir.
* dipnot; kaynak dosyalarını
bu bağlantıdan indirebilirsiniz.
index.php;
<?php
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
require('class.saintx.php');
$SAINTX = new SAINTX;
if($_POST) {
header('Content-Type: application/json; charset=utf-8');
$result = $SAINTX->searchYouTube($_GET['q'], $_GET['p'])->getData();
echo json_encode($result[$_POST['index'] + 1]);
exit;
}
?><!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>.saintx!</title>
<script src="http://yandex.st/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript">
var a = document.createElement("script");
a.src = "//www.youtube.com/iframe_api";
var b = document.getElementsByTagName("script")[0];
b.parentNode.insertBefore(a, b);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('vidyo', {
height: '390',
width: '640',
videoId: $('input[name="videoId"]').val(),
events: {
'onReady': onReady
}
});
}
/*
sanırım istediğin buydu? yes valla ellerine kolların saglık rica ederim. :)
*/
function onReady(l) {
l.target.playVideo();
player.addEventListener('onStateChange', function(e) {
if(e.data == "0") {
l.target.playVideo();
}
});
}
</script>
</head>
<body>
<div class="video-box">
<?php
$result = $SAINTX->searchYouTube($_GET['q'], $_GET['p'])->getData();
echo sprintf('<h1>%s</h1>', $result[0]['title']);
echo sprintf('<input type="hidden" name="videoQuery" value="%s" />', $_GET['q']);
echo sprintf('<input type="hidden" name="videoPage" value="%s" />', $_GET['q']);
echo '<input type="hidden" name="videoIndex" value="0" />';
echo sprintf('<input type="hidden" name="videoId" value="%s" />', $result[0]['video_id']);
?>
</div>
<div id="vidyo"></div>
</body>
</html>class.saintx.php;
<?php
class SAINTX {
const AUTHOR = 'SAINTX';
public $YouTube = null;
public $YouTubeQuery = null;
public $YouTubeFeeds = null;
public $YouTubeFeedsOutput = null;
public function __construct() {
require('Zend/Loader/Autoloader.php');
Zend_Loader_Autoloader::getInstance();
$this->YouTube = new Zend_Gdata_YouTube();
$this->YouTube->setMajorProtocolVersion(2);
}
public function searchYouTube($term='flux pavilion', $pageNumber='1') {
$this->YouTubeQuery = $this->YouTube->newVideoQuery();
$this->YouTubeQuery->setQuery($term);
if($pageNumber == '1')
$this->YouTubeQuery->setStartIndex(1);
else
$this->YouTubeQuery->setStartIndex(($pageNumber * 50));
$this->YouTubeQuery->setMaxResults(50);
$this->YouTubeFeeds = $this->YouTube->getVideoFeed($this->YouTubeQuery);
$this->YouTubeOutputs = array();
foreach($this->YouTubeFeeds as $key => $value) {
$this->YouTubeFeedsOutput[$key]['title'] = $value->getVideoTitle();
$this->YouTubeFeedsOutput[$key]['video_id'] = $value->getVideoId();
$this->YouTubeFeedsOutput[$key]['duration'] = $value->getVideoDuration();
# süreleri hesaplatalım..
$this->YouTubeFeedsOutput[$key]['calculated_duration'] = $this->calculateDuration($value->getVideoDuration());
}
return $this;
}
public function getData() {
return $this->YouTubeFeedsOutput;
}
public function calculateDuration($duration) {
$delimiter = ':';
$seconds = $duration % 60;
$minutes = floor($duration /60);
$hours = floor($seconds_count / 3600);
$seconds = str_pad($seconds, 2, "0", STR_PAD_LEFT);
$minutes = str_pad($minutes, 2, "0", STR_PAD_LEFT) . $delimiter;
if($hours > 0)
$hours = str_pad($hours, 2, "0", STR_PAD_LEFT) . $delimiter;
else
$hours = '';
return sprintf('%s%s%s', $hours, $minutes, $seconds);
}
}
?>