From 94088424b718b8710a113fcc7651e7ef92e6faac Mon Sep 17 00:00:00 2001 From: Alex Scrobot Date: Tue, 24 Oct 2017 12:09:15 +0700 Subject: [PATCH 1/6] Addition parameters as fields to Youtube request --- src/Youtube.php | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/Youtube.php b/src/Youtube.php index 6c1fe0c..dc76980 100644 --- 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,15 +326,18 @@ 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); @@ -672,4 +680,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; + } } From 8567940a20f50dd8309d047fe026ffa60018fd24 Mon Sep 17 00:00:00 2001 From: Alex Scrobot Date: Tue, 24 Oct 2017 12:24:21 +0700 Subject: [PATCH 2/6] minimum-stability --- composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/composer.json b/composer.json index e1b8e40..04eaa69 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "name": "madcoda/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":{ From 82830c7007a23e6820c6ed4a9851309f4e29de24 Mon Sep 17 00:00:00 2001 From: Alex Scrobot Date: Tue, 24 Oct 2017 12:24:27 +0700 Subject: [PATCH 3/6] minimum-stability dev --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 04eaa69..2b80d24 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "support":{ - "email":"jason@madcoda.com", + "email":"jason@madcoda.com",e "issues":"https://github.com/madcoda/php-youtube-api/issues" }, "require": { From 56ff509ceecb2b5f9189ae96dbd50eeb464776b6 Mon Sep 17 00:00:00 2001 From: Alex Scrobot Date: Tue, 24 Oct 2017 12:24:43 +0700 Subject: [PATCH 4/6] minimum-stability dev --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2b80d24..04eaa69 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "support":{ - "email":"jason@madcoda.com",e + "email":"jason@madcoda.com", "issues":"https://github.com/madcoda/php-youtube-api/issues" }, "require": { From b96733da8f5888a4078c4c6897d927418de8ab35 Mon Sep 17 00:00:00 2001 From: Alex Scrobot Date: Tue, 24 Oct 2017 12:26:23 +0700 Subject: [PATCH 5/6] composer changes --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 04eaa69..9175154 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "madcoda/php-youtube-api", + "name": "scrobot/php-youtube-api", "type": "library", "minimum-stability": "dev", "description": "PHP wrapper for the Youtube Data API v3", From 25f3d4eb374cdb219b631e80282f35cafbfa3e51 Mon Sep 17 00:00:00 2001 From: Batis Date: Sun, 12 Aug 2018 18:28:22 +0300 Subject: [PATCH 6/6] =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 0 .styleci.yml | 0 .travis.yml | 0 LICENSE | 0 README.md | 0 composer.json | 0 composer.lock | 0 phpunit.xml.dist | 0 src/Constants.php | 0 src/Facades/Youtube.php | 0 src/Youtube.php | 14 +++++++++----- src/YoutubeServiceProviderLaravel4.php | 0 src/YoutubeServiceProviderLaravel5.php | 0 src/cert/cacert.pem | 0 src/compat.php | 0 src/config/youtube.php | 0 tests/YoutubeTest.php | 0 17 files changed, 9 insertions(+), 5 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 .styleci.yml mode change 100644 => 100755 .travis.yml mode change 100644 => 100755 LICENSE mode change 100644 => 100755 README.md mode change 100644 => 100755 composer.json mode change 100644 => 100755 composer.lock mode change 100644 => 100755 phpunit.xml.dist mode change 100644 => 100755 src/Constants.php mode change 100644 => 100755 src/Facades/Youtube.php mode change 100644 => 100755 src/Youtube.php mode change 100644 => 100755 src/YoutubeServiceProviderLaravel4.php mode change 100644 => 100755 src/YoutubeServiceProviderLaravel5.php mode change 100644 => 100755 src/cert/cacert.pem mode change 100644 => 100755 src/compat.php mode change 100644 => 100755 src/config/youtube.php mode change 100644 => 100755 tests/YoutubeTest.php 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 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 dc76980..f37cee8 --- a/src/Youtube.php +++ b/src/Youtube.php @@ -151,7 +151,7 @@ public function getVideoInfo($vId) * @param array $parts * @return \StdClass */ - public function getVideosInfo($vIds, array $parts) + public function getVideosInfo($vIds, array $parts = []) { $partArray = $this->fillParts(['id', 'snippet', 'contentDetails', 'player', 'statistics', 'status'], $parts); @@ -307,7 +307,7 @@ public function paginateResults($params, $token = null) * @param array $parts * @return \StdClass */ - public function getChannelByName($username, $optionalParams = false, array $parts) + public function getChannelByName($username, $optionalParams = false, array $parts = []) { $partArray = $this->fillParts(['id', 'snippet', 'contentDetails', 'invideoPromotion', 'statistics'], $parts); @@ -330,19 +330,21 @@ public function getChannelByName($username, $optionalParams = false, array $part * @param array $parts * @return \StdClass */ - public function getChannelById($id, $optionalParams = false, array $parts) + 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' => implode(",", $partArray) ); + if ($optionalParams) { $params = array_merge($params, $optionalParams); } + $apiData = $this->api_get($API_URL, $params); + return $this->decodeSingle($apiData); } @@ -624,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) { @@ -641,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; } 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