O'Reilly Forums: You Tube Chapter 12 - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

You Tube Chapter 12 Thumbnail layout

#1 User is offline   mikel1 

  • New Member
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 16-February 12

Posted 28 May 2012 - 09:02 AM

Been struggling with this for a while now. The thumbs and videos are pulling in fine. What I am trying to do is pull 28 thumbs and have them in 4 rows of 7. Right now they are blowing off the page.

Attached File  youtube.php (2K)
Number of downloads: 72


<?php
define('YOUTUBE_URL', 'http://gdata.youtube.com/feeds/api/videos/-/dog/funny/bad/');
define('NUM_VIDEOS', 28);
define('NUM_VIDEOS_ROW', 7);

// Read the XML data into an object
$xml = simplexml_load_file(YOUTUBE_URL);

$num_videos_found = count($xml->entry);
if ($num_videos_found > 0) {
echo '<table><tr>';
for ($i = 0; $i < min($num_videos_found, NUM_VIDEOS, NUM_VIDEOS_ROW); $i++) {

if(($i+1)%NUM_VIDEOS_ROW === 7) {

echo '<br/>';
}
// Get the title


$entry = $xml->entry[$i];
$media = $entry->children('http://search.yahoo.com/mrss/');
$title = $media->group->title;
// Get the duration in minutes and seconds, and then format it
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$length_min = floor($attrs['seconds'] / 60);
$length_sec = $attrs['seconds'] % 60;
$length_formatted = $length_min . (($length_min != 1) ? ' minutes, ':' minute, ') .
$length_sec . (($length_sec != 1) ? ' seconds':' second');

// Get the video URL
$attrs = $media->group->player->attributes();
$video_url = $attrs['url'];

// Get the thumbnail image URL
$attrs = $media->group->thumbnail[0]->attributes();
$thumbnail_url = $attrs['url'];

// Display the results for this entry
echo '<td style="vertical-align:bottom; text-align:center" width="' . (100 / NUM_VIDEOS) . '%"><a href="' . $video_url . '" target="_blank">' .
$title . '<br /><span style="font-size:smaller; color:black">' . $length_formatted . '</span><br /><img src="' . $thumbnail_url . '" style = "width:200px; border=0" /></a></td>';
}
echo '</tr></table>';
}

else {
echo '<p>Sorry, no videos were found.</p>';
}
echo '</div>';

//echo '</div><br style="clear: both;" />';
?>

This post has been edited by mikel1: 28 May 2012 - 09:04 AM

0

#2 User is offline   mikel1 

  • New Member
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 16-February 12

Posted 28 May 2012 - 09:18 AM

View Postlemuel, on 28 May 2012 - 09:15 AM, said:

Ask yourself: For what value(s) of '$i' is this statement true?
(($i+1)%NUM_VIDEOS_ROW === 7)

0

#3 User is offline   mikel1 

  • New Member
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 16-February 12

Posted 28 May 2012 - 09:24 AM

Thank you, I am back at it.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users