hello , i wanna make a small video sharing script , i need to show the videos in my script from youtube and google with the all data (thumbnail, the title and description), so i wrote a code to put the video link in the $url then i limit the video type if its youtube or google to show the video in the script and i succeed on that but i cant output the video thumbnail, the title and description and i dont know how can i do it so if that is my code ---------------------------------------------------------------------------------------------------------------------- <?php $site_type = "1"; /* site_type=1 --> youtube ...... site_type=2 --> google*/ $url = "http://www.youtube.com/watch?v=9IOpuGVoyCk"; /*put here the video link*/ $parts = explode("=", $url); $video_id = $parts[1]; if ($site_type == '1') { ?> <object type="application/x-shockwave-flash" width="444" height="333" data="http://www.youtube.com/v/<?php echo $video_id; ?>"><param name="movie"/></object> <?php } elseif ($site_type == '2') { ?> <object type="application/x-shockwave-flash" width="444" height="333" data="http://video.google.com/googleplayer.swf?docId=<?php echo $video_id; ? >&hl=en&stop=true&playerMode=simple"><param name="movie"/></object> <?php } ?> --------------------------------------------------------------------------------------------------------------------------------- if u opened it on your browser it will show the video only without the other needed data, just some body help me to add function or code in it to show the thumbnail, the title and description under the video , resend me the code back after the editing on it and i will be thankful for that thanks
You should use the API for youtube.. For search the feed url is something like http://gdata.youtube.com/feeds/api/videos?q=your+search (replace your+search with your search terms) each entry gives you the url of videos, thumbnails, title & description, etc.. also there is no need for replacing watch?v= with /v/ using the API... Look into the simplexml functions which come with php 5+ to parse the xml hope it helps
well , first i wanna say thanks for that fast reply but i still dont understand if i have in the beginning of the php code video ur like that $url = "http://www.youtube.com/watch?v=9IOpuGVoyCk" then i gonna split the video id "9IOpuGVoyCk" , so what code gonna i use to show the all video data when i open the php file in the browser ? just can u make the full php file in the beginning of it the normal video url like $url = "http://www.youtube.com/watch?v=9IOpuGVoyCk" and when i gonna open it, it will show the video , thumbnail, the title and description just to understand ??? i wish u can do that , i will be thankful for it , thanks again
Would be something like: <?php $feedurl = 'http://gdata.youtube.com/feeds/api/videos/9IOpuGVoyCk'; $xml = simplexml_load_file($feedurl); $media = $xml->entry->children('http://search.yahoo.com/mrss/'); echo $media->group->title.'<br />'; //video title echo $media->group->description.'<br />'; //video description $content = $entry->xpath("media:content[@type='application/x-shockwave-flash']"); echo '<embed src="'.$content[0][url].'"></embed><br />'; //embedded video ?> PHP: Havent tested the code - but should work
thanks for that code but i got error Warning: main() [function.main]: Node no longer exists in C:\AppServ\www\1\6.php on line 7 but at less , now i understand more , so check if u can fix the error thanks
Hmm.. there is no main() function in my code. Did you have any other code in your script when you tested?
no i didnt put any codes with your code in the file but i found that code on that web now ----------------------------------------- <?php function output_video_thumbs($search_term, $max_results = 15, $page, $orderby = 'relevance') { $url = "http://gdata.youtube.com/feeds/api/videos?vq=$search_term&max-results=$max_results&orderby=$orderby&start-index=$start_index&alt=rss"; // Use the magpie rss function retch_rss to read from the feed $rss = fetch_rss($url); // Outputs div'd thumbnails from parsed array foreach ($rss->items as $item) { $title = $item[title]; $url = $item[link]; $desc = $item[description]; // This is just small function I wrote to truncate extra long descriptions I will not include it as it is off topic. $desc = ShortenText($desc); // Get the video id from the video url $parts = explode("=", $url); $video_id = $parts[1]; echo "<div class='video_thumb'><a href='$url'><img src='http://img.youtube.com/vi/$video_id/2.jpg' title='$title' height='97' width='130'/></a>"; // This url will obviously change depending on your link structure. echo "<a href='watch/$video_id'>$title</a>"; echo "<p>$desc</p>"; echo "</div>"; } } ?> --------------------------------------------- but i dont understand if we have the video link like that http://www.youtube.com/watch?v=9IOpuGVoyCk where gonna we put the link or the video id on that code ?? check it , put on it the video url or the video id like "9IOpuGVoyCk" ,check it on your browser if it load the video with the data and i wish it gonna works waiting for your reply , thanks