Affichage d'une vidéo YouTube

Nouveau WRInaute
Bonjour,

J'ai un site web et je voudrais afficher une vidéo youtube par rapport à une recherche. Je me suis inscrit à YouTube Developper et j'ai acquis une ID mais je n'arrive pas à afficher une seule vidéo, j'obtiens une liste de vidéo avec description : http://www.abandonware-paradise.fr/youtest.php

Voici mon fichier youtest.php :

Code:
<?php

require_once('class.youtube.php');

$yt = new youTube;
$yt->yt_tag("pAIeW-ZFxHk", "football", 10, 1)

?>

Et voici mon class.youtube.php ( de base, celui trouvé sur youtube ) :

Code:
<?php

/*
YouTube API hack up.
Version: 1.0
Author: Sam Napolitano
URL: http://www.napolitopia.com/youtube_videos.php
Last Mod Date: 9/22/06
Notes: I am relatively new to php so you will have to excuse me if it seems that this is a little redundant or undercoded.
This is also the first class I have ever created from scratch, so the concept is still new to me.
This is under a GNU just leave my name in the credits and use/hack/destroy as needed.
*/

class youTube {

function get_feed($feed){

//Open and return Feed with cURL for parsing
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $feed);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$xml = curl_exec($ch);
curl_close($ch);

return $xml;

}

function yt_results($xml, $howmany){

//Match appropriate tags and throw them in an array. I know I don't need to escape the carrots but I was recieving some strange results without it.
preg_match_all("/\<url\>(.+?)\<\/url\>/smi",$xml, $url);
preg_match_all("/\<description\>(.+?)\<\/description\>/smi",$xml, $description);
preg_match_all("/\<video\>(.+?)\<\/video\>/smi",$xml, $video);
preg_match_all("/\<thumbnail_url\>(.+?)\<\/thumbnail_url\>/smi",$xml, $thumb_nail);

//shift return arrays to negate 0 level
array_shift($url);
array_shift($thumb_nail);
array_shift($description);
array_shift($video);

// Replace html characters. More can be added but this seems to work for me across the board.
for($i=0;$i<count($description[0]);$i++){

$description[0][$i] = preg_replace("/</","<",$description[0][$i]);
$description[0][$i] = html_entity_decode($description[0][$i],ENT_QUOTES);

}

// find out how many videos are returned
$total_videos = count($video[0]);

//error checking for how many videos to display

//if more videos are asked for then exist only return how many acutally exist
if($howmany > $total_videos){

$howmany = $total_videos;

}

//if none are asked for default to all
if(!$howmany || $howmany == 0){

$howmany = $total_videos;

}

//video display options
for($i = 0; $i<$howmany; $i++){

print "<p><a href=\"".$url[0][$i]."\" target=\"_blank\"><img src=\"".$thumb_nail[0][$i]."\"></a><br />".$description[0][$i]."</p>";

}
}

function yt_featured($dev_id, $howmany){

//youTube api feed
$feed = "https://www.youtube.com/api2_rest?method=youtube.videos.list_featured&dev_id=$dev_id";

//get the feed as a string data source
$xml = $this->get_feed($feed);

//get results
$this->yt_results($xml, $howmany);

}

function yt_user($dev_id, $user, $howmany){

//youTube api feed
$feed = "https://www.youtube.com/api2_rest?method=youtube.videos.list_by_user&dev_id=$dev_id&user=$user";

//get the feed as a string data source
$xml = $this->get_feed($feed);

//get results
$this->yt_results($xml, $howmany);

}

function yt_tag($dev_id, $tag, $howmany){

//youTube api feed
$feed = "https://www.youtube.com/api2_rest?method=youtube.videos.list_by_tag&dev_id=$dev_id&tag=$tag";

//get the feed as a string data source
$xml = $this->get_feed($feed);

//get results
$this->yt_results($xml, $howmany);


}

}

?>

Comment puis-je faire pour afficher une seule vidéo prête à être visionné et non pas ce listing de vidéo ?

Merci
 
WRInaute occasionnel
tu ne selectionnes que le dernier.
dans l'url tu ne prend que l'id, et tu affiche le visualisateur :)
 
Nouveau WRInaute
Merci pour ta réponse, dsl mais je suis un peu nul j'ai du mal à piger :D

Tu veux dire que je reprend que :

Code:
function yt_tag($dev_id, $tag, $howmany){

//youTube api feed
$feed = "https://www.youtube.com/api2_rest?method=youtube.videos.list_by_tag&dev_id=$dev_id&tag=$tag";

//get the feed as a string data source
$xml = $this->get_feed($feed);

//get results
$this->yt_results($xml, $howmany);


}

Comment reprendre juste l'id ?

$this->yt_results($dev_id); ?

Ensuite je met le visualisateur et j'affiche l'id avec $this ?

Dsl d'être aussi nul :? Je vais essayer cela, j'espere que tu pourra me mettre sur la voie une fois de plus.

Merci
 
WRInaute occasionnel
Essaie:
$yt->yt_tag("pAIeW-ZFxHk", "football", 1, 1)
pour n'en selectionner qu'un.
 
Nouveau WRInaute
Merci grâce à toi j'ai réussi :D

Juste une dernière question :lol: Est il possible de changer la method de recherche, la c'est par tag : method=youtube.videos.list_by_tag
A part par user y'a t'il d'autres methodes ?

Merci
 
Nouveau WRInaute
Oublie ma question, je suis aller voir sur youtube, j'ai vu les différentes méthodes. Me reste a trouver comment obtenir la meilleure recherche possible avec mes titres de jeux :/ En utilisant plusieurs tags peut-être ? Si c'est possible...

Merci en tout cas jv essayer de me dépatouiller maintenant :)
 
Nouveau WRInaute
bonjour
j'ai le meme probleme sur mon site qui est en vbulletin , j'ai ajouter le BBcode qui permet au utilisateur d'ajouter des videos , et ca marche .
mais a la fin il afiche les video similaire de youtube , or que je veux a ficher qu'une video et a la fin , elle revient au debut pour la possibilité de revoir la vidéo rien que cette video .

mon bbcode est le suivant :
////::
table id="Tableau_01" width="600" height="486" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3">
<img src="images/misc/interface-video-embed.gif" width="600" height="40" alt=""></td>
</tr>
<tr>
<td rowspan="2">
<img src="images/misc/interface-video-embed-02.gif" width="40" height="446" alt=""></td>
<td>
<object width="520" height="390"><param name="movie" value="https://www.youtube.com/v/{param}"></param><embed src="https://www.youtube.com/v/{param}" type="application/x-shockwave-flash" width="520" height="390" wmode="transparent"></embed></object></td>
<td rowspan="2">
<img src="images/misc/interface-video-embed-04.gif" width="40" height="446" alt=""></td>
</tr>
<tr>
<td>
<img src="images/misc/interface-video-embed-05.gif" width="520" height="40" alt=""></td>
</tr>
</table>
/////::

comment faire pour resoudre ce probleme????????
merci
 
Discussions similaires
Haut