Skip to content

Instantly share code, notes, and snippets.

@marcosfreitas
Created February 20, 2014 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcosfreitas/9115552 to your computer and use it in GitHub Desktop.
Save marcosfreitas/9115552 to your computer and use it in GitHub Desktop.
script que pega os vídeos enviado ao youtube por um determinado usuário.
<?php
$start = microtime(true);
header('Content-Type: text/html; charset=ISO-8859-1');
echo '<h3 style="color: #2e8ece; font-family: sans-serif; font-weight: normal !important; margin: 10px; width: 100%; text-align: center; clear:both;">Tempo inicial de execução do script: '.$start.'</h3>';
ini_set('display_errors', 1);
error_reporting(E_ALL);
?>
<style>
body{overflow: hidden;}
.elastislide-wrapper{
height: auto;
}
#multimedia {
position: relative;
padding-top: 0px;
height: 385px;
overflow: hidden;
padding-bottom: 0px;
}
.list-videos-h{
margin: 2px; display: inline-block;
}
</style>
<section class="fixed-bar">
<!-- Elastislide Carousel -->
<ul id="carousel" class="elastislide-list">
<?php
// método 2 - integração php (simple xml com api do youtube)
// read feed into SimpleXML object
$sxml = simplexml_load_file('http://gdata.youtube.com/feeds/api/users/GISCAEMPREENDIMENTOS/uploads');
//$sxml = simplexml_load_file('http://gdata.youtube.com/feeds/api/users/TheVintronic/uploads');
if(!$sxml) echo 'Erro ao carregar vídeos contate a <abbr title="envie um e-mail para atendimento@onservices.com.br">administração</abbr>.';
$cont = 0;
// iterate over entries in feed
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'];
#transformando a url para uma válida
$watch = str_replace('http://www.youtube.com/watch?v=', 'http://www.youtube.com/embed/', $watch);
$watch = str_replace('&feature=youtube_gdata_player', '', $watch);
//first vídeo url
if($cont == 0)
$firstVideo = $watch;
// 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 <yt:stats> node for viewer statistics
$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->statistics->attributes();
$viewCount = (float) $attrs['viewCount'];
//var_dump($viewCount);
// 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;
}
//configurações de exibições
if($viewCount == "1")
$youtube_rank = ($viewCount.' exibição</p>');
else
if($viewCount == "0" || empty($viewCount))
$youtube_rank = 'nenhuma exibição</p>';
else
$youtube_rank = ($viewCount).' exibições</p>';
//título do vídeo
$youtube_title = utf8_decode(substr(($media->group->title),0,100));
echo '<li class="list-videos-h" style="width:150px !important; height: 117px !important;"><a href="'.$watch.'" data-rank="'.$youtube_rank.'" data-title="'.$youtube_title.'" class="youtube-list"><img width="150" height="117" src="'.$thumbnail.'"/></a></li>';
}//fim foreach videos
?>
<ul>
</section>
<!-- End Elastislide Carousel -->
<?php
$end_time = microtime(true);
echo "<h2>End time: </h2>".$end_time.'<br>';
$time_taken = microtime(true) - $start;
echo '<h3 style="color: #2e8ece; font-family: sans-serif; font-weight: normal !important; margin: 10px; width: 100%; text-align: center; clear:both;">Tempo total de execução do script: '.$time_taken.' segs</h3>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment