<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>app/views/ytdatasource/search.ctp</filename>
    </added>
    <added>
      <filename>app/views/ytdatasource/view.ctp</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -5,10 +5,10 @@ class YtdatasourceController extends AppController {
 	var $Youtube;
 	
 	
-    function beforeFilter() {
-        App::import('ConnectionManager');
-        $this-&gt;Youtube =&amp; ConnectionManager::getDataSource('youtube');
-    }
+	function beforeFilter() {
+	   App::import('ConnectionManager');
+	   $this-&gt;Youtube =&amp; ConnectionManager::getDataSource('youtube');
+	}
 	
 	function index()
 	{
@@ -16,6 +16,15 @@ class YtdatasourceController extends AppController {
 		$this-&gt;set(&quot;video&quot;, $video);
 	}
 	
+	function search() {
+		$search = $_GET['search'];
+		$results = $this-&gt;Youtube-&gt;search($search);
+		debug($results);
+		$this-&gt;set('totalResults', $results['totalResults']);
+		$this-&gt;set('startIndex', $results['startIndex']);
+		$this-&gt;set('itemsPerPage', $results['itemsPerPage']);
+	}
+	
 	function latest($page=0)
 	{
 		</diff>
      <filename>app/controllers/ytdatasource_controller.php</filename>
    </modified>
    <modified>
      <diff>@@ -2,6 +2,7 @@
 class YoutubeSource extends DataSource{
 	
 	var $Snoopy;
+	var $xml;
 	var $config;
 
     var $description = &quot;Youtube data API&quot;;
@@ -12,12 +13,79 @@ class YoutubeSource extends DataSource{
 		}
 		uses('xml');
         vendor('snoopy/snoopy');
+        $this-&gt;xml = new XML;
         $this-&gt;Snoopy = new Snoopy();
     }
     
+    function search($search, $maxresults=20, $offset=1, $sortby='relevance') {
+	$urlSearch = urlencode($search);
+	$feedUrl = 'http://gdata.youtube.com/feeds/api/videos?vq='.$urlSearch.'&amp;orderby='.$sortby.'&amp;start-index='.$offset.'&amp;max-results='.$maxresults;
+	$this-&gt;Snoopy-&gt;fetch($feedUrl);
+	$result = $this-&gt;Snoopy-&gt;results;
+	$this-&gt;xml-&gt;load($result);
+	//debug($this-&gt;xml-&gt;children[0]-&gt;children[17]);
+	$return = array();
+	$return['title'] = $this-&gt;xml-&gt;children[0]-&gt;children[3]-&gt;value;
+	$return['totalResults'] = $this-&gt;xml-&gt;children[0]-&gt;children[11]-&gt;value;
+	$return['startIndex'] = $this-&gt;xml-&gt;children[0]-&gt;children[12]-&gt;value;
+	$return['itemsPerPage'] = $this-&gt;xml-&gt;children[0]-&gt;children[13]-&gt;value;
+        $entries = array();
+        foreach($this-&gt;xml-&gt;children[0]-&gt;children as $description) {
+                if($description-&gt;name == 'http://www.w3.org/2005/Atom:entry') {
+                        $entry = array();
+                        $entry['categories'] = array();
+                        foreach($description-&gt;children as $attribute) {
+                                switch($attribute-&gt;name) {
+                                        case 'http://www.w3.org/2005/Atom:id':
+                                                $id = str_replace('http://gdata.youtube.com/feeds/api/videos/', '', $attribute-&gt;value);
+                                                $entry['id'] = $id;
+                                                break;
+                                        case 'http://www.w3.org/2005/Atom:published':
+                                                $entry['published'] = $attribute-&gt;value;
+                                                break;
+                                        case 'http://www.w3.org/2005/Atom:updated':
+                                                $entry['updated'] = $attribute-&gt;value;
+                                                break;
+                                        case 'http://www.w3.org/2005/Atom:category':
+                                                $entry['categories'][] = $attribute-&gt;attributes['term'];
+                                                break;
+                                        case 'http://www.w3.org/2005/Atom:title':
+                                                $entry['title'] = $attribute-&gt;value;
+                                                break;
+                                        case 'http://www.w3.org/2005/Atom:content':
+                                                $entry['description'] = $attribute-&gt;value;
+                                                break;
+                                        case 'http://www.w3.org/2005/Atom:author':
+                                                $entry['author'] = $attribute-&gt;children[0]-&gt;value;
+                                                break;
+                                        case 'http://gdata.youtube.com/schemas/2007:statistics':
+                                                $entry['viewCount'] = $attribute-&gt;attributes['viewCount'];
+                                                $entry['favoriteCount'] = $attribute-&gt;attributes['favoriteCount'];
+                                                break;
+                                        case 'http://schemas.google.com/g/2005:rating':
+                                                $entry['averageRating'] = $attribute-&gt;attributes['average'];
+                                                break;
+                                }
+                        }
+                        $entries[] = $entry;
+                }
+        }
+        $return['entries'] = $entries;
+        return $return;
+    }
+    
+    function topRated($time=null)
+    {
+    	# code...
+    }
+    
     function video($videoId) {
     	return new YoutubeVideo($videoId);
     }
+    
+    function user($username) {
+    	return new YoutubeUser($username);
+    }
 }
 
 class YoutubeVideo extends YoutubeSource {
@@ -41,10 +109,9 @@ class YoutubeVideo extends YoutubeSource {
 	}
 	
 	function getDetails() {
-		$xml = new XML;
 		$feedresult = $this-&gt;Snoopy-&gt;fetch($this-&gt;videoFeed);
-		$xml-&gt;load($this-&gt;Snoopy-&gt;results);
-		foreach($xml-&gt;children[0]-&gt;children as $chunk) {
+		$this-&gt;xml-&gt;load($this-&gt;Snoopy-&gt;results);
+		foreach($this-&gt;xml-&gt;children[0]-&gt;children as $chunk) {
 			switch ($chunk-&gt;name) {
 				case 'http://www.w3.org/2005/Atom:published':
 					$this-&gt;published = $chunk-&gt;value;
@@ -75,6 +142,7 @@ class YoutubeVideo extends YoutubeSource {
 					break;
 			}
 		}
+		
 	}
 	function findRelated() {
 		$relatedFeed = 'http://gdata.youtube.com/feeds/api/videos/'.$this-&gt;id.'/related';
@@ -83,4 +151,22 @@ class YoutubeVideo extends YoutubeSource {
 		return $this-&gt;Snoopy-&gt;results;
 	}
 }
+
+class YoutubeUser extends YoutubeSource {
+	
+	
+	var $username;
+	var $userFeed;
+	
+	function __construct($username) {
+		parent::__construct();
+		$this-&gt;username = $username;
+		$this-&gt;userFeed = 'http://gdata.youtube.com/feeds/api/videos/'.$this-&gt;id;
+		$this-&gt;getDetails();
+	}
+	
+	function getDetails() {
+		
+	}
+}
 ?&gt; 
\ No newline at end of file</diff>
      <filename>app/models/datasources/youtube_source.php</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>b90e791c5e52125509a2cd01e0cf81a45ec04660</id>
    </parent>
  </parents>
  <author>
    <name>stuartloxton</name>
    <email>stuart.loxton@googlemail.com</email>
  </author>
  <url>http://github.com/stuartloxton/cakephp-ytdatasource/commit/a5e0d12d7de9ae9ccefd22d1687e41c84d6ca6f9</url>
  <id>a5e0d12d7de9ae9ccefd22d1687e41c84d6ca6f9</id>
  <committed-date>2008-06-01T14:55:27-07:00</committed-date>
  <authored-date>2008-06-01T14:55:27-07:00</authored-date>
  <message>Added video search funtion</message>
  <tree>3724a81e50f18d5029c612b2f856855d147fa936</tree>
  <committer>
    <name>stuartloxton</name>
    <email>stuart.loxton@googlemail.com</email>
  </committer>
</commit>
