I am in need of some help. What I have so far is a basic Youtube API
search page
"<body>
<h1>Keyword search</h1>
<form method="post" action="/search.php">
Keywords: <br/>
<input type="text" name="q" id='q' / >
<p/>
Items to display: <br/>
<select name="i">
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
</select>
<p/>
<input type="submit" name="submit" value="Search"/>
</form>
</body>"
that sends the users query to search.php which contains the Youtube
API response feeds displaying all of the video information.
"<?php
// if form not submitted
// display search box
if (!isset($_POST['submit'])) {
?>
<?php
// if form submitted
} else {
// check for search keywords
// trim whitespace
// separate multiple keywords with /
if (!isset($_POST['q']) || empty($_POST['q'])) {
die ('ERROR: Please enter one or more search keywords');
} else {
$q = $_POST['q'];
$q = preg_replace('/[[:space:]]+/', '/', trim($q));
}
// set max results
if (!isset($_POST['i']) || empty($_POST['i'])) {
$i = 10;
} else {
$i = $_POST['i'];
}
// generate feed URL
$feedURL = "http://gdata.youtube.com/feeds/api/videos?q=$q&max-
results={$i}";
// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);
// get summary counts from opensearch: namespace
$counts = $sxml->children('http://a9.com/-/spec/opensearchrss/
1.0/');
$total = $counts->totalResults;
$startOffset = $counts->startIndex;
$endOffset = ($startOffset-1) + $counts->itemsPerPage;
?>
<h1>Search results</h1>
<?php echo $total; ?> items found. Showing items
<?php echo $startOffset; ?> to <?php echo $endOffset; ?>:
<p/>
<table>
<?php
// iterate over entries in resultset
// print each entry's details
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'];
// get video thumbnail
$attrs = $media->group->thumbnail[0]->attributes();
$thumbnail = $attrs['url'];
// get <yt:duration> node for video length
$yt = $media->children('http://gdata.youtube.com/schemas/
2007');
$attrs = $yt->duration->attributes();
$length = $attrs['seconds'];
// get <gd:rating> node for video ratings
$gd = $entry->children('http://schemas.google.com/g/2005');
if ($gd->rating) {
$attrs = $gd->rating->attributes();
$rating = $attrs['average'];
} else {
$rating = 0;
}
// print record
echo "<tr><td colspan=\"2\" class=\"line\"></td>
</tr>\n";
echo "<tr>\n";
echo "<td><a href=\"index.php?{$watch}\"><img src=\"$thumbnail
\"/></a></td>\n";
echo "<td><a href=\"index.php?{$watch}\">
{$media->group->title}</a><br/>\n";
echo sprintf("%0.2f", $length/60) . " min. | {$rating} user
rating<br/>\n";
echo $media->group->description . "</td>\n";
echo "</tr>\n";
}
}
?>
</table>
</body>"
What I am trying to do is grab the $watch variable which contains the
video url for the users request and send it into another webpage which
currently is a manual input form, where a user can input he url
themselves. What I am trying to do is have the third page grab the
video url from the search results page and go ahead and process it as
if it has been manually input. The third page source is as follows.
"<body>
<?php
// On form submission...
if ($_POST['submit'])
{
// Print "please wait" message and preview image
echo '<div id="preview" style="display:block"><p>...Please wait</
p>';
echo '<p><img src="http://img.youtube.com/vi/'.$converter-
>ExtractVideoId(trim($_POST['watch'])).'/1.jpg" alt="preview image" /
></p>';
echo '<p>'.$converter->ExtractSongTrackName(trim($_POST['watch']),
'url').'</p>';
echo '<div id="progress-bar"><div id="progress">0%</div></div></
div>';
flush();
// Main Program Execution
if ($converter->DownloadVideo(trim($_POST['watch'])))
{
echo ($converter->GenerateMP3($_POST['quality'])) ? '<p>Success!</
p><p><a href="'.$_SERVER['PHP_SELF'].'?
mp3='.urlencode(trim(strstr($converter->GetSongFileName(), '/'),
'/')).'">Download your MP3 file.</a></p>' : '<p>Error generating MP3
file!</p>';
}
else
{
echo '<p>Error downloading video!</p>';
}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Enter a valid YouTube.com video URL:</p>
<p><input type="text" name="watch" /></p>
<p><i>(i.e., "<span style="color:red">http://www.youtube.com/watch?
v=HMpmI2F2cMs</span>")</i></p>
<p style="margin-top:20px">Choose the audio quality (better quality
results in larger files):</p>
<p style="margin-bottom:25px"><input type="radio" value="64"
name="quality" />Low <input type="radio" value="128"
name="quality" checked="checked" />Medium <input type="radio"
value="320" name="quality" />High</p>
<p><input type="submit" name="submit" value="Create MP3 File" /></p>
</form>
</body>"
as you can see the webpage has a form already for a user to input but
I would like to skip that part and have the form simply recognize the
incoming url and send it the my back end php script for processing.
What I have so far is the first page I can search for a video and they
display on a second page, however when I click on the video title link
or thumbnail link I would like for that to execute the url into my
backend php script as if it was entered manually into the web form. If
i simply load the third pages scripts it does work with my back end
php script and will process the url properly, my issue lays in getting
the search results page to send the $watch variable, which is the
video url into the third pages form. Any help would be so appreciated
and credit will be offered. I am stuck and cant seem to figure this
one out I am still quite newer to youtube API however so I guess
learning is in place :)
--
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To post to this group, send email to youtube-api-gdata@googlegroups.com.
To unsubscribe from this group, send email to youtube-api-gdata+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/youtube-api-gdata?hl=en.
No comments:
Post a Comment