public function actionAddVideo($videoId, $size) { $lib = new Vimeo(Yii::$app->params['vimeoClientId'], Yii::$app->params['vimeoSecret'], Yii::$app->params['vimeoAccessToken']); $video = new Video(); $video->videoId = $videoId; $video->size = $size; $response = $lib->request('/me/videos/' . $videoId, [], 'GET'); $video->duration = $response['body']['duration']; $video->embed = $response['body']['embed']['html']; $files = $response['body']['files']; $temp = []; foreach ($files as $key => $value) { switch ($value['quality']) { case 'mobile': $video->mobileLink = $value['link']; break; case 'sd': $video->sdLink = $value['link']; break; case 'hls': $video->hlsLink = $value['link']; break; } } return $response['body']['stats']['plays']; }
/** * Create a Vimeo media * * @param string $url * @return array */ public function create(string $url) : array { $config = $this->config; /* @var $service VimeoDriver */ $service = new VimeoDriver($config['client_id'], $config['client_secret'], $config['access_token']); $parsed = parse_url($url); $uri = explode('/', $parsed['path']); $videoId = array_pop($uri); $response = $service->request('/videos/' . $videoId, [], 'GET'); $video = $response['body']; return $video; }
/** * resolve the url data * * @return mixed */ protected function doResolve() { $id = $this->id ? $this->id : $this->validate(); $lib = new Vimeo($this->config()->get('vimeoKey'), $this->config()->get('vimeoSecret')); $token = $lib->clientCredentials('private public'); if (isset($token['body']['access_token'])) { $lib->setToken($token['body']['access_token']); } $response = $lib->request('/videos/' . $id); if (isset($response['body']['error'])) { return false; } return $response['body']; }
/** * Make an API request to Vimeo. * * @param string $url A Vimeo API Endpoint. Should not include the host * @param array $params An array of parameters to send to the endpoint. If the HTTP method is GET, they will be added to the url, otherwise they will be written to the body * @param string $method The HTTP Method of the request * @param bool $json_body * * @return array|null */ public function request($url, $params = array(), $method = 'GET', $json_body = true) { if (Config::get('debugMode')) { static $requestCount = 0; if (++$requestCount > $this->requestLimit) { System::log(sprintf('The request limit of %s has been reached. Please check your script for possible optimizations.', $this->requestLimit), __METHOD__, 'VIMEO'); return null; } System::log('Vimeo request to: ' . $url, __METHOD__, 'VIMEO'); } try { $response = parent::request($url, $params, $method, $json_body); } catch (\Exception $e) { System::log(sprintf('Vimeo request (%s) failed with exception: %s', $url, $e->getMessage()), __METHOD__, TL_ERROR); return null; } $this->updateStats($response['headers']); if ($response['status'] !== 200) { System::log(sprintf('Vimeo request (%s) failed (code %s): %s', $url, $response['status'], print_r($response, true)), __METHOD__, TL_ERROR); return null; } return $response; }
public function actionConfirmed() { $codeBankCampaign = new CodeBankCampaign(); $codeBankCampaign->loadDefaultValues(); $video = new Video(); $video->loadDefaultValues(); $request = Yii::$app->request; if ($request->isPost) { $lib = new Vimeo(Yii::$app->params['vimeoClientId'], Yii::$app->params['vimeoSecret'], Yii::$app->params['vimeoAccessToken']); if ($codeBankCampaign->load($request->post()) && $video->load($request->post())) { $response = $lib->request('/me/videos/' . $video->videoId, [], 'GET'); $video->duration = $response['body']['duration']; $video->embed = $response['body']['embed']['html']; $video->poster = $response['body']['pictures']['sizes'][3]['link']; $files = $response['body']['files']; foreach ($files as $key => $value) { switch ($value['quality']) { case 'mobile': $video->mobileLink = $value['link']; break; case 'sd': $video->sdLink = $value['link']; break; case 'hls': $video->hlsLink = $value['link']; break; } } if (isset($codeBankCampaign->codeBank_code)) { $video->confirmed = 1; } $video->save(); $codeBankCampaign->objectId = $video->id; $codeBankCampaign->save(); // $view = $this->getView(); // $view->title = 'Step 3: Editing Video Information for Hyrizy Code ' . Html::tag('label',$codeBankCampaign->codeBank_code,['class'=>'label label-primary']); // return $this->render('update',['model'=>$video]); return $this->redirect(['/campaign/view', 'id' => $codeBankCampaign->id]); } } }
<?php //utf-8 header('Content-Type: text/html; charset=utf-8'); //lib vimeo use Vimeo\Vimeo; //métodos de inicialização $config = (require __DIR__ . '/init.php'); //vimeo video id @($id = $_GET["id"]); //isset get if (isset($id)) { // vimeo class send config.json paramns $lib = new Vimeo($config['client_id'], $config['client_secret'], $config['access_token']); //get data vimeo video $me = $lib->request("/me/videos/{$id}"); //iframe vídeo $embed = $me["body"]["embed"]["html"]; //edit video size $default_size = 'width="' . $me["body"]["width"] . '" height="' . $me["body"]["height"] . '"'; $new_size = 'width="420" height="220"'; $embed = str_replace($default_size, $new_size, $embed); //autoplay $embed = str_replace('player_id=0', 'player_id=0&autoplay=1', $embed); } else { echo "Not find get id video"; } ?> <!DOCTYPE html> <html> <head>
/** * Fetch the video images * * @param int $videoId * * @return array|null */ protected function fetchVideoImages($videoId) { $data = $this->client->request('/videos/' . $videoId . '/pictures'); return $data === null ? null : $data['body']; }
* Created by PhpStorm. * User: Fahmy * Date: 12/1/15 * Time: 8:35 PM */ /* @var $video common\models\Video */ use Vimeo\Vimeo; use yii\helpers\Url; ?> <div class="box-shadow shadow-effect-2" style="padding: 0 10px 10px 10px;margin-top: 15px"> <?php if ($model->modelClass === 'Video') { ?> <?php $video = $model->getVideo(); $lib = new Vimeo(Yii::$app->params['vimeoClientId'], Yii::$app->params['vimeoSecret'], Yii::$app->params['vimeoAccessToken']); $response = $lib->request('/me/videos/' . $video->videoId, [], 'GET'); ?> <div class="row"> <div class="col-md-11"> <div class="headline" style="margin-bottom: 0;margin-top: 10px"> <h3> <a href="<?php echo Url::to(['/campaign/view', 'id' => $model->id]); ?> "><?php echo $model->name; ?> </a> </h3> </div> </div> <div class="col-md-1" style="padding-top: 25px">
/** * VimeoService constructor. * * @param string $client_id * @param string $client_secret * @param null $access_token */ public function __construct($client_id, $client_secret, $access_token = null) { parent::__construct($client_id, $client_secret, $access_token); }