Kilka postów niżej poprawiona klasa----------------------------------
Klasa łączy sie z youTube.com wchodzi w dany profil i pobiera filmy. Klase napisałem troszkę temu dla kolegi, a dziś robiąc porządki ją znalazłem więc zamieszczam.
<?php
class youTube
{
public $sNick;
public $sUrl = 'http://pl.youtube.com/profile_videos?user=%s';
public $sUrl_ = 'http://pl.youtube.com/profile_videos?user=%s&page=%s';
private $page;
private $sString;
public $aMatches_;
private $bRun=false;
function __construct($sNick)
{
$this->sNick = $sNick;
}
public function connect()
{
{
$sUrl = sprintf($this->sUrl, $this->sNick); } else {
$sUrl = sprintf($this->sUrl_, $this->sNick, $this->page); }
}
public function getVideos()
{
if($this->bRun)
{
return $this->aMatches;
} else {
$this->getVideos_();
return $this->aMatches;
}
}
public function randVideo()
{
$aMatches_ = $this->getVideos();
return $this->aMatches_[$iKey];
}
public function getVideos_()
{
$this->bRun = true;
$this->connect();
preg_match_all("#<!-- end vEntry -->(.*?)<!-- end vEntry -->#is", $this->sString, $aMatches); foreach($aMatches[1] AS $sValue)
{
$aMatches__ = preg_replace('!.*watch?v=(.*?)".*!is', '$1', $sValue); $this->aMatches_[] = '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/'.$aMatches__.'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'.$aMatches__.'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>';
}
$this->page = preg_replace("#.*?<a href=\"/profile_videos?user=".$this->sNick."&p=r&page=([0-9]*?)\" class=\"pagerNotCurrent\">Dalej</a>.*#is", '$1', $this->sString); if((int)$this->page>0)
{
$this->getVideos_();
}
}
}
?>
I jak użyć:
<?php
$yt = new youTube($sNick);
echo $yt->randVideo(); //losuje film print_r($yt->getAllVideos()); //zwraca wszystkie filmy ?>
Ten post edytował bim2 5.01.2008, 22:00:08