Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. <?php
  2. // set feed URL
  3. $feedURL = 'http://gdata.youtube.com/feeds/api/standardfeeds/most_viewed';
  4.  
  5. // read feed into SimpleXML object
  6. $sxml = simplexml_load_file($feedURL);
  7. ?>
  8. <h1><?php echo $sxml->title; ?></h1>
  9. <?php
  10. // iterate over entries in feed
  11. foreach ($sxml->entry as $entry) {
  12. // get nodes in media: namespace for media information
  13. $media = $entry->children('http://search.yahoo.com/mrss/');
  14.  
  15. // get video player URL
  16. $attrs = $media->group->player->attributes();
  17. $watch = $attrs['url'];
  18.  
  19. // get video thumbnail
  20. $attrs = $media->group->thumbnail[0]->attributes();
  21. $thumbnail = $attrs['url'];
  22.  
  23. // get <yt:duration> node for video length
  24. $yt = $media->children('http://gdata.youtube.com/schemas/2007');
  25. $attrs = $yt->duration->attributes();
  26. $length = $attrs['seconds'];
  27.  
  28. // get <yt:stats> node for viewer statistics
  29. $yt = $entry->children('http://gdata.youtube.com/schemas/2007');
  30. $attrs = $yt->statistics->attributes();
  31. $viewCount = $attrs['viewCount'];
  32.  
  33. // get <gd:rating> node for video ratings
  34. $gd = $entry->children('http://schemas.google.com/g/2005');
  35. if ($gd->rating) {
  36. $attrs = $gd->rating->attributes();
  37. $rating = $attrs['average'];
  38. } else {
  39. $rating = 0;
  40. }
  41. $my_format = 'mqdefault.jpg';
  42. $my_url = 'img.ytapi.com';
  43. ?>
  44.  
  45. <div class="item">
  46. <span class="title">
  47. <a href="<?php echo $watch; ?>"><?php echo $media->group->title; ?></a>
  48. </span>
  49. <p>
  50. <span class="thumbnail">
  51. <a href="<?php echo $watch; ?>"><img src="<?php echo str_replace(array("i.ytimg.com","0.jpg"),array($my_url, $my_format), $thumbnail);?>" /></a>
  52. <br/>click to view
  53. </span>
  54. <span class="attr">By:</span> <?php echo $entry->author->name; ?> <br/>
  55. <span class="attr">Duration:</span> <?php printf('%0.2f', $length/60); ?>
  56. min. <br/>
  57. <span class="attr">Views:</span> <?php echo $viewCount; ?> <br/>
  58. <span class="attr">Rating:</span> <?php echo $rating; ?>
  59. </p>
  60. </div>
  61. <?php
  62. }
  63. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement