Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Available commands (link, subs, views, videos, last, last3, date, datetime, datediff, datetimediff)
- // obtain your own API key at
- // https://console.developers.google.com
- $MyKey = xxxxx_xxxxx_xxxxx;
- // Convert the GET data into variables.
- $YouTubeID = $_GET["Channel_ID"];
- $Command = $_GET["Command"];
- $User = $_GET["User"];
- // Get the channel ID and Upload ID from the YouTube name inputted
- $IDs = json_decode(@file_get_contents("https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=$YouTubeID&key=$MyKey"), true);
- if($IDs['items'][0]['id'] == null)
- {
- echo 'No such YouTube channel exists.';
- die();
- }
- // Set variables.
- $Channel_ID = $IDs['items'][0]['id'];
- $Uploads_ID = $IDs['items'][0]['contentDetails']['relatedPlaylists']['uploads'];
- // Get the Subscribers, views and videos.
- $ChannelInfo = json_decode(@file_get_contents("https://www.googleapis.com/youtube/v3/channels?part=contentDetails%2C+statistics%2Csnippet&id=$Channel_ID&key=$MyKey"), true);
- // Set variables.
- $CorrectName = $ChannelInfo['items'][0]['snippet']['title'];
- $ViewSubsDenied = $ChannelInfo['items'][0]['statistics']['hiddenSubscriberCount'];
- $TotalSubs = $ChannelInfo['items'][0]['statistics']['subscriberCount'];
- $NextSub = number_format($TotalSubs) + 1;
- $TotalViews = $ChannelInfo['items'][0]['statistics']['viewCount'];
- $TotalVideos = $ChannelInfo['items'][0]['statistics']['videoCount'];
- $CreatedDate = date('Y-m-d', strtotime($ChannelInfo['items'][0]['snippet']['publishedAt']));
- $CreatedDateTime = date('Y-m-d H:i:s', strtotime($ChannelInfo['items'][0]['snippet']['publishedAt']));
- // Get the last3 video uploaded.
- $Last3Videos = json_decode(@file_get_contents("https://www.googleapis.com/youtube/v3/playlistItems?playlistId=$Uploads_ID&key=$MyKey&fields=items&part=snippet&maxResults=3"), true);
- // Get the last video uploaded.
- $LastVideo = json_decode(@file_get_contents("https://www.googleapis.com/youtube/v3/playlistItems?playlistId=$Uploads_ID&key=$MyKey&fields=items&part=snippet&maxResults=1"), true);
- // Set variable.
- $Last3VideosURL = $Last3Videos['items'][0]['snippet']['resourceId']['videoId'];
- $Last3VideosTitle = $Last3Videos['items'][0]['snippet']['title'];
- $Last2VideosURL = $Last3Videos['items'][1]['snippet']['resourceId']['videoId'];
- $Last2VideosTitle = $Last3Videos['items'][1]['snippet']['title'];
- $Last1VideosURL = $Last3Videos['items'][2]['snippet']['resourceId']['videoId'];
- $Last1VideosTitle = $Last3Videos['items'][2]['snippet']['title'];
- $LastVideoURL = $LastVideo['items'][0]['snippet']['resourceId']['videoId'];
- $LastVideoTitle = $LastVideo['items'][0]['snippet']['title'];
- // Figure out what to display, and display it.
- if($Command == "link")
- {
- echo $User . ": You can be " . $CorrectName . "'s NEXT " . number_format($NextSub) . " YouTube Subscriber right now! Subscribe to " . $CorrectName . "'s YouTube URL: https://www.youtube.com/channel/" . $YouTubeID . "?sub_confirmation=1";
- }
- if($Command == "subs")
- {
- if($ViewSubsDenied == "true")
- {
- echo $CorrectName . ' has hidden their number of subscribers!';
- }
- else
- {
- echo $CorrectName . ' has ' . number_format($TotalSubs) . ' YouTube Subscribers!';
- }
- }
- if($Command == "views")
- {
- echo $CorrectName . ' has a total of ' . number_format($TotalViews) . ' YouTube Videos Views.';
- }
- if($Command == "videos")
- {
- echo $CorrectName . ' has ' . number_format($TotalVideos) . ' YouTube videos.';
- }
- if($Command == "last3")
- {
- echo $CorrectName . "'s last 3 YouTube videos: ($Last3VideosTitle) youtu.be/" . $Last3VideosURL . " | ($Last2VideosTitle) youtu.be/" . $Last2VideosURL . " | ($Last1VideosTitle) youtu.be/" . $Last1VideosURL;
- }
- if($Command == "last")
- {
- echo $CorrectName . "'s YouTube latest video: ($LastVideoTitle) youtu.be/" . $LastVideoURL;
- }
- if($Command == "date" || $Command == "datetime" || $Command == "datediff" || $Command == "datetimediff")
- {
- echo $CorrectName . ' created their YouTube account on ';
- if($Command == "date" || $Command == "datediff")
- {
- echo $CreatedDate;
- if($Command == "datediff")
- {
- echo ' (';
- echo GetDateDifference($CreatedDate, $Command);
- echo ')';
- }
- }
- if($Command == "datetime" || $Command == "datetimediff")
- {
- echo $CreatedDateTime;
- if($Command == "datetimediff")
- {
- echo ' (';
- echo GetDateDifference($CreatedDateTime, $Command);
- echo ')';
- }
- }
- }
- // Function to get the date difference.
- function GetDateDifference($datetime, $Command)
- {
- $now = new DateTime;
- $ago = new DateTime($datetime);
- $diff = $now->diff($ago);
- $diff->w = floor($diff->d / 7);
- $diff->d -= $diff->w * 7;
- if($Command == "datetimediff")
- {
- $string = array
- (
- 'y' => 'year',
- 'm' => 'month',
- 'w' => 'week',
- 'd' => 'day',
- 'h' => 'hour',
- 'i' => 'minute',
- 's' => 'second',
- );
- }
- if($Command == "datediff")
- {
- $string = array
- (
- 'y' => 'year',
- 'm' => 'month',
- 'w' => 'week',
- 'd' => 'day',
- );
- }
- foreach ($string as $k => &$v) {
- if ($diff->$k) {
- $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
- }
- else
- {
- unset($string[$k]);
- }
- }
- return $string ? implode(', ', $string) . '' : '';
- }
- ?>
- Example:
- Youtube.php?Channel_ID=YT_Channel_ID&Command=subs
- or
- Youtube.php?Channel_ID=YT_Channel_ID&Command=subs&User=username
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement