YouТube dislike count fetched from API

Lyubomir Filipov
3 min readDec 24, 2021

Well, it was recently when YouTube decided to remove their dislike count from the website. Many people were curious because of this change and wanted to find a way how we could check the actual dislike count of a video.

Fellow colleague Daniel Angelov gave the idea to build a tool to check the dislike count of a video.

So we started working on it with him. It was simple, all we had to do was call an API and show the results.

We were in need of:

  • design
  • parser of the youtube video URL
  • API to get the results

Design

So we started with the design, we had to find something simple that will work for us.

There are plenty of free templates that could be used on the internet. One of the best sources is https://html5up.net/. I have recommended those templates to my students in the university as well.

Parser of YouTube video

We needed a script that will parse the video URL and fetch the id of the video so we could pass it to the API.

Good artists copy, great artists steal

Well, nowadays you don’t need to start from scratch there is plenty of code and plenty of examples that could be used for inspiration or adjustments. Quick search gives you PHP Regex to get youtube video ID?

$re = '/(?im)\b(?:https?:\/\/)?(?:w{3}\.)?youtu(?:be)?\.(?:com|be)\/(?:(?:\??v=?i?=?\/?)|watch\?vi?=|watch\?.*?&v=|embed\/|)([A-Z0-9_-]{11})\S*(?=\s|$)/';
$str = 'http://youtube.com/v/tFad5gHoBjY
https://youtube.com/vi/tFad5gHoBjY
http://www.youtube.com/?v=tFad5gHoBjY
http://www.youtube.com/?vi=tFad5gHoBjY
https://www.youtube.com/watch?v=tFad5gHoBjY
youtube.com/watch?vi=tFad5gHoBjY
youtu.be/tFad5gHoBjY
http://youtu.be/qokEYBNWA_0?t=30m26s
youtube.com/v/7HCZvhRAk-M
youtube.com/vi/7HCZvhRAk-M
youtube.com/?v=7HCZvhRAk-M
youtube.com/?vi=7HCZvhRAk-M
youtube.com/watch?v=7HCZvhRAk-M
youtube.com/watch?vi=7HCZvhRAk-M
youtu.be/7HCZvhRAk-M
youtube.com/embed/7HCZvhRAk-M
http://youtube.com/v/7HCZvhRAk-M
http://www.youtube.com/v/7HCZvhRAk-M
https://www.youtube.com/v/7HCZvhRAk-M
youtube.com/watch?v=7HCZvhRAk-M&wtv=wtv
http://www.youtube.com/watch?dev=inprogress&v=7HCZvhRAk-M&feature=related
youtube.com/watch?v=7HCZvhRAk-M
http://youtube.com/v/dQw4w9WgXcQ?feature=youtube_gdata_player
http://youtube.com/vi/dQw4w9WgXcQ?feature=youtube_gdata_player
http://youtube.com/?v=dQw4w9WgXcQ&feature=youtube_gdata_player
http://www.youtube.com/watch?v=dQw4w9WgXcQ&feature=youtube_gdata_player
http://youtube.com/?vi=dQw4w9WgXcQ&feature=youtube_gdata_player
http://youtube.com/watch?v=dQw4w9WgXcQ&feature=youtube_gdata_player
http://youtube.com/watch?vi=dQw4w9WgXcQ&feature=youtube_gdata_player
http://youtu.be/dQw4w9WgXcQ?feature=youtube_gdata_player';

preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);

var_dump($matches);
//Note: Source code is copy from the link above

API to get the results

So we had the design, we had the parser ,we were in a need of an API.

In order to gain access to the API one should:

  1. Create a new project in GCP
  2. Enable YouTube Data API v3
  3. Create an API key
  4. Write the code to fetch results
$API_KEY = 'Fetched from GCP project';
$postVideoURL = $_POST['videoURL'];
$curl = curl_init();curl_setopt_array($curl, array(CURLOPT_URL => "https://www.googleapis.com/youtube/v3/videos?id={$postVideoURL}&key={$API_KEY}&fields=items(id,snippet(channelId,title,categoryId),statistics)&part=snippet,statistics",CURLOPT_RETURNTRANSFER => true,CURLOPT_ENCODING => '',CURLOPT_MAXREDIRS => 10,CURLOPT_TIMEOUT => 0,CURLOPT_FOLLOWLOCATION => true,CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,CURLOPT_CUSTOMREQUEST => 'GET',));
$response = curl_exec($curl);
curl_close($curl);
echo $response;

The results

Well, we managed to get a simple product

We had a tool where you provide your video URL and then you could get the ‘RAW’ results.

What have we missed?

  1. There was a product doing the same thing — YouTube Dislike Button Count but you had to install a browser extension to use it.
  2. YouTube removed dislikes from the API
  1. It is never too late to work on an idea
  2. “Fail early, fail often”
  3. Work in a team! — “Alone we can do so little; together we can do so much.”
  4. You need only a couple of minutes to start

--

--

Lyubomir Filipov

Group Architect at FFW, believer, developer, enthusiast