Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition parameters as fields to Youtube request #62

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .styleci.yml
100644 → 100755
Empty file.
Empty file modified .travis.yml
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
7 changes: 6 additions & 1 deletion composer.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
{
"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",
"authors": [
{
"name": "Madcoda",
"email": "[email protected]"
},
{
"name": "Scrobot",
"email": "[email protected]"
}
],
"support":{
Expand Down
Empty file modified composer.lock
100644 → 100755
Empty file.
Empty file modified phpunit.xml.dist
100644 → 100755
Empty file.
Empty file modified src/Constants.php
100644 → 100755
Empty file.
Empty file modified src/Facades/Youtube.php
100644 → 100755
Empty file.
46 changes: 36 additions & 10 deletions src/Youtube.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Empty file modified src/YoutubeServiceProviderLaravel4.php
100644 → 100755
Empty file.
Empty file modified src/YoutubeServiceProviderLaravel5.php
100644 → 100755
Empty file.
Empty file modified src/cert/cacert.pem
100644 → 100755
Empty file.
Empty file modified src/compat.php
100644 → 100755
Empty file.
Empty file modified src/config/youtube.php
100644 → 100755
Empty file.
Empty file modified tests/YoutubeTest.php
100644 → 100755
Empty file.