Bueno para los que quieren tener su buscador de youtube en su web miren este code :
solo funciona con servidor que soporte php5 lo pueden probar con el appserv
::::::::::::::::::::::Primero creamos el class.youtube.php ::::::::::
<?php
error_reporting(E_ALL);
// for pagination
session_start();
define('API_KEY', 'ARgbYoNTCbs'); // YOUR YOUTUBE DEVELOPERS API KEY
//-------------------------------//
// DO NOT EDIT
//-------------------------------//
/////////////////////
// CONSTANTS //
////////////////////
define('API_URL', 'http://www.youtube.com/');
// CALL GATEWAYS
define('API_REST_CALL', API_URL . 'api2_rest?');
define('API_XMLRPC_CALL', API_URL . 'api2_xmlrpc?');
// METHODS FOR VIDEOS
define('BY_TAG', 'list_by_tag');
// create youtube class
class youtube {
// CLASS PROPERTIES
public
// VARIABLE TO HOLD THE SIMPLE XML ELEMENT WITH RETURNED DATA
$xml,
// HOLDS CONFIG OPTIONS
$config = array(),
// VAR TO STORE THE QUERY STRING FOR YOUTUBE
$api_call,
// RETURNED DATA FROM XML CALL
$return,
$tag,
// IF WE ENCOUNTER ERRORS ALONG OUR JOURNEY
$errors;
// CONSTRUCTION VARIABLES
public function __construct($api_key = API_KEY, $page = 1, $per_page = 25) {
// JUST TO SETUP SOME DEFAULT VALUES FOR A NOMINAL CALL.
// WE WANTED TO MAKE IT EASY TO JUST USE THE CLASS, NOT CONFIGURE IT.
youtube::set('api_key', API_KEY);
youtube::set('page', $page);
youtube::set('per_page', $per_page);
// modify the call
youtube::modify_call(API_REST_CALL . 'method=youtube.');
}
function xml_to_array($xml) {
$fils = 0;
$tab = false;
$array = array();
foreach($xml->children() as $key => $value) {
$child = youtube::xml_to_array($value);
//To deal with the attributes
//foreach ($node->attributes() as $ak => $av) {
// $child[$ak] = (string)$av;
//}
//Let see if the new child is not in the array
if ($tab == false && in_array($key, array_keys($array))) {
//If this element is already in the array we will create an indexed array
$tmp = $array[$key];
$array[$key] = NULL;
$array[$key][] = $tmp;
$array[$key][] = $child;
$tab = true;
} elseif($tab == true) {
//Add an element in an existing array
$array[$key][] = $child;
} else {
//Add a simple element
$array[$key] = $child;
}
$fils++;
}
if($fils==0) {
return (string)$xml;
}
return $array;
}
// SET A CONFIG VARIABLE
public function set($item, $value) {
$this->config[$item] = $value;
}
// ACCESS CONFIG
public function config($item) {
return $this->config[$item];
}
// MODIFY THE CALL CLASS PROPERTY
public function modify_call($params) {
$this->api_call .= $params;
}
// ECHO THE CALL FOR DEBUGGING
public function return_call() {
return $this->api_call;
}
// YOUTUBE VIDEO METHODS
public function videos($data = 'mutemath', $method = BY_TAG) {
//---------------------------------------------//
$this->api_call .= 'videos.'; ///////////////////////
//---------------------------------------------//
switch ($method) {
case BY_TAG:
if (isset($_GET['tag'])) {
$this->tag = '&tag=' . $_GET['tag'];
} else {
$this->tag = '&tag='. $data;
}
youtube::modify_call($method . '&dev_id=' . $this->config['api_key'] . $this->tag);
break;
default:
return 'The WaxJelly YouTube API Class only supports retrieving videos by tag.';
break;
}
// CALL DISPLAY
return youtube::display();
}
public function tags_for_video($tags) {
$tag_links = '';
// explode
$x = explode(' ', $tags);
if (count($x) > 0) {
foreach ($x as $k => $v) {
$tag_links .= "$v ";
}
} else {
$tag_links = "mutemath";
}
return $tag_links;
}
// DISPLAY RESULTS
public function display() {
// CHECK FOR A NEW PAGE & PER PAGE
if (isset($_GET['page'])) {
youtube::set('page', $_GET['page']);
}
if (isset($_GET['per_page'])) {
youtube::set('per_page', $_GET['per_page']);
}
// per page, page, prev, next
// total videos, total pages
youtube::modify_call('&page=' . youtube::config('page') . '&per_page=' . youtube::config('per_page'));
// SEND REQUEST
$this->return = file_get_contents(youtube::return_call());
$this->xml = new SimpleXMLElement($this->return);
$this->xml = youtube::xml_to_array($this->xml);
// CHECK IF THEY'RE ASKING FOR A VIDEO ID
if (isset($_GET['video_id'])) {
define('YOUTUBE_VIDEO_ID', $_GET['video_id']);
// loop through videos to get videos index
foreach ($this->xml['video_list']['video'] as $indx => $array) {
if ($array['id'] == $_GET['video_id']) {
$index = $indx;
echo $index;
break;
} else {
$index = '';
}
}
// define index
define('YOUTUBE_VIDEO_INDEX', $index);
} else {
define('YOUTUBE_VIDEO_ID', $this->xml['video_list']['video'][0]['id']);
define('YOUTUBE_VIDEO_INDEX', 0);
}
//////////////////////////////////////////
// CREATE DISPLAY CONSTANTS //
/////////////////////////////////////////
define('YOUTUBE_PAGE', youtube::config('page'));
define('YOUTUBE_PER_PAGE', youtube::config('per_page'));
$prev = (youtube::config('page') - 1 == 0) ? 1 : youtube::config('page') - 1;
define('YOUTUBE_PREV_PAGE', $prev . $this->tag);
define('YOUTUBE_NEXT_PAGE', youtube::config('page') + 1 . $this->tag);
define('YOUTUBE_TOTAL_VIDEOS', $this->xml['video_list']['total']);
define('YOUTUBE_TOTAL_PAGES', ceil($this->xml['video_list']['total'] / youtube::config('per_page')));
// CONVERT FROM SIMPLEXML OBJECT TO ARRAY
return $this->xml;
}
}
?>
::::::::::::::::::::::::::::::::::::luego el style.css ::::::::::::::::::::::::::::
body {
margin: 0 30px;
background-color: #424C66;
background-image: url(http://www.mycrosyte.com/admin/templates/imgs/filter_gradient.gif);
background-repeat: repeat-x;
font-family: Arial;
font-size: 10pt;
color: #eef;
}
#frame {
background-image: url(http://www.mycrosyte.com/admin/templates/imgs/global_bg.jpg);
background-repeat: repeat-x;
background-color: #2E3546;
margin-right: auto;
margin-left: auto;
width: 900px;
padding: 0px;
text-align: left;
}
#frame div {
padding: 10px;
}
#contentleft {
width: 400px;
float: left;
}
#contentcenter {
width: 450px;
float: left;
}
#contentheader {
height: 50px;
}
#contentheader, #contentfooter {
text-align: right;
background-image: url(http://www.mycrosyte.com/admin/templates/imgs/h4_gradient.gif);
}
#contentfooter {
clear: all;
}
#contentheader h1 {
color: #444;
display: inline;
margin: 0;
padding: 0;
float: left;
}
h2 {
margin: 0;
padding: 0;
display: block;
}
.paginate {
text-align: justify;
}
input {
border: none;
padding: 3px;
color: #333;
border: 1px solid #cccccc;
}
a, a:visited, a:link, a:active {
text-decoration: none;
color: #fc0;
}
::::::::::::::::::::::luego el index.php::::::::::::::::::
<?php
// include the youtube class and instantiate it with the object $yt
include('youtube.class.php');
$yt = new youtube();
// set the amount of results per page, in this case, 19
$yt->set('per_page', 10);
// get videos by a tag (default search string is "mutemath" in this case ,you can change it to whatever you want.
$res = $yt->videos('pamela');
// build the video list array
$video_list = $res['video_list']['video'];
?>
pcxd.com.ar
" >
"><< prev :: page <?=YOUTUBE_PAGE ?> of <?=YOUTUBE_TOTAL_PAGES ?> :: ">next >>
<?php
// loop through each video in the list and display it for design purposes
$i = 0;
foreach ($video_list as $k => $v) {
// limit the title's length so it doesn't break the design
$title = substr($v['title'], 0, 15) . '...';
echo "
{$title}
{$v['length_seconds']}
{$v['rating_avg']} / {$v['rating_count']}
";
$i++;
// only 3 videos per row
if ($i == 2) {
$i = 0;
echo '';
}
}
?>
"><< prev :: page <?=YOUTUBE_PAGE ?> of <?=YOUTUBE_TOTAL_PAGES ?> :: ">next >>
">
" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350">
<?=$video_list[YOUTUBE_VIDEO_INDEX]['description'] ?>
Views: <?=$video_list[YOUTUBE_VIDEO_INDEX]['view_count'] ?>
Comments: <?=$video_list[YOUTUBE_VIDEO_INDEX]['comment_count'] ?>
Tags: <?=$yt->tags_for_video($video_list[YOUTUBE_VIDEO_INDEX]['tags']) ?>
clever
parese que el codigo no se ve bien lo pueden descargar de aqui::::
Buen código Y para los que
Buen código
Y para los que desean usar otro lenguaje de programación recomiendo revise YouTube Developer Area (http://www.youtube.com/dev)
Saludos
- - - - - - - - - - - - - - - - - - - -
CesarS | moderador
backdraft : usabilidad y desarrollo web | trabajoTech.com
Interesante... desconocia la
Interesante... desconocia la existencia de un API de YouTube... a ver que se puede hacer.
Salu2 Erik http://porroa.com/erik
es un muy buen buscador que
es un muy buen buscador que quizas pueda integrar a mi pagina de videos para que la gente pueda seguir con ello