diff --git a/youtube-api/userInfos.php b/youtube-api/userInfos.php index bf06225f4e14ea1d0b037a174c0dc1a5a6bc6302..b9ec64c65b08c23a0cbf2fe9d1ab86d28eed99d4 100644 --- a/youtube-api/userInfos.php +++ b/youtube-api/userInfos.php @@ -5,13 +5,12 @@ * Date: 2018/11/18 * Time: 16:16 */ -require 'vendor/autoload.php'; +include '../vendor/autoload.php'; $setting = array( 'key' => 'AIzaSyAg1Jz2Zxlna4sLJTE8BNpQlN2vSETqcHA' ); - function searchByKey($keyword){ global $setting; $youtube = new Madcoda\Youtube\Youtube($setting); @@ -26,6 +25,13 @@ function getChannelId($id){ return $res; } +function getChannelUsername($id){ + global $setting; + $youtube = new Madcoda\Youtube\Youtube($setting); + $res= $youtube->getChannelById($id); + return $res; +} + function getChannelNbFollowers($id) { global $setting; $youtube = new Madcoda\Youtube\Youtube($setting); @@ -37,7 +43,7 @@ function getChannelProfileImage($id) { global $setting; $youtube = new Madcoda\Youtube\Youtube($setting); $res= $youtube->getChannelById($id); - $url = $res->thumbnails->medium->url; + $url = $res->snippet->thumbnails->high->url; return $url; } @@ -53,4 +59,137 @@ function getChannelViewCount($id) { $youtube = new Madcoda\Youtube\Youtube($setting); $res= $youtube->getChannelById($id); return intval($res->statistics->viewCount); -} \ No newline at end of file +} + +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; +} + + + + + +