Skip to content
Extraits de code Groupes Projets
Valider 2d57b9e9 rédigé par ZeyuC's avatar ZeyuC
Parcourir les fichiers

new function for youtube API

parent f87a7901
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -5,13 +5,12 @@ ...@@ -5,13 +5,12 @@
* Date: 2018/11/18 * Date: 2018/11/18
* Time: 16:16 * Time: 16:16
*/ */
require 'vendor/autoload.php'; include '../vendor/autoload.php';
$setting = array( $setting = array(
'key' => 'AIzaSyAg1Jz2Zxlna4sLJTE8BNpQlN2vSETqcHA' 'key' => 'AIzaSyAg1Jz2Zxlna4sLJTE8BNpQlN2vSETqcHA'
); );
function searchByKey($keyword){ function searchByKey($keyword){
global $setting; global $setting;
$youtube = new Madcoda\Youtube\Youtube($setting); $youtube = new Madcoda\Youtube\Youtube($setting);
...@@ -26,6 +25,13 @@ function getChannelId($id){ ...@@ -26,6 +25,13 @@ function getChannelId($id){
return $res; return $res;
} }
function getChannelUsername($id){
global $setting;
$youtube = new Madcoda\Youtube\Youtube($setting);
$res= $youtube->getChannelById($id);
return $res;
}
function getChannelNbFollowers($id) { function getChannelNbFollowers($id) {
global $setting; global $setting;
$youtube = new Madcoda\Youtube\Youtube($setting); $youtube = new Madcoda\Youtube\Youtube($setting);
...@@ -37,7 +43,7 @@ function getChannelProfileImage($id) { ...@@ -37,7 +43,7 @@ function getChannelProfileImage($id) {
global $setting; global $setting;
$youtube = new Madcoda\Youtube\Youtube($setting); $youtube = new Madcoda\Youtube\Youtube($setting);
$res= $youtube->getChannelById($id); $res= $youtube->getChannelById($id);
$url = $res->thumbnails->medium->url; $url = $res->snippet->thumbnails->high->url;
return $url; return $url;
} }
...@@ -54,3 +60,136 @@ function getChannelViewCount($id) { ...@@ -54,3 +60,136 @@ function getChannelViewCount($id) {
$res= $youtube->getChannelById($id); $res= $youtube->getChannelById($id);
return intval($res->statistics->viewCount); return intval($res->statistics->viewCount);
} }
function getVideoInfoById($id){
global $setting;
$youtube = new Madcoda\Youtube\Youtube($setting);
$res = $youtube->getVideoInfo($id);
return $res;
}
/**
* Search Get the name of the a video by ID
* @param Id
* @return the Name of a video
*/
function getVideoNameById($id){
global $setting;
$youtube = new Madcoda\Youtube\Youtube($setting);
$res = $youtube->getVideoInfo($id)->snippet->title;
return $res;
}
/**
* Search Get the Icon of the a video by ID
* @param Id
* @return the Icon of a video
*/
function getVideoIconById($id){
global $setting;
$youtube = new Madcoda\Youtube\Youtube($setting);
$res = $youtube->getVideoInfo($id)->snippet->thumbnails->default->url;
return $res;
}
/**
* Search Get the ViewCount of the a video by ID
* @param Id
* @return the viewCount of a video
*/
function getVideoViewCountById($id){
global $setting;
$youtube = new Madcoda\Youtube\Youtube($setting);
$res = $youtube->getVideoInfo($id)->statistics->viewCount;
return $res;
}
/**
* Search Get the most populare count videos's id in a channel by channelID
* @param $channelId
* @param $count
* @return an array including the id of the most populare count videos
*/
function getCountTopVideos($channelId,$count)
{
global $setting;
$youtube = new Madcoda\Youtube\Youtube($setting);
$vid = $youtube->searchChannelVideos('',$channelId,$count, "viewCount");
$CountList = array();
for($i=0;$i<$count ; $i++)
{
$CountList[$i] = getVideoInfoById($vid[$i]->id->videoId)->id;
}
return $CountList;
}
/**
* Get the viewcount of the recent count videos by channelID
* @param $channelId
* @param $count
*/
function getviewCountOfRecentVideo($channelId,$count)
{
global $setting;
$youtube = new Madcoda\Youtube\Youtube($setting);
$vid = $youtube->searchChannelVideos('',$channelId,$count,"date");
$ViewCountList = array();
for($i=0; $i<$count ; $i++)
{
$id = $vid[$i]->id->videoId;
$ViewCountList[$i] = getVideoInfoById($id)->statistics->viewCount;
}
return $ViewCountList;
}
/**
* Get the Likecount of the recent count videos by channelID
* @param $channelId
* @param $count
*/
function getDislikeCountOfRecentVideo($channelId,$count)
{
global $setting;
$youtube = new Madcoda\Youtube\Youtube($setting);
$vid = $youtube->searchChannelVideos('',$channelId,$count);
$CountList = array();
for($i=0;$i<$count ; $i++)
{
$CountList[$i] = (getVideoInfoById($vid[$i]->id->videoId))->statistics->dislikeCount;
}
return $CountList;
}
/**
* Search Get the DisLikecount of the recent count videos by channelID
* @param $channelId
* @param $count
*/
function getLikeCountOfRecentVideo($channelId,$count)
{
global $setting;
$youtube = new Madcoda\Youtube\Youtube($setting);
$vid = $youtube->searchChannelVideos('',$channelId,$count);
$CountList = array();
for($i=0;$i<$count ; $i++)
{
$CountList[$i] = (getVideoInfoById($vid[$i]->id->videoId))->statistics->likeCount;
}
return $CountList;
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter