This is my script that takes my 'name' and 'artist' from mysql
database and searches YouTube for them...
I'm trying to get the video url into a variable so I can then use it
to be the source of my chromeless youtube player..
This is an example of some of the XML a query would return:
Code:
<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007'><id>http://gdata.youtube.com/feeds/api/videos</id><updated>2009-07-27T10:12:26.915Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/><title type='text'>YouTube Videos matching query: Apartment Fall into place</title><logo>http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo><link rel='alternate' type='text/html' href='http://www.youtube.com'/><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos'/><link rel='http://schemas.google.com/g/2005#batch' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/batch'/><link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos?q=Apartment+Fall+into+place&start-index=1&max-results=1'/><link rel='next' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos?q=Apartment+Fall+into+place&start-index=2&max-results=1'/><author><name>YouTube</name><uri>http://www.youtube.com/</uri></author><generator version='2.0' uri='http://gdata.youtube.com/'>YouTube data API</generator><openSearch:totalResults>373</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>1</openSearch:itemsPerPage><entry><id>http://gdata.youtube.com/feeds/api/videos/Hei_T3x40Rk</id><published>2007-11-17T19:03:39.000Z</published><updated>2009-07-26T22:53:33.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/><category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Music' label='Music'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Music'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='apartment'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='fall'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='into'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='place'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='rock'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='fifa'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='08'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='song'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='football'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='top'/><title type='text'>Fall into Place - Apartment</title><content type='text'>A new song that makes part of Fifa 08... Fall into Place - Apartment</content><link rel='alternate' type='text/html' href='http://www.youtube.com/watch?v=Hei_T3x40Rk'/><link rel='http://gdata.youtube.com/schemas/2007#video.responses' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/Hei_T3x40Rk/responses'/><link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/Hei_T3x40Rk/related'/><link rel='http://gdata.youtube.com/schemas/2007#mobile' type='text/html' href='http://m.youtube.com/details?v=Hei_T3x40Rk'/><link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/Hei_T3x40Rk'/><author><name>paulomoniz</name><uri>http://gdata.youtube.com/feeds/api/users/paulomoniz</uri></author><gd:comments><gd:feedLink href='http://gdata.youtube.com/feeds/api/videos/Hei_T3x40Rk/comments' countHint='324'/></gd:comments><media:group><media:category label='Music' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Music</media:category><media:content url='http://www.youtube.com/v/Hei_T3x40Rk&f=videos&app=youtube_gdata' type='application/x-shockwave-flash' medium='video' isDefault='true' expression='full' duration='203' yt:format='5'/><media:content url='rtsp://rtsp2.youtube.com/CiILENy73wIaGQkZ0Xh8T7_oHRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='203' yt:format='1'/><media:content url='rtsp://rtsp2.youtube.com/CiILENy73wIaGQkZ0Xh8T7_oHRMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='203' yt:format='6'/><media:description type='plain'>A new song that makes part of Fifa 08... Fall into Place - Apartment</media:description><media:keywords>Music, apartment, fall, into, place, rock, fifa, 08, song, football, top</media:keywords><media:player url='http://www.youtube.com/watch?v=Hei_T3x40Rk'/><media:thumbnail url='http://i.ytimg.com/vi/Hei_T3x40Rk/2.jpg' height='90' width='120' time='00:01:41.500'/><media:thumbnail url='http://i.ytimg.com/vi/Hei_T3x40Rk/1.jpg' height='90' width='120' time='00:00:50.750'/><media:thumbnail url='http://i.ytimg.com/vi/Hei_T3x40Rk/3.jpg' height='90' width='120' time='00:02:32.250'/><media:thumbnail url='http://i.ytimg.com/vi/Hei_T3x40Rk/0.jpg' height='240' width='320' time='00:01:41.500'/><media:title type='plain'>Fall into Place - Apartment</media:title><yt:duration seconds='203'/></media:group><gd:rating average='4.9259257' max='5' min='1' numRaters='378' rel='http://schemas.google.com/g/2005#overall'/><yt:statistics favoriteCount='975' viewCount='133165'/></entry></feed>
This is my PHP Code:
PHP Code:
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("fsdb", $con);
$result = mysql_query("SELECT *FROM test");
while($row = mysql_fetch_array($result))
{
$name = $row['Name'];
$artist = $row['Artist'];
echo '<table width="75%" align="center" border="0" cellpadding="5" cellspacing="0"><tr><th width="25%" class="row">';
echo $row['Name'];
echo '</th>';
echo '<th width="25%" " class="row">';
echo $row['Artist'];
echo '</th>';
echo '<th width="25%" " class="row">';
echo '<a href="http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsSearch?term=';
echo $row['Name'];
echo "+";
echo $row['Artist'];
echo '&media=music&limit=1">Download</a>';
echo '</th>';
echo '<th width="25%" " class="row">';
$gdata = "http://gdata.youtube.com/feeds/api/videos?q=$name+$artist&max-results=1";
$request_url = $gdata;
$xml = simplexml_load_file($gdata) or die("Song could not be found, sorry.");
foreach ($sxml->entry as $entry)
// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');
// get video player URL
$attrs = $media->group->player->attributes();
$watch = $attrs['url'];
echo $watch;
echo '</th>';
echo '</tr>';
echo '</table>';
}
mysql_close($con);
?>
Will be grateful for any help at all 
|