public function listChannel($usuario) { $channel = YoutubeService::getChannelByName($usuario); $playlists = YoutubeService::getPlaylistsByChannelId($channel->id); $videos = []; foreach ($playlists as $playlist) { $videos[$playlist->snippet->title] = YoutubeService::getPlaylistItemsByPlaylistId($playlist->id); } return $videos; }
function create_shortcode() { $option = get_option('ta_videobook_setting'); //Default Googke Key $GoogleKey = 'AIzaSyBZqdpiCXFQqHI4h90fFfbkiaZSPquqhjM'; //Default Playlist $PlayListID = 'PLKbMO3RbT7Pd9XQWaFRBCR5wb_wcrSgL5'; if (isset($option['google_key']) && !is_null($option['google_key'])) { $GoogleKey = $option['google_key']; } if (isset($option['playlistID']) && !is_null($option['playlistID'])) { $PlayListID = $option['playlistID']; } $YouTube_v3 = new Youtube($GoogleKey); $Number_Video_Of_Page = 12; // 1 - Lay trang hi?n t?i $Current_Page = isset($_GET['vdPage']) ? $_GET['vdPage'] : 1; // 2 - Lay thong tin PlayList // Bao nhieu Video de Phan trang $playList = $YouTube_v3->getPlaylistById($PlayListID, ['contentDetails']); $Video_Items_Count = $playList->contentDetails->itemCount; if ($Video_Items_Count == 0) { echo 'No video in the playlist'; return; } $count_pages = ceil($Video_Items_Count / 12); //echo 'So luong video trong playlist la: ' . $Video_Items_Count; $KetQua = ""; echo '<div style="width: 700px;">'; //echo var_dump($playList); // 3 - Lay danh sach video t? playlist $playlistItems = []; $nextPageToken = ""; for ($index = 0; $index < $count_pages; $index++) { $pageNumber = $index + 1; if ($pageNumber == $Current_Page) { $playlistItems = $YouTube_v3->getPlaylistItemsByPlaylistId($PlayListID, $nextPageToken, $Number_Video_Of_Page, ['id', 'snippet']); break; } else { $nextPageToken = is_null($nextPageToken) ? true : $nextPageToken; $playlistItems = $YouTube_v3->getPlaylistItemsByPlaylistId($PlayListID, $nextPageToken, $Number_Video_Of_Page, ['id']); $nextPageToken = $playlistItems['info']['nextPageToken']; } } // 4 - Hien thi Video player $first_video = $playlistItems['results'][0]; $first_video_id = $first_video->snippet->resourceId->videoId; $first_Video_Player = $YouTube_v3->getVideoInfo($first_video_id, ['player']); echo '<div class="intelliam-normal-player" style="width: 100%">'; //echo '<div class="intelliam-big-title">' . $first_video->snippet->title . '</div>'; echo '<div class="intelliam-fluid-width-video-wrapper" id="video-container"><div class="fluid-width-video-wrapper" style="padding-top: 55%">' . $first_Video_Player->player->embedHtml . '</div></div>'; echo '</div>'; //Hien thi phan trang intelliam_util::displayPagination($count_pages, $Current_Page); // Lay Danh sach Id cua tat ca video $VideoId_List = intelliam_util::getVideoIdList($playlistItems['results']); // Lay Danh thong tin video tu danh sach $Video_List_ContentDetails_Statistics = $YouTube_v3->getVideoInfo($VideoId_List, ['contentDetails', 'statistics']); //Hien Thi danh sach video intelliam_util::displayVideoList($playlistItems['results'], $Video_List_ContentDetails_Statistics); //Hien thi phan trang intelliam_util::displayPagination($count_pages, $Current_Page); echo '</div>'; //return $KetQua; }
public function createWebsite() { $user_id = Auth::user()->id; $rules = array('title' => 'required', 'type' => 'required', 'account_id' => 'required'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('/websites/new')->withErrors($validator)->withInput(); } else { $client = new GuzzleHttp\Client(); $title = Input::get('title'); $tagline = Input::get('tagline'); $about = Input::get('about'); $type = Input::get('type'); $account_id = Input::get('account_id'); $domain_name = Input::get('domain_name'); $is_public = 0; if (Input::has('public')) { $is_public = 1; } $website = new Website(); $website->user_id = $user_id; $website->long_id = Str::slug(substr($title, 0, 160) . '-' . str_random(6)); $website->type = $type; $website->domain_name = $domain_name; $website->title = $title; $website->tagline = $tagline; $website->about = $about; $website->public = $is_public; $website->save(); $website_id = $website->id; if ($type == 'youtube') { $youtube = new Youtube(array('key' => Config::get('keys.youtube'))); $youtube_channel = $youtube->getChannelByName($account_id); $site_channel_id = $youtube_channel->id; $site_channel_title = $youtube_channel->snippet->title; $site_channel_description = $youtube_channel->snippet->description; $site_channel_thumbnail = $youtube_channel->snippet->thumbnails->high->url; } else { if ($type == 'vimeo') { $vimeo = $client->get("http://vimeo.com/api/v2/{$account_id}/info.json"); $vimeo_channel = json_decode($vimeo->getBody(), true); $site_channel_id = $vimeo_channel['id']; $site_channel_title = $vimeo_channel['display_name']; $site_channel_description = strip_tags($vimeo_channel['bio']); $site_channel_thumbnail = $vimeo_channel['portrait_huge']; } } $channel = new Channel(); $channel->user_id = $user_id; $channel->website_id = $website_id; $channel->channel_id = $site_channel_id; $channel->title = $site_channel_title; $channel->description = $site_channel_description; $channel->thumbnail = $site_channel_thumbnail; $channel->save(); $channel_id = $channel->id; $next_playlisttoken = ''; if ($type == 'youtube') { do { $playlists = $youtube->getPlaylistsByChannelId($youtube_channel->id, array('maxResults' => 50, 'pageToken' => $next_playlisttoken)); $next_playlisttoken = $youtube->page_info; if (!empty($playlists)) { foreach ($playlists as $pl) { //only cached playlists that are public if ($pl->status->privacyStatus == 'public') { $playlist_id = $pl->id; $playlist_params['body'] = array('id' => $playlist_id, 'user_id' => $user_id, 'website_id' => $website_id, 'channel_id' => $channel_id, 'title' => $pl->snippet->title, 'playlist_type' => 'youtube', 'description' => $pl->snippet->description, 'thumbnail' => $pl->snippet->thumbnails->high->url, 'published_at' => $pl->snippet->publishedAt); $playlist_params['index'] = 'video-websites'; $playlist_params['type'] = 'playlist'; $playlist_params['id'] = $playlist_id; $ret = Es::index($playlist_params); $next_videostoken = ''; do { $playlist_items = $youtube->getPlaylistItemsByPlaylistId($playlist_id, array('maxResults' => 50, 'pageToken' => $next_videostoken)); $next_videostoken = $youtube->page_info; if (!empty($playlist_items)) { foreach ($playlist_items as $video) { if ($video->status->privacyStatus == 'public') { $video_id = $video->id; $video_params['body'] = array('id' => $video_id, 'video_id' => $video->contentDetails->videoId, 'user_id' => $user_id, 'website_id' => $website_id, 'channel_id' => $channel_id, 'playlist_id' => $playlist_id, 'video_type' => 'youtube', 'position' => $video->snippet->position, 'title' => $video->snippet->title, 'description' => $video->snippet->description, 'thumbnails' => array('small' => $video->snippet->thumbnails->default->url, 'medium' => $video->snippet->thumbnails->medium->url, 'large' => $video->snippet->thumbnails->high->url), 'published_at' => $video->snippet->publishedAt); $video_params['index'] = 'video-websites'; $video_params['type'] = 'video'; $video_params['id'] = $video_id; $ret = Es::index($video_params); } } } } while (is_string($next_videostoken)); } } } } while (is_string($next_playlisttoken)); } else { if ($type == 'vimeo') { $playlists_response = $client->get("http://vimeo.com/api/v2/{$account_id}/channels.json"); $playlists = json_decode($playlists_response->getBody(), true); if (!empty($playlists)) { foreach ($playlists as $pl) { $playlist_id = $pl['id']; $playlist_params['body'] = array('id' => $playlist_id, 'user_id' => $user_id, 'website_id' => $website_id, 'channel_id' => $channel_id, 'title' => $pl['name'], 'playlist_type' => 'vimeo', 'description' => $pl['description'], 'thumbnail' => $pl['logo'], 'published_at' => $pl['created_on']); $playlist_params['index'] = 'video-websites'; $playlist_params['type'] = 'playlist'; $playlist_params['id'] = $playlist_id; $ret = Es::index($playlist_params); $video_page = 1; $video_index = 0; do { $videos_response = $client->get("http://vimeo.com/api/v2/{$playlist_id}/videos.json?page={$video_page}"); $videos = json_decode($videos_response->getBody(), true); if (!empty($videos)) { foreach ($videos as $video) { if ($video['embed_privacy'] == 'anywhere') { $video_id = $video['id']; $video_params['body'] = array('id' => $video_id, 'video_id' => $video_id, 'user_id' => $user_id, 'website_id' => $website_id, 'channel_id' => $channel_id, 'playlist_id' => $playlist_id, 'video_type' => 'vimeo', 'position' => $video_index, 'title' => $video['title'], 'description' => strip_tags($video['description']), 'thumbnails' => array('small' => $video['thumbnail_small'], 'medium' => $video['thumbnail_medium'], 'large' => $video['thumbnail_large']), 'published_at' => date('Y-m-d', strtotime($video['upload_date']))); $video_params['index'] = 'video-websites'; $video_params['type'] = 'video'; $video_params['id'] = $video_id; $ret = Es::index($video_params); } $video_index += 1; } } $video_page += 1; } while (!empty($videos) && $video_page <= 3); } } else { $video_page = 1; $video_index = 0; do { $allvideos_response = $client->get("http://vimeo.com/api/v2/{$account_id}/all_videos.json?page={$video_page}"); $videos = json_decode($allvideos_response->getBody(), true); if (!empty($videos)) { foreach ($videos as $video) { if ($video['embed_privacy'] == 'anywhere') { $video_id = $video['id']; $video_params['body'] = array('id' => $video_id, 'video_id' => $video_id, 'user_id' => $user_id, 'website_id' => $website_id, 'channel_id' => $channel_id, 'video_type' => 'vimeo', 'position' => $video_index, 'title' => $video['title'], 'description' => strip_tags($video['description']), 'thumbnails' => array('small' => $video['thumbnail_small'], 'medium' => $video['thumbnail_medium'], 'large' => $video['thumbnail_large']), 'published_at' => date('Y-m-d', strtotime($video['upload_date']))); $video_params['index'] = 'video-websites'; $video_params['type'] = 'video'; $video_params['id'] = $video_id; $ret = Es::index($video_params); } $video_index += 1; } } $video_page += 1; } while (!empty($videos) && $video_page <= 3); } } } return Redirect::to('/websites/new')->with('message', array('type' => 'success', 'text' => 'You have successfully created a website!')); } }
}); Route::get('/mock', function () { $youtube = new Youtube(array('key' => Config::get('keys.youtube'))); $youtube_channel = $youtube->getChannelByName('CodingEntrepreneurs'); $next_playlisttoken = ''; do { $playlists = $youtube->getPlaylistsByChannelId($youtube_channel->id, array('maxResults' => 50, 'pageToken' => $next_playlisttoken)); $next_playlisttoken = $youtube->page_info; if (!empty($playlists)) { foreach ($playlists as $pl) { //only cached playlists that are public if ($pl->status->privacyStatus == 'public') { $playlist_id = $pl->id; $next_videostoken = ''; do { $playlist_items = $youtube->getPlaylistItemsByPlaylistId($playlist_id, array('maxResults' => 50, 'pageToken' => $next_videostoken)); $next_videostoken = $youtube->page_info; echo "next video token: "; print_r($next_videostoken); echo "<br>"; if (!empty($playlist_items)) { foreach ($playlist_items as $video) { echo "<pre>"; print_r($video); echo "</pre>"; } } } while (is_string($next_videostoken)); } } }
public function getPlaylistVideos($playlistId) { return \Youtube::getPlaylistItemsByPlaylistId($playlistId)['results']; }