diff -urN orig-Service/Yahoo/VideoResult.php Service/Yahoo/VideoResult.php --- orig-Service/Yahoo/VideoResult.php Thu Jan 1 01:00:00 1970 +++ Service/Yahoo/VideoResult.php Mon Jul 17 16:38:19 2006 @@ -0,0 +1,99 @@ +_fields = array('Summary', 'RefererUrl', 'FileSize', + 'FileFormat', 'Duration', 'Thumbnail'); + + parent::__construct($result); + $this->setThumbnail(); + } +} + diff -urN orig-Service/Yahoo/VideoResultSet.php Service/Yahoo/VideoResultSet.php --- orig-Service/Yahoo/VideoResultSet.php Thu Jan 1 01:00:00 1970 +++ Service/Yahoo/VideoResultSet.php Mon Jul 17 16:38:19 2006 @@ -0,0 +1,45 @@ +_results->item($this->_currentItem)); + } +} + diff -urN orig-Service/Yahoo.php Service/Yahoo.php --- orig-Service/Yahoo.php Tue Jul 18 10:48:56 2006 +++ Service/Yahoo.php Mon Jul 17 16:40:19 2006 @@ -81,6 +81,16 @@ require_once 'Zend/Service/Yahoo/WebResultSet.php'; /** + * Zend_Service_YahooVideoResult + */ +require_once 'Zend/Service/Yahoo/VideoResult.php'; + +/** + * Zend_Service_YahooVideoResultSet + */ +require_once 'Zend/Service/Yahoo/VideoResultSet.php'; + +/** * Zend_Filter */ require_once 'Zend/Filter.php'; @@ -150,10 +160,6 @@ $this->_validateImageSearch($options); - $this->_rest = new Zend_Service_Rest; - - $this->_rest->setUri('api.search.yahoo.com'); - $response = $this->_rest->restGet('/ImageSearchService/V1/imageSearch', $options); if ($response->isError()) { @@ -207,7 +213,7 @@ $this->_validateLocalSearch($options); - $this->_uri->setHost('api.local.yahoo.com'); + $this->_rest->setUri('http://api.local.yahoo.com'); $response = $this->_rest->restGet('/LocalSearchService/V1/localSearch', $options); @@ -250,8 +256,6 @@ $this->_validateNewsSearch($options); - $this->_uri->setHost('api.search.yahoo.com'); - $response = $this->_rest->restGet('/NewsSearchService/V1/newsSearch', $options); if ($response->isError()) { @@ -299,8 +303,6 @@ $options = $this->_prepareOptions($query, $options, $default_options); $this->_validateWebSearch($options); - $this->_uri->setHost('api.search.yahoo.com'); - $response = $this->_rest->restGet('/WebSearchService/V1/webSearch', $options); if ($response->isError()) { @@ -317,6 +319,51 @@ } /** + * Perform a search of videos. The most basic query consists simply + * of a plain text search, but you can also specify the format. + * + * The specific options are: + * 'type' => (all|any|phrase) How to parse the query terms + * 'results' => int How many results to return, max is 50 + * 'start' => int The start offset for search results + * 'format' => (any|avi|flash|mpeg|msmedia|quicktime|realmedia) The type of videos to search for + * 'adult_ok' => bool Flag to allow 'adult' videos. + * + * @param string $query the query to be run + * @param array $options an optional array of query options. + * @return Zend_Service_Yahoo_VideoResultSet the search results + */ + public function videoSearch($query, $options = NULL) + { + static $default_options = array('type' => 'all', + 'results' => 10, + 'start' => 1, + 'format' => 'any'); + + $options = $this->_prepareOptions($query, $options, $default_options); + + $this->_validateVideoSearch($options); + + $this->_rest = new Zend_Service_Rest; + + $this->_rest->setUri('http://api.search.yahoo.com'); + + $response = $this->_rest->restGet('/VideoSearchService/V1/videoSearch', $options); + + if ($response->isError()) { + throw new Zend_Service_Exception('An error occurred sending request. Status code: ' . + $response->getStatus()); + } + + $dom = new DOMDocument(); + $dom->loadXML($response->getBody()); + + self::_checkErrors($dom); + + return new Zend_Service_Yahoo_VideoResultSet($dom); + } + + /** * Validate Local Search Options * * @param array $options @@ -510,6 +557,59 @@ /** + * Validate Video Search Options + * + * @param array $options + */ + protected function _validateVideoSearch($options) + { + $valid_options = array('appid', 'query', 'type', 'results', 'start', 'format', 'adult_ok'); + if (!is_array($options)) { + return; + } + $this->_compareOptions($options, $valid_options); + + if (isset($options['type'])) { + switch($options['type']) { + case 'all': + case 'any': + case 'phrase': + break; + default: + throw new Zend_Service_Exception("$type is an invalid type."); + } + } + + if (isset($options['results'])) { + if (!Zend_Filter::isBetween($options['results'], 1, 50, true)) { + throw new Zend_Service_Exception($options['results'] . ' is not valid for the "results" option.'); + } + } + + if (isset($options['start'])) { + if (!Zend_Filter::isBetween($options['start'], 1, 1000, true)) { + throw new Zend_Service_Exception($options['start'] . ' is not valid for the "start" option.'); + } + } + + if (isset($options['format'])) { + switch($options['format']) { + case 'any': + case 'avi': + case 'flash': + case 'mpeg': + case 'msmedia': + case 'quicktime': + case 'realsmedia': + break; + default: + throw new Zend_Service_Exception("$format is an invalid type"); + } + } + } + + + /** * Prepare options for sending to Yahoo! * * @param string $query Search Query