Exemplo n.º 1
0
 public function testGetPlaylistItemsByPlaylistId()
 {
     $GOOGLE_ZEITGEIST_PLAYLIST = 'PL590L5WQmH8fJ54F369BLDSqIwcs-TCfs';
     $response = $this->youtube->getPlaylistItemsByPlaylistId($GOOGLE_ZEITGEIST_PLAYLIST);
     $this->assertTrue(count($response) > 0);
     $this->assertEquals('youtube#playlistItem', $response[0]->kind);
 }
Exemplo n.º 2
0
 /**
  * @return JsonResponse
  *
  * @Route("/sync")
  */
 public function syncAction()
 {
     $youtube = new Youtube(['key' => $this->getParameter('youtube_api_key')]);
     $videos = $youtube->getPlaylistItemsByPlaylistId($this->getParameter('youtube_playlist_id'));
     $em = $this->getDoctrine()->getManager();
     foreach ($videos as $video) {
         $name = $video->snippet->title;
         $youtubeId = $video->snippet->resourceId->videoId;
         $description = $video->snippet->description;
         if (property_exists($video->snippet->thumbnails, 'maxres')) {
             $thumbnail = $video->snippet->thumbnails->maxres->url;
         } elseif (property_exists($video->snippet->thumbnails, 'high')) {
             $thumbnail = $video->snippet->thumbnails->high->url;
         } elseif (property_exists($video->snippet->thumbnails, 'medium')) {
             $thumbnail = $video->snippet->thumbnails->medium->url;
         } else {
             $thumbnail = $video->snippet->thumbnails->default->url;
         }
         $video = $em->getRepository('TGVideoBundle:Video')->findOneByYoutubeId($youtubeId);
         if ($video === null) {
             $video = new Video();
             $video->setYoutubeId($youtubeId);
             $em->persist($video);
         }
         $video->setName($name);
         $video->setDescription($description);
         $video->setThumbnail($thumbnail);
         $video->setUrl('https://www.youtube.com/embed/' . $youtubeId);
     }
     $em->flush();
     $videos = $this->getDoctrine()->getRepository('TGVideoBundle:Video')->findAll([], ['createdAt' => 'DESC']);
     $serializer = new Serializer([$this->get('tg_video.normalizer')]);
     return new JsonResponse(['videos' => $serializer->normalize($videos)]);
 }
Exemplo n.º 3
0
 public function youtubecronAction()
 {
     include_once 'vendor/autoload.php';
     $vidModel = $this->getVideosModel();
     $youtube = new Youtube(array('key' => $vidModel->api_key));
     $playListArr = $youtube->getPlaylistItemsByPlaylistId($vidModel->playlist_id);
     $vidMapper = $this->getVideosMapper();
     $vidEntArr = $vidModel->formatYoutubeResponse($playListArr);
     foreach ($vidEntArr as $key => $ent) {
         $vidMapper->saveVideo($ent);
     }
 }
Exemplo n.º 4
0
?>
">Читать все материалы</a>
            </div>
        </div>
    </div>
    <div class="video-tv">
        <h3>Канал-ТВ</h3>
        <div class="well">
            <div class="row">
                <?php 
$key = 'AIzaSyAvDmtfH6P73IJzaV4bN0JyoJl--3Z4tc8';
$youtube = new Youtube(array('key' => $key));
$channel = $youtube->getChannelByName('fcbaltika');
//                var_dump($channel);
$playlist = $channel->contentDetails->relatedPlaylists->uploads;
$playlistItems = $youtube->getPlaylistItemsByPlaylistId($playlist);
$i = 0;
$playList = '';
$video = '';
foreach ($playlistItems as $item) {
    //                    echo $item->thumbnails->medium;
    //                    echo Html::img($item->snippet->thumbnails->medium->url, [
    //                        'width' => $item->snippet->thumbnails->default->width,
    //                        'height' => $item->snippet->thumbnails->default->height
    //                    ]);
    //                    var_dump($item->snippet->thumbnails);
    if ($i == 0) {
        $video = $item->snippet->resourceId->videoId;
    } else {
        $playList .= $item->snippet->resourceId->videoId . ',';
    }
Exemplo n.º 5
0
<?php

require "vendor/autoload.php";
//require_once('vendor/fennb/phirehose/lib/Phirehose.php');
//require_once('vendor/fennb/phirehose/lib/OauthPhirehose.php');
use Madcoda\Youtube;
include 'config.php';
//require_once("phpfastcache.php");
phpFastCache::setup("path", dirname(__FILE__) . '/cache');
// Path For Files
// simple Caching with:
$cache = phpFastCache();
// Try to get $content from Caching First
// product_page is "identity keyword";
$content = $cache->get(PLAYLIST_ID);
$content = null;
if ($content == null) {
    $youtube = new Youtube(array('key' => YOUTUBE_API_KEY));
    $content = $youtube->getPlaylistItemsByPlaylistId(PLAYLIST_ID);
    //$content = "DB QUERIES | FUNCTION_GET_PRODUCTS | ARRAY | STRING | OBJECTS";
    // Write products to Cache in 10 minutes with same keyword
    $cache->set(PLAYLIST_ID, $content, CACHE_TIME);
    //echo "Used API <br><br>";
} else {
    //echo "Used Cache <br><br>";
}
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
echo json_encode($content);
//debug( $debug );
Exemplo n.º 6
0
<?php

require __DIR__ . '/vendor/autoload.php';
use Madcoda\Youtube;
// API KEY
$apikey = trim(file_get_contents(__DIR__ . '/APIKEY.txt'));
$youtube = new Youtube(array('key' => $apikey));
// List: PLmTv5sSj3TpGueGhscXrWMxXNxvTr4iHY
//$playlist = $youtube->getPlaylistById('PLmTv5sSj3TpGueGhscXrWMxXNxvTr4iHY');
$videos = $youtube->getPlaylistItemsByPlaylistId('PLmTv5sSj3TpGueGhscXrWMxXNxvTr4iHY');
foreach ($videos as $video) {
    echo $video->snippet->title . PHP_EOL;
    echo $video->snippet->thumbnails->medium->url . PHP_EOL;
    echo $video->contentDetails->videoId . PHP_EOL;
}
/*
array(1) {
  [0] =>
  class stdClass#5 (6) {
    public $kind =>
    string(20) "youtube#playlistItem"
    public $etag =>
    string(57) ""kuL0kDMAqRo3pU7O0pwlO-Lfzp4/V8mAxXVDSZ6VH01tWC6Bm274RMg""
    public $id =>
    string(45) "PLFJeS94nReeHSJnvhtU9l6pp8UlS4-BqhbBD08jw-xkQ"
    public $snippet =>
    class stdClass#6 (9) {
      public $publishedAt =>
      string(24) "2015-12-21T21:59:28.000Z"
      public $channelId =>
      string(24) "UCTQ9lOLYm3tyBXzrKn4p1bA"