Skip to content
Merged
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
44 changes: 44 additions & 0 deletions src/Sseffa/VideoApi/Services/Vimeo.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ public function getVideoDetail($id)
);
}

/**
* Get Video Raw Data
*
* @param string $id
* @return array|mixed
* @throws \Exception
*/
public function getVideoRawData($id)
{
$this->setId($id);

$data = $this->getData($this->baseVideoUrl);

if(!$data) {
throw new \Exception("Video not found");
}

$data = $data[0];

return $data;
}

/**
* Get Video Channel By Id (username)
*
Expand Down Expand Up @@ -100,4 +122,26 @@ public function getVideoList($id)
}
return $list;
}

/**
* Parse a vimeo URL to get the vimeo video id.
* Support vimeo.com url
*
* @param string $vimeo_url
* @throws \Exception
* @return string Video Id
*/
public function parseVIdFromURL($vimeo_url)
{
if (strpos($vimeo_url, 'vimeo.com')) {
$tokens = explode("/", $vimeo_url);
if(is_numeric($tokens[3]))
return $tokens[3];
else
throw new \Exception('The supplied URL does not contain a valid Vimeo video id');
} else {
throw new \Exception('The supplied URL does not look like a Vimeo URL');
}
}
}

89 changes: 88 additions & 1 deletion src/Sseffa/VideoApi/Services/Youtube.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,30 @@ public function getVideoDetail($id)
'like_count' => isset($data->items[0]->statistics->likeCount) ? $data->items[0]->statistics->likeCount : 0,
'view_count' => isset($data->items[0]->statistics->viewCount) ? $data->items[0]->statistics->viewCount : 0,
'comment_count' => isset($data->items[0]->statistics->commentCount) ? $data->items[0]->statistics->commentCount : 0,
'uploader' => null
'uploader' => $data->items[0]->snippet->channelTitle
);
}

/**
* Get Video Raw Data
* @param string $id
* @return array
* @throws \Exception
*/
public function getVideoRawData($id)
{
$this->setId($id);

$data = $this->getData(str_replace('{key}', $this->key, $this->baseVideoUrl));

if(isset($data->error))
{
throw new \Exception("Video not found");
}

return $data;
}

/**
* Get Video List
* @param string $id
Expand All @@ -93,4 +113,71 @@ public function getVideoList($id)

return $list;
}

/**
* Parse a youtube URL to get the youtube Vid.
* Support both full URL (www.youtube.com) and short URL (youtu.be)
* Source: https://github.com/alaouy/Youtube
*
* @param string $youtube_url
* @throws \Exception
* @return string Video Id
*/
public function parseVIdFromURL($youtube_url)
{
if (strpos($youtube_url, 'youtube.com')) {
if (strpos($youtube_url, 'embed')) {
$path = static::_parse_url_path($youtube_url);
$vid = substr($path, 7);
return $vid;
} else {
$params = static::_parse_url_query($youtube_url);
return $params['v'];
}
} else if (strpos($youtube_url, 'youtu.be')) {
$path = static::_parse_url_path($youtube_url);
$vid = substr($path, 1);
return $vid;
} else {
throw new \Exception('The supplied URL does not look like a Youtube URL');
}
}

/**
* Parse the input url string and return just the path part
* Source: https://github.com/alaouy/Youtube
*
* @param string $url the URL
* @return string the path string
*/
public static function _parse_url_path($url)
{
$array = parse_url($url);

return $array['path'];
}

/**
* Parse the input url string and return an array of query params
* Source: https://github.com/alaouy/Youtube
*
* @param string $url the URL
* @return array array of query params
*/
public static function _parse_url_query($url)
{
$array = parse_url($url);
$query = $array['query'];

$queryParts = explode('&', $query);

$params = array();
foreach ($queryParts as $param) {
$item = explode('=', $param);
$params[$item[0]] = empty($item[1]) ? '' : $item[1];
}

return $params;
}
}