diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/.styleci.yml b/.styleci.yml old mode 100644 new mode 100755 diff --git a/.travis.yml b/.travis.yml old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 index e1b8e40..9175154 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { - "name": "madcoda/php-youtube-api", + "name": "scrobot/php-youtube-api", "type": "library", + "minimum-stability": "dev", "description": "PHP wrapper for the Youtube Data API v3", "keywords": ["youtube", "api", "video", "madcoda"], "license": "MIT", @@ -8,6 +9,10 @@ { "name": "Madcoda", "email": "jason@madcoda.com" + }, + { + "name": "Scrobot", + "email": "scrobot91@gmail.com" } ], "support":{ diff --git a/composer.lock b/composer.lock old mode 100644 new mode 100755 diff --git a/phpunit.xml.dist b/phpunit.xml.dist old mode 100644 new mode 100755 diff --git a/src/Constants.php b/src/Constants.php old mode 100644 new mode 100755 diff --git a/src/Facades/Youtube.php b/src/Facades/Youtube.php old mode 100644 new mode 100755 diff --git a/src/Youtube.php b/src/Youtube.php old mode 100644 new mode 100755 index 6c1fe0c..f37cee8 --- a/src/Youtube.php +++ b/src/Youtube.php @@ -148,16 +148,18 @@ public function getVideoInfo($vId) /** * @param $vIds + * @param array $parts * @return \StdClass - * @throws \Exception */ - public function getVideosInfo($vIds) + public function getVideosInfo($vIds, array $parts = []) { + $partArray = $this->fillParts(['id', 'snippet', 'contentDetails', 'player', 'statistics', 'status'], $parts); + $ids = is_array($vIds) ? implode(',', $vIds) : $vIds; $API_URL = $this->getApi('videos.list'); $params = array( 'id' => $ids, - 'part' => 'id, snippet, contentDetails, player, statistics, status' + 'part' => implode(",", $partArray), ); $apiData = $this->api_get($API_URL, $params); @@ -301,15 +303,18 @@ public function paginateResults($params, $token = null) /** * @param $username + * @param bool $optionalParams + * @param array $parts * @return \StdClass - * @throws \Exception */ - public function getChannelByName($username, $optionalParams = false) + public function getChannelByName($username, $optionalParams = false, array $parts = []) { + $partArray = $this->fillParts(['id', 'snippet', 'contentDetails', 'invideoPromotion', 'statistics'], $parts); + $API_URL = $this->getApi('channels.list'); $params = array( 'forUsername' => $username, - 'part' => 'id,snippet,contentDetails,statistics,invideoPromotion' + 'part' => implode(",", $partArray) ); if ($optionalParams) { $params = array_merge($params, $optionalParams); @@ -321,20 +326,25 @@ public function getChannelByName($username, $optionalParams = false) /** * @param $id + * @param bool $optionalParams + * @param array $parts * @return \StdClass - * @throws \Exception */ - public function getChannelById($id, $optionalParams = false) + public function getChannelById($id, $optionalParams = false, array $parts = []) { + $partArray = $this->fillParts(['id', 'snippet', 'contentDetails', 'invideoPromotion', 'statistics'], $parts); $API_URL = $this->getApi('channels.list'); $params = array( 'id' => $id, - 'part' => 'id,snippet,contentDetails,statistics,invideoPromotion' + 'part' => implode(",", $partArray) ); + if ($optionalParams) { $params = array_merge($params, $optionalParams); } + $apiData = $this->api_get($API_URL, $params); + return $this->decodeSingle($apiData); } @@ -616,9 +626,9 @@ public function decodeList(&$apiData) */ public function api_get($url, $params) { + //set the youtube key $params['key'] = $this->youtube_key; - //boilerplates for CURL $tuCurl = curl_init(); if ($this->sslPath !== null) { @@ -633,9 +643,11 @@ public function api_get($url, $params) } curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, 1); $tuData = curl_exec($tuCurl); + if (curl_errno($tuCurl)) { throw new \Exception('Curl Error : ' . curl_error($tuCurl), curl_errno($tuCurl)); } + return $tuData; } @@ -672,4 +684,18 @@ public static function _parse_url_query($url) return array_filter($params); } + + /** + * @param array $defaultParts + * @param array $parts + * @return array + */ + private function fillParts(array $defaultParts, array $parts) + { + if (!empty($parts)) { + return array_unique(array_merge($defaultParts, $parts)); + } + + return $defaultParts; + } } diff --git a/src/YoutubeServiceProviderLaravel4.php b/src/YoutubeServiceProviderLaravel4.php old mode 100644 new mode 100755 diff --git a/src/YoutubeServiceProviderLaravel5.php b/src/YoutubeServiceProviderLaravel5.php old mode 100644 new mode 100755 diff --git a/src/cert/cacert.pem b/src/cert/cacert.pem old mode 100644 new mode 100755 diff --git a/src/compat.php b/src/compat.php old mode 100644 new mode 100755 diff --git a/src/config/youtube.php b/src/config/youtube.php old mode 100644 new mode 100755 diff --git a/tests/YoutubeTest.php b/tests/YoutubeTest.php old mode 100644 new mode 100755