Location: PHPKode > scripts > YouTube Video API > youtube.class.php
<?php
class youtube extends google_data
{
	const	FEED				= "http://gdata.youtube.com/feeds/api/videos?q=%s&start-index=%d&max-results=%d&v=2";
	
	public	$query				= false;
	public 	$page_size			= 1;
	public 	$page_index			= 0;
	
	public	$response			= null;
	public	$entry_traverse		= 0;
	
	public	$result_count		= 0;
	public	$videos				= null;

	public function execute($query)
	{
		$this->videos		= array();
		$this->query 		= $query;
		$this->page_index	= 0;
		$this->result_count	= 0;
		$xpath				= $this->read(sprintf(self::FEED, 
				str_replace(" ", "+", $query), 
				($page_index * $this->page_size)+1, 
				$this->page_size));
		
		$this->parse($xpath);
	}

	private function parse($xpath)
	{
		$this->result_count = $this->get_node_value($xpath, "//openSearch:totalResults", null, 0);
		$this->max_pages 	= ($this->result_count / $this->page_size) + 1;
		$entries 			= $xpath->query("//atom:entry");
		if ($entries)
		{
			foreach ($entries as $entry)
			{
				array_push($this->videos, new video($xpath, $entry));
			}
		}
	}
		
	public function next_page()
	{
		if ($this->query)
		{
			if ($this->page_index < $this->max_pages-1)
			{
				$this->page_index++;
				$this->execute_query($this->query, $this->page_index);
			}
		}
	}
	
	public function prev_page()
	{
		if ($this->query)
		{
			if ($this->page_index > 0)
			{
				$this->page_index--;
				$this->execute_query($this->query, $this->page_index);
			}
		}
	}
}
?>
Return current item: YouTube Video API