Ejemplo n.º 1
0
 /**
  * Get Youtube video info by video id
  * @param Request $request
  * @return Response
  */
 public function queryYoutubeVideo(Request $request)
 {
     $video = null;
     if ($request->has('id')) {
         $video = \Youtube::getVideoInfo($request->input('id'));
     }
     return new Response(json_encode($video));
 }
Ejemplo n.º 2
0
 public function postAdd()
 {
     if (!$this->checkRoute()) {
         return Redirect::route('index');
     }
     $title = 'Add A Youtube Video / Playlist - ' . $this->site_name;
     $input = Input::only('url', 'category', 'modpack', 'mod');
     $validator = Validator::make($input, ['url' => 'required']);
     if ($validator->fails()) {
         return Redirect::action('YoutubeController@getadd')->withErrors($validator)->withInput();
     }
     $youtube = new Youtube();
     $processed_url = $this->processURL($input['url']);
     if (!$processed_url['type']) {
         return Redirect::action('YoutubeController@getadd')->withErrors(['message' => 'Unable to process URL.'])->withInput();
     }
     $youtube_information = $youtube->getVideoInfo($processed_url['id'], $processed_url['type']);
     if (!$youtube_information) {
         return Redirect::action('YoutubeController@getadd')->withErrors(['message' => 'Unable to process Youtube API.'])->withInput();
     }
     $youtube_information = $youtube_information->items[0];
     $youtube->type = $processed_url['type'];
     $youtube->title = $youtube_information->snippet->title;
     $youtube->youtube_id = $youtube_information->id;
     $youtube->channel_title = $youtube_information->snippet->channelTitle;
     $youtube->channel_id = $youtube_information->snippet->channelId;
     $youtube->thumbnail = $youtube_information->snippet->thumbnails->medium->url;
     $youtube->category_id = $input['category'];
     if ($input['modpack']) {
         $youtube->modpack_id = $input['modpack'];
     } elseif ($input['mod']) {
         $youtube->mod_id = $input['mod'];
     }
     $youtube->last_ip = Request::getClientIp();
     $success = $youtube->save();
     if ($success) {
         Cache::tags('modpacks')->flush();
         Cache::tags('mods')->flush();
         Queue::push('BuildCache');
         return View::make('youtube.add', ['title' => $title, 'success' => true, 'categories' => $this->categories]);
     }
     return Redirect::action('YoutubeController@getadd')->withErrors(['message' => 'Unable to add modpack code.'])->withInput();
 }
Ejemplo n.º 3
0
 /**
  * @param $key
  * @return array
  */
 public function getVideoInfo($key)
 {
     $result = [];
     $result['duration'] = '';
     $result['thumbnail'] = '';
     $key = trim($key);
     try {
         if (filter_var($key, FILTER_VALIDATE_URL)) {
             $array = explode('=', $key);
             $key = end($array);
         }
         $video = \Youtube::getVideoInfo($key);
         $start = new \DateTime('@0');
         // Unix epoch
         $start->add(new \DateInterval($video->contentDetails->duration));
         $result['duration'] = $start->format('H:i:s');
         $result['thumbnail'] = isset($video->snippet->thumbnails->standard->url) ? $video->snippet->thumbnails->standard->url : $video->snippet->thumbnails->high->url;
     } catch (\Exception $e) {
         return $result;
     }
     return $result;
 }
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;
}
Ejemplo n.º 5
0
|--------------------------------------------------------------------------
| Routes File
|--------------------------------------------------------------------------
|
| Here is where you will register all of the routes in an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    return view('welcome');
});
Route::get('/hello', function () {
    $activities = Youtube::getActivitiesByChannelId('UC5aFrNqC7R5N5CNRA9MIi7g');
    $video = $activities[0]->contentDetails->upload->videoId;
    $videoInfo = Youtube::getVideoInfo($video);
    var_dump($videoInfo);
});
Route::get('update', 'YTUpdate\\YTUpdateController@UpDateVideo');
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| This route group applies the "web" middleware group to every route
| it contains. The "web" middleware group is defined in your HTTP
| kernel and includes session state, CSRF protection, and more.
|
*/
Route::group(['middleware' => ['web']], function () {
    //
Ejemplo n.º 6
0
function loadVideoInfo(&$video)
{
    $isArray = is_array($video);
    if ($isArray) {
        foreach ($video as $v) {
            $infos = Youtube::getVideoInfo($v->url);
            $v->infos = $infos;
        }
    } else {
        $infos = Youtube::getVideoInfo($video->url);
        $video->infos = $infos;
    }
}